generator-begcode
Version:
Spring Boot + Angular/React/Vue in one handy generator
38 lines (37 loc) • 1.25 kB
JavaScript
export const extractArgumentsFromConfigs = (configs) => {
if (!configs)
return {};
return Object.fromEntries(Object.entries(configs)
.filter(([_name, def]) => def.argument)
.map(([name, def]) => [
name,
{
description: def.description,
scope: def.scope,
choices: def.choices,
...def.argument,
},
]));
};
export const extractJdlDefinitionFromCommandConfig = (configs = {}) => Object.entries(configs)
.filter(([_name, def]) => def.jdl)
.map(([name, def]) => ({
...def.jdl,
name,
knownChoices: def.choices?.map(choice => (typeof choice === 'string' ? choice : choice.value)),
}))
.sort((a, b) => (b.name.startsWith(a.name) ? 1 : a.name.localeCompare(b.name)));
export const convertConfigToOption = (name, config) => {
if (!config?.cli?.type && config?.internal !== true)
return undefined;
const choices = config.choices?.map(choice => (typeof choice === 'string' ? choice : choice.value));
return {
name,
default: config.default,
description: config.description,
choices,
scope: config.scope ?? 'storage',
type: val => val,
...config.cli,
};
};