Skip to content

Commit 3e46b67

Browse files
authored
Merge pull request #298 from turusuke/base-option
feat: base option
2 parents fb006f4 + 362a00b commit 3e46b67

13 files changed

Lines changed: 92 additions & 23 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"build": "rimraf lib && babel src -d lib",
2424
"coverage": "nyc report --reporter=text-lcov | coveralls",
2525
"pretest": "npm run build",
26-
"test": "nyc ava --verbose"
26+
"test": "nyc ava --timeout=1m --verbose"
2727
},
2828
"files": [
2929
"lib/"

readme.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ $ posthtml --help
2323
$ posthtml <patterns>
2424

2525
Options:
26-
--output -o Output File or Folder
27-
--config -c Path to config file
28-
--use -u PostHTML plugin name
29-
--help -h CLI Help
30-
--version -v CLI Version
26+
--output -o Output File or Folder
27+
--config -c Path to config file
28+
--use -u PostHTML plugin name
29+
--root -r Mirror the directory structure relative to this path in the output directory(default: .)
30+
--allInOutput -a Save the nesting structure for output
31+
--help -h CLI Help
32+
--version -v CLI Version
3133

3234
Examples:
3335
$ posthtml input.html
@@ -36,7 +38,8 @@ $ posthtml --help
3638
$ posthtml input.html -o output.html -c posthtml.js
3739
$ posthtml input.html -o output.html -u posthtml-bem --posthtml-bem.elemPrefix __
3840
$ posthtml inputFolder/*.html -o outputFolder
39-
$ posthtml inputFolder/**/*.html -o outputFolder
41+
$ posthtml inputFolder/**/*.html -o outputFolder -a
42+
$ posthtml inputFolder/**/*.html -o outputFolder -a -r inputFolder
4043
```
4144

4245
## Options

src/cfg-resolve.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import mergeOptions from 'merge-options';
44

55
export default ({input, flags = {}}) => {
66
const explorer = cosmiconfigSync('posthtml');
7-
let {config, use, output} = flags;
7+
let {config, use, output, root, allInOutput} = flags;
88

99
if (config) {
1010
({config} = explorer.load(config));
@@ -20,6 +20,8 @@ export default ({input, flags = {}}) => {
2020

2121
return mergeOptions({
2222
input,
23-
output
23+
output,
24+
root,
25+
allInOutput
2426
}, use || {}, config || {});
2527
};

src/cli.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ const cli = meow(`
1313
Usage: posthtml <patterns>
1414
1515
Options:
16-
--output -o Output File or Folder
17-
--config -c Path to config file
18-
--use -u PostHTML plugin name
19-
--help -h CLI Help
20-
--version -v CLI Version
16+
--output -o Output File or Folder
17+
--config -c Path to config file
18+
--use -u PostHTML plugin name
19+
--root -r Mirror the directory structure relative to this path in the output directory(default: .)
20+
--allInOutput -a Save the nesting structure for output
21+
--help -h CLI Help
22+
--version -v CLI Version
2123
2224
Examples:
2325
$ posthtml input.html
@@ -26,7 +28,8 @@ const cli = meow(`
2628
$ posthtml input.html -o output.html -c posthtml.js
2729
$ posthtml input.html -o output.html -u posthtml-bem --posthtml-bem.elemPrefix __
2830
$ posthtml inputFolder/*.html -o outputFolder
29-
$ posthtml inputFolder/**/*.html -o outputFolder
31+
$ posthtml inputFolder/**/*.html -o outputFolder -a
32+
$ posthtml inputFolder/**/*.html -o outputFolder -a -r inputFolder
3033
`, {
3134
flags: {
3235
config: {
@@ -48,6 +51,15 @@ const cli = meow(`
4851
use: {
4952
type: 'array',
5053
alias: 'u'
54+
},
55+
root: {
56+
type: 'string',
57+
alias: 'r',
58+
default: '.'
59+
},
60+
allInOutput: {
61+
type: 'boolean',
62+
alias: 'a'
5163
}
5264
}
5365
});
@@ -68,7 +80,7 @@ const getPlugins = config => Object.keys(config.plugins || {})
6880
const config = cfgResolve(cli);
6981

7082
const processing = async file => {
71-
const output = await outResolve(file, config.output);
83+
const output = await outResolve(file, config);
7284
const plugins = Array.isArray(config.plugins) ? config.plugins : getPlugins(config);
7385

7486
makeDir(path.dirname(output))

src/out-resolve.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
import path from 'path';
22

3-
export default (input, output) => new Promise(resolve => {
3+
export default (input, {output, root, allInOutput} = {}) => 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+
let inputPath = path.basename(input);
10+
11+
if (allInOutput) {
12+
inputPath = path.relative(root, input);
13+
}
14+
15+
return resolve(path.join(output, inputPath));
1016
}
1117

12-
resolve(input);
18+
return resolve(input);
1319
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div>input-nesting-child/index</div>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div>input-nesting-index</div>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div>input-nesting-child/index</div>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div>input-nesting-index</div>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div>input-nesting-child/index</div>

0 commit comments

Comments
 (0)