Skip to content

Commit 6c5ba0b

Browse files
committed
feat: add --key | -k to config loader
1 parent 2c4eccd commit 6c5ba0b

5 files changed

Lines changed: 16 additions & 4 deletions

File tree

examples/test-input/scaffold.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module.exports = {
77
},
88
component: {
99
templates: ["examples/test-input/Component"],
10-
output: "examples/test-output",
10+
output: "examples/test-output/component",
1111
data: { property: "myProp", value: "10" },
1212
},
1313
}

pages/cli.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ Options:
2020
arguments to CLI or using a Node.js script. You may pass a
2121
JSON or JS file, with a relative or absolute path.
2222
23+
--key|-k Key to load inside the config file. This overwrites the
24+
config key provided after the colon in --config (e.g. --config
25+
scaffold.cmd.js:component)
26+
2327
--output|-o Path to output to. If --create-sub-folder is enabled,
2428
the subfolder will be created inside this path.
2529
(default: current dir)

src/cmd.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ export async function parseCliArgs(args = process.argv.slice(2)) {
3131
description:
3232
"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.",
3333
})
34+
.option({
35+
name: "key",
36+
aliases: ["k"],
37+
description:
38+
"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)",
39+
})
3440
.option({
3541
name: "output",
3642
aliases: ["o"],

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ export interface ScaffoldCmdConfig {
337337
verbose: LogLevel
338338
dryRun: boolean
339339
config?: string
340+
key?: string
340341
}
341342

342343
export type ScaffoldConfigFile = Record<string, ScaffoldConfig>

src/utils.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ export function log(config: ScaffoldConfig, level: LogLevel, ...obj: any[]): voi
118118
i instanceof Error
119119
? chalkFn(i, JSON.stringify(i, undefined, 1), i.stack)
120120
: typeof i === "object"
121-
? chalkFn(JSON.stringify(i, undefined, 1))
122-
: chalkFn(i),
121+
? chalkFn(JSON.stringify(i, undefined, 1))
122+
: chalkFn(i),
123123
),
124124
)
125125
}
@@ -402,7 +402,8 @@ export function parseConfig(config: ScaffoldCmdConfig & OptionsBase): ScaffoldCo
402402
let c: ScaffoldConfig = config
403403

404404
if (config.config) {
405-
const [configFile, template = "default"] = config.config.split(":")
405+
const [configFile, colonTemplate = "default"] = config.config.split(":")
406+
const template = config.key ?? colonTemplate
406407
const configImport: ScaffoldConfigFile = require(path.resolve(process.cwd(), configFile))
407408
if (!configImport[template]) {
408409
throw new Error(`Template "${template}" not found in ${configFile}`)

0 commit comments

Comments
 (0)