Skip to content

Commit 0e37f6d

Browse files
zigomiryyx990803
authored andcommitted
Multi choice.
1 parent 19eee29 commit 0e37f6d

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ You can also create your own template from scratch:
5959

6060
- All template files will be piped through Handlebars for simple templating - `vue-cli` will automatically infer the prompts based on `{{}}` interpolations found in the files.
6161

62-
- A template repo **may** have a `meta.json` file that provides a schema for the prompts. The schema will be passed to [inquirer](https://github.com/SBoudrias/Inquirer.js). See [example](https://github.com/vuejs-templates/webpack/blob/master/meta.json). We only support `string` and `boolean` types at the moment.
62+
- A template repo **may** have a `meta.json` file that provides a schema for the prompts. The schema will be passed to [inquirer](https://github.com/SBoudrias/Inquirer.js). See [example](https://github.com/vuejs-templates/webpack/blob/master/meta.json). We support `string`, `boolean` and `checkbox` (for multi choice) types.
6363

6464
While developing your template you can test via `vue-cli` with:
6565

bin/vue-init

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,21 @@ function ask (files, metalsmith, done) {
142142
var prompt = opts.schema[key]
143143

144144
inquirer.prompt([{
145-
type: promptInquirerTypeMapping[prompt.type],
145+
type: promptInquirerTypeMapping[prompt.type] || prompt.type,
146146
name: key,
147147
message: prompt.label || key,
148-
default: prompt.default
148+
default: prompt.default,
149+
choices: prompt.choices || []
149150
}], function (answers) {
150-
metalsmithMetadata[key] = answers[key]
151+
if (Array.isArray(answers[key])) {
152+
metalsmithMetadata[key] = {}
153+
answers[key].forEach(function (multiChoiceAnswer) {
154+
metalsmithMetadata[key][multiChoiceAnswer] = true
155+
})
156+
} else {
157+
metalsmithMetadata[key] = answers[key]
158+
}
159+
151160
done()
152161
})
153162
}

0 commit comments

Comments
 (0)