diff --git a/examples/test-input/scaffold.config.js b/examples/test-input/scaffold.config.js index 15647f8..f307c0a 100644 --- a/examples/test-input/scaffold.config.js +++ b/examples/test-input/scaffold.config.js @@ -7,7 +7,7 @@ module.exports = { }, component: { templates: ["examples/test-input/Component"], - output: "examples/test-output", + output: "examples/test-output/component", data: { property: "myProp", value: "10" }, }, } diff --git a/pages/cli.md b/pages/cli.md index e0fbdc2..80db3e9 100644 --- a/pages/cli.md +++ b/pages/cli.md @@ -20,6 +20,10 @@ Options: arguments to CLI or using a Node.js script. You may pass a JSON or JS file, with a relative or absolute path. + --key|-k Key to load inside the config file. This overwrites the + config key provided after the colon in --config (e.g. --config + scaffold.cmd.js:component) + --output|-o Path to output to. If --create-sub-folder is enabled, the subfolder will be created inside this path. (default: current dir) diff --git a/src/cmd.ts b/src/cmd.ts index af34176..bbc778a 100644 --- a/src/cmd.ts +++ b/src/cmd.ts @@ -31,6 +31,12 @@ export async function parseCliArgs(args = process.argv.slice(2)) { description: "Filename to load config from instead of passing arguments to CLI or using a Node.js script. You may pass a JSON or JS file, with a relative or absolute path.", }) + .option({ + name: "key", + aliases: ["k"], + description: + "Key to load inside the config file. This overwrites the config key provided after the colon in --config (e.g. --config scaffold.cmd.js:component)", + }) .option({ name: "output", aliases: ["o"], diff --git a/src/types.ts b/src/types.ts index b989078..a526f74 100644 --- a/src/types.ts +++ b/src/types.ts @@ -337,6 +337,7 @@ export interface ScaffoldCmdConfig { verbose: LogLevel dryRun: boolean config?: string + key?: string } export type ScaffoldConfigFile = Record diff --git a/src/utils.ts b/src/utils.ts index 04d058d..92d921f 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -118,8 +118,8 @@ export function log(config: ScaffoldConfig, level: LogLevel, ...obj: any[]): voi i instanceof Error ? chalkFn(i, JSON.stringify(i, undefined, 1), i.stack) : typeof i === "object" - ? chalkFn(JSON.stringify(i, undefined, 1)) - : chalkFn(i), + ? chalkFn(JSON.stringify(i, undefined, 1)) + : chalkFn(i), ), ) } @@ -402,7 +402,8 @@ export function parseConfig(config: ScaffoldCmdConfig & OptionsBase): ScaffoldCo let c: ScaffoldConfig = config if (config.config) { - const [configFile, template = "default"] = config.config.split(":") + const [configFile, colonTemplate = "default"] = config.config.split(":") + const template = config.key ?? colonTemplate const configImport: ScaffoldConfigFile = require(path.resolve(process.cwd(), configFile)) if (!configImport[template]) { throw new Error(`Template "${template}" not found in ${configFile}`)