Skip to content
This repository was archived by the owner on Feb 5, 2022. It is now read-only.

Commit 2a2b324

Browse files
Akryumegoist
authored andcommitted
feat: answers option (#134)
* feat: answers option * accepts object * fix lint
1 parent 6789f2b commit 2a2b324

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

bin/cli.js

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ cli
3030
.option('-c, --clone', 'Clone repository instead of archive download')
3131
.option('-y, --yes', 'Use the default options')
3232
.option('--registry <registry>', 'Use a custom registry for package manager')
33+
.option('--answers <json>', 'Skip prompts and use provided answers directly')
3334
.option('--debug', 'Show debug logs')
3435

3536
cli

lib/index.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,16 @@ class SAO {
116116
await config.prepare.call(generatorContext, generatorContext)
117117
}
118118

119-
if (config.prompts) {
119+
if (this.opts.answers) {
120+
try {
121+
generatorContext._answers =
122+
typeof this.opts.answers === 'string'
123+
? JSON.parse(this.opts.answers)
124+
: this.opts.answers
125+
} catch (err) {
126+
throw new Error(`Answers JSON could not be parsed (${err.message})`)
127+
}
128+
} else if (config.prompts) {
120129
await require('./runPrompts')(config, generatorContext)
121130
}
122131

0 commit comments

Comments
 (0)