Skip to content

Commit de59985

Browse files
committed
feat: add config plugins, #288
1 parent 5e62b38 commit de59985

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

src/cfg-resolve.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
1-
import path from 'path';
2-
import getCff from 'get-cff';
1+
import cosmiconfig from 'cosmiconfig';
32
import toCamelCase from 'to-camel-case';
4-
import pathExists from 'path-exists';
5-
import deepAssign from 'deep-assign';
3+
import mergeOptions from 'merge-options';
64

7-
export default (flags = {}) => new Promise(async resolve => {
5+
export default (flags = {}) => new Promise(resolve => {
6+
const explorer = cosmiconfig('posthtml');
87
let {config, use} = flags;
98

109
if (config) {
11-
config = path.resolve(config);
12-
config = await pathExists(config) ? await getCff(config) : {};
10+
({config} = explorer.loadSync(config));
1311
}
1412

1513
if (use) {
16-
use = [].concat(use).reduce((cfg, key) => deepAssign(cfg, {[key]: flags[toCamelCase(key)] || {}}), {});
14+
use = [].concat(use).reduce((cfg, key) => mergeOptions(cfg, {plugins: {[key]: flags[toCamelCase(key)] || {}}}), {});
1715
}
1816

19-
resolve(deepAssign({}, use || {}, config || {}));
17+
if (!config && !use) {
18+
({config} = explorer.searchSync());
19+
}
20+
21+
resolve(mergeOptions({}, use || {}, config || {}));
2022
});

0 commit comments

Comments
 (0)