Skip to content

Commit

Permalink
feat: add config plugins, #288
Browse files Browse the repository at this point in the history
  • Loading branch information
Scrum committed Jun 26, 2019
1 parent 5e62b38 commit de59985
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/cfg-resolve.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import path from 'path';
import getCff from 'get-cff';
import cosmiconfig from 'cosmiconfig';
import toCamelCase from 'to-camel-case';
import pathExists from 'path-exists';
import deepAssign from 'deep-assign';
import mergeOptions from 'merge-options';

export default (flags = {}) => new Promise(async resolve => {
export default (flags = {}) => new Promise(resolve => {
const explorer = cosmiconfig('posthtml');
let {config, use} = flags;

if (config) {
config = path.resolve(config);
config = await pathExists(config) ? await getCff(config) : {};
({config} = explorer.loadSync(config));
}

if (use) {
use = [].concat(use).reduce((cfg, key) => deepAssign(cfg, {[key]: flags[toCamelCase(key)] || {}}), {});
use = [].concat(use).reduce((cfg, key) => mergeOptions(cfg, {plugins: {[key]: flags[toCamelCase(key)] || {}}}), {});
}

resolve(deepAssign({}, use || {}, config || {}));
if (!config && !use) {
({config} = explorer.searchSync());
}

resolve(mergeOptions({}, use || {}, config || {}));
});

0 comments on commit de59985

Please sign in to comment.