File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ $ posthtml --help
2626 --output -o Output File or Folder
2727 --config -c Path to config file
2828 --use -u PostHTML plugin name
29+ --base -b Mirror the directory structure relative to this path in the output directory
2930 --help -h CLI Help
3031 --version -v CLI Version
3132
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ import mergeOptions from 'merge-options';
44
55export default ( { input, flags = { } } ) => {
66 const explorer = cosmiconfigSync ( 'posthtml' ) ;
7- let { config, use, output} = flags ;
7+ let { config, use, output, base } = flags ;
88
99 if ( config ) {
1010 ( { config} = explorer . load ( config ) ) ;
@@ -20,6 +20,7 @@ export default ({input, flags = {}}) => {
2020
2121 return mergeOptions ( {
2222 input,
23- output
23+ output,
24+ base
2425 } , use || { } , config || { } ) ;
2526} ;
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ const cli = meow(`
1616 --output -o Output File or Folder
1717 --config -c Path to config file
1818 --use -u PostHTML plugin name
19+ --base -b Mirror the directory structure relative to this path in the output directory
1920 --help -h CLI Help
2021 --version -v CLI Version
2122
@@ -27,6 +28,7 @@ const cli = meow(`
2728 $ posthtml input.html -o output.html -u posthtml-bem --posthtml-bem.elemPrefix __
2829 $ posthtml inputFolder/*.html -o outputFolder
2930 $ posthtml inputFolder/**/*.html -o outputFolder
31+ $ posthtml inputFolder/**/*.html -o outputFolder -b inputFolder
3032` , {
3133 flags : {
3234 config : {
@@ -48,6 +50,10 @@ const cli = meow(`
4850 use : {
4951 type : 'array' ,
5052 alias : 'u'
53+ } ,
54+ base : {
55+ type : 'string' ,
56+ alias : 'b'
5157 }
5258 }
5359} ) ;
@@ -68,7 +74,7 @@ const getPlugins = config => Object.keys(config.plugins || {})
6874const config = cfgResolve ( cli ) ;
6975
7076const processing = async file => {
71- const output = await outResolve ( file , config . output ) ;
77+ const output = await outResolve ( file , config . output , config . base ) ;
7278 const plugins = Array . isArray ( config . plugins ) ? config . plugins : getPlugins ( config ) ;
7379
7480 makeDir ( path . dirname ( output ) )
Original file line number Diff line number Diff line change 11import path from 'path' ;
22
3- export default ( input , output ) => new Promise ( resolve => {
3+ export default ( input , output , base ) => new Promise ( resolve => {
44 if ( output && path . extname ( output ) ) {
55 return resolve ( output ) ;
66 }
77
88 if ( output ) {
9- return resolve ( path . join ( output , path . basename ( input ) ) ) ;
9+ const basePath = base ? path . resolve ( input ) . replace ( path . resolve ( base ) , '' ) : path . basename ( input ) ;
10+ return resolve ( path . join ( output , basePath ) ) ;
1011 }
1112
1213 resolve ( input ) ;
You can’t perform that action at this time.
0 commit comments