Skip to content

Commit b5505f0

Browse files
committed
handle prompt-for default bug for all string fields
1 parent c3daf7b commit b5505f0

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

bin/vue-init

+13-4
Original file line numberDiff line numberDiff line change
@@ -95,17 +95,26 @@ function generate (src, dest, fn) {
9595
var khaos = new Khaos(template)
9696
var opts = options(src)
9797

98-
// work around prompt-for bug...
99-
// which ignores default value for strings
100-
// otherwise we can just use khaos.generate :(
10198
khaos.schema(opts.schema)
10299
khaos.read(function (err, files) {
103100
if (err) logger.fatal(err)
104101
khaos.parse(files, function (err, schema) {
105102
if (err) logger.fatal(err)
106103
khaos.prompt(schema, function (err, answers) {
107104
if (err) logger.fatal(err)
108-
if (!answers.name) answers.name = name
105+
// work around prompt-for bug...
106+
// which ignores default value for strings
107+
// otherwise we can just use khaos.generate :(
108+
Object.keys(schema).forEach(function (key) {
109+
if (
110+
typeof schema[key] === 'object' &&
111+
schema[key].type === 'string' &&
112+
schema[key].default != null &&
113+
answers[key] === ''
114+
) {
115+
answers[key] = schema[key].default
116+
}
117+
})
109118
khaos.write(dest, files, answers, fn)
110119
})
111120
})

0 commit comments

Comments
 (0)