Skip to content

Commit e3222b8

Browse files
committed
feat: add io in config, close #280, close #256
1 parent 85f927d commit e3222b8

3 files changed

Lines changed: 17 additions & 10 deletions

File tree

src/cfg-resolve.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import cosmiconfig from 'cosmiconfig';
22
import toCamelCase from 'to-camel-case';
33
import mergeOptions from 'merge-options';
44

5-
export default (flags = {}) => new Promise(resolve => {
5+
export default ({input, flags = {}}) => {
66
const explorer = cosmiconfig('posthtml');
7-
let {config, use} = flags;
7+
let {config, use, output} = flags;
88

99
if (config) {
1010
({config} = explorer.loadSync(config));
@@ -18,5 +18,8 @@ export default (flags = {}) => new Promise(resolve => {
1818
({config} = explorer.searchSync());
1919
}
2020

21-
resolve(mergeOptions({}, use || {}, config || {}));
22-
});
21+
return mergeOptions({
22+
input,
23+
output
24+
}, use || {}, config || {});
25+
};

src/cli.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,15 @@ const read = file => new Promise(resolve => fs.readFile(file, 'utf8', (error, da
6060
resolve(data);
6161
}));
6262

63+
const getPlugins = config => Object.keys(config.plugins || {})
64+
.map(plugin => require(plugin)(config.plugins[plugin]));
65+
66+
const config = cfgResolve(cli);
67+
6368
const processing = async file => {
64-
const output = await outResolve(file, cli.flags.output);
65-
const config = await cfgResolve(cli.flags);
66-
const plugins = Object.keys(config.plugins || {})
67-
.map(plugin => require(plugin)(config.plugins[plugin]));
69+
const output = await outResolve(file, config.output);
70+
// const output = path.resolve(config.output, path.basename(file));
71+
const plugins = getPlugins(config);
6872

6973
makeDir(path.dirname(output))
7074
.then(read.bind(null, file))
@@ -80,6 +84,6 @@ const processing = async file => {
8084
});
8185
};
8286

83-
fg.stream(cli.input)
87+
fg.stream(config.input)
8488
.on('data', processing)
8589
.once('error', console.warn);

src/out-resolve.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default (input, output) => new Promise(resolve => {
66
}
77

88
if (output) {
9-
return resolve(path.join(output, input));
9+
return resolve(path.join(output, path.basename(input)));
1010
}
1111

1212
resolve(input);

0 commit comments

Comments
 (0)