Support plugins field in config (#3584)
* Actually support plugins field in config * Resolve plugin parsers * Fix default from CLI for "plugins"master
parent
15a68394dd
commit
b63c669ed9
|
@ -443,10 +443,19 @@ const detailedOptionMap = detailedOptions.reduce(
|
||||||
{}
|
{}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const apiDetailedOptionMap = detailedOptions.reduce(
|
||||||
|
(current, option) =>
|
||||||
|
option.forwardToApi && option.forwardToApi !== option.name
|
||||||
|
? Object.assign(current, { [option.forwardToApi]: option })
|
||||||
|
: current,
|
||||||
|
{}
|
||||||
|
);
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
categoryOrder,
|
categoryOrder,
|
||||||
minimistOptions,
|
minimistOptions,
|
||||||
detailedOptions,
|
detailedOptions,
|
||||||
detailedOptionMap,
|
detailedOptionMap,
|
||||||
|
apiDetailedOptionMap,
|
||||||
usageSummary
|
usageSummary
|
||||||
};
|
};
|
||||||
|
|
|
@ -37,9 +37,12 @@ function getOptions(argv) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function dashifyObject(object) {
|
function cliifyOptions(object) {
|
||||||
return Object.keys(object || {}).reduce((output, key) => {
|
return Object.keys(object || {}).reduce((output, key) => {
|
||||||
output[dashify(key)] = object[key];
|
const apiOption = constant.apiDetailedOptionMap[key];
|
||||||
|
const cliKey = apiOption ? apiOption.name : key;
|
||||||
|
|
||||||
|
output[dashify(cliKey)] = object[key];
|
||||||
return output;
|
return output;
|
||||||
}, {});
|
}, {});
|
||||||
}
|
}
|
||||||
|
@ -202,8 +205,8 @@ function parseArgsToOptions(argv, overrideDefaults) {
|
||||||
boolean: constant.minimistOptions.boolean,
|
boolean: constant.minimistOptions.boolean,
|
||||||
default: Object.assign(
|
default: Object.assign(
|
||||||
{},
|
{},
|
||||||
dashifyObject(apiDefaultOptions),
|
cliifyOptions(apiDefaultOptions),
|
||||||
dashifyObject(overrideDefaults)
|
cliifyOptions(overrideDefaults)
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
),
|
),
|
||||||
|
@ -619,7 +622,10 @@ function normalizeConfig(type, rawConfig, options) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const option = constant.detailedOptionMap[key];
|
let option = constant.detailedOptionMap[key];
|
||||||
|
if (type === "api" && option === undefined) {
|
||||||
|
option = constant.apiDetailedOptionMap[key];
|
||||||
|
}
|
||||||
|
|
||||||
// unknown option
|
// unknown option
|
||||||
if (option === undefined) {
|
if (option === undefined) {
|
||||||
|
|
|
@ -44,6 +44,8 @@ function normalize(options) {
|
||||||
const normalized = Object.assign({}, options || {});
|
const normalized = Object.assign({}, options || {});
|
||||||
const filepath = normalized.filepath;
|
const filepath = normalized.filepath;
|
||||||
|
|
||||||
|
normalized.plugins = loadPlugins(normalized);
|
||||||
|
|
||||||
if (
|
if (
|
||||||
filepath &&
|
filepath &&
|
||||||
!normalized.parentParser &&
|
!normalized.parentParser &&
|
||||||
|
@ -52,7 +54,7 @@ function normalize(options) {
|
||||||
const extension = path.extname(filepath);
|
const extension = path.extname(filepath);
|
||||||
const filename = path.basename(filepath).toLowerCase();
|
const filename = path.basename(filepath).toLowerCase();
|
||||||
|
|
||||||
const language = getSupportInfo().languages.find(
|
const language = getSupportInfo(null, normalized).languages.find(
|
||||||
language =>
|
language =>
|
||||||
typeof language.since === "string" &&
|
typeof language.since === "string" &&
|
||||||
(language.extensions.indexOf(extension) > -1 ||
|
(language.extensions.indexOf(extension) > -1 ||
|
||||||
|
@ -122,7 +124,6 @@ function normalize(options) {
|
||||||
delete normalized.useFlowParser;
|
delete normalized.useFlowParser;
|
||||||
}
|
}
|
||||||
|
|
||||||
normalized.plugins = loadPlugins(normalized);
|
|
||||||
normalized.astFormat = resolveParser(normalized).astFormat;
|
normalized.astFormat = resolveParser(normalized).astFormat;
|
||||||
normalized.printer = getPrinter(normalized);
|
normalized.printer = getPrinter(normalized);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue