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

Commit

Permalink
feat: answers option (#134)
Browse files Browse the repository at this point in the history
* feat: answers option

* accepts object

* fix lint
  • Loading branch information
Akryum authored and egoist committed Sep 30, 2019
1 parent 6789f2b commit 2a2b324
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions bin/cli.js
Expand Up @@ -30,6 +30,7 @@ cli
.option('-c, --clone', 'Clone repository instead of archive download')
.option('-y, --yes', 'Use the default options')
.option('--registry <registry>', 'Use a custom registry for package manager')
.option('--answers <json>', 'Skip prompts and use provided answers directly')
.option('--debug', 'Show debug logs')

cli
Expand Down
11 changes: 10 additions & 1 deletion lib/index.js
Expand Up @@ -116,7 +116,16 @@ class SAO {
await config.prepare.call(generatorContext, generatorContext)
}

if (config.prompts) {
if (this.opts.answers) {
try {
generatorContext._answers =
typeof this.opts.answers === 'string'
? JSON.parse(this.opts.answers)
: this.opts.answers
} catch (err) {
throw new Error(`Answers JSON could not be parsed (${err.message})`)
}
} else if (config.prompts) {
await require('./runPrompts')(config, generatorContext)
}

Expand Down

0 comments on commit 2a2b324

Please sign in to comment.