73 lines
1.7 KiB
JavaScript
73 lines
1.7 KiB
JavaScript
|
export function getAvailableOptions(supportInfo, enabledOptions) {
|
||
|
const supportedOptions = supportInfo.options.reduce((acc, option) => {
|
||
|
acc[option.name] = option;
|
||
|
return acc;
|
||
|
}, {});
|
||
|
|
||
|
return enabledOptions.reduce((optionsList, optionConfig) => {
|
||
|
if (!supportedOptions[optionConfig.name]) {
|
||
|
return optionsList;
|
||
|
}
|
||
|
|
||
|
const option = Object.assign(
|
||
|
{},
|
||
|
optionConfig,
|
||
|
supportedOptions[optionConfig.name]
|
||
|
);
|
||
|
option.cliName =
|
||
|
"--" +
|
||
|
(option.inverted ? "no-" : "") +
|
||
|
option.name.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
|
||
|
|
||
|
optionsList.push(option);
|
||
|
return optionsList;
|
||
|
}, []);
|
||
|
}
|
||
|
|
||
|
export function fixPrettierVersion(version) {
|
||
|
const match = version.match(/^\d+\.\d+\.\d+-pr.(\d+)$/);
|
||
|
if (match) {
|
||
|
return `pr-${match[1]}`;
|
||
|
}
|
||
|
return version;
|
||
|
}
|
||
|
|
||
|
export function getDefaults(availableOptions) {
|
||
|
return availableOptions.reduce((acc, option) => {
|
||
|
acc[option.name] = option.default;
|
||
|
return acc;
|
||
|
}, {});
|
||
|
}
|
||
|
|
||
|
export function buildCliArgs(availableOptions, options) {
|
||
|
const args = [];
|
||
|
for (let i = 0; i < availableOptions.length; i++) {
|
||
|
const option = availableOptions[i];
|
||
|
const value = options[option.name];
|
||
|
|
||
|
if (option.type === "boolean") {
|
||
|
if ((value && !option.inverted) || (!value && option.inverted)) {
|
||
|
args.push([option.cliName, true]);
|
||
|
}
|
||
|
} else if (value !== option.default) {
|
||
|
args.push([option.cliName, value]);
|
||
|
}
|
||
|
}
|
||
|
return args;
|
||
|
}
|
||
|
|
||
|
export function getCodemirrorMode(parser) {
|
||
|
switch (parser) {
|
||
|
case "css":
|
||
|
case "less":
|
||
|
case "scss":
|
||
|
return "css";
|
||
|
case "graphql":
|
||
|
return "graphql";
|
||
|
case "markdown":
|
||
|
return "markdown";
|
||
|
default:
|
||
|
return "jsx";
|
||
|
}
|
||
|
}
|