gpt4 book ai didi

yeoman - 如何在 yeoman 生成器中获取嵌套提示结果

转载 作者:行者123 更新时间:2023-12-02 05:02:00 24 4
gpt4 key购买 nike

我是一名 javascript 初学者,通过遵循编写第一个生成器教程并阅读其他生成器代码,我已经成功地使用我的第一个生成器实现了这一目标。

我尝试了各种方法来使其正常工作,但都失败了,如果有人能指出我正确的方向,我将不胜感激。我可能应该指出我已经使用了generator-generator v0.4.3

哎呀忘了说问题是从 flavor 列表中获取响应。

askFor: function () {
var done = this.async();

var prompts = [{
name: 'sitename',
message: 'What would you like to name your app/site?',
default: 'New Project'
},{
type: 'checkbox',
name: 'features',
message: 'Please choose additional features',
choices:[{
name: 'Modernizr',
value: 'includeModernizr',
checked: false
},{
name: 'Respond',
value: 'includeRespond',
checked: false
}]
},{
type: 'list',
name: 'flavour',
message: 'Which type of css would you like to use?',
choices: [{
name: 'Sass',
value: 'includeSass'
},{
name: 'Sass with Compass',
value: 'includeCompass'
},{
name: 'Stylus',
value: 'includeStylus'
},{
name: 'Standard css',
value: 'includeCss'
}]
,default: 1
},{
when: function (props) {
return props.flavour.indexOf('includeSass') !== -1;
},
type: 'confirm',
name: 'libsass',
value: 'includeLibSass',
message: 'Would you like to use libsass? Read about libsass at \n' + chalk.green('https://github.com/andrew/node-sass#nodesass'),
default: false
}];

this.prompt(prompts, function (props) {
var features = props.features;

function hasFeature (feat) {
return features.indexOf(feat) !== -1;
}

this.sitename = props.sitename;

this.includeModernizr = hasFeature('includeModernizr');
this.includeRespond = hasFeature('includeRespond');

//this is obviously the wrong way to do it
this.includeSass = props.includeSass;

this.includeLibSass = props.libsass;
this.includeRubySass = !props.libsass;

done();
}.bind(this));
},

最佳答案

您可以使用 _.includes 而不是使用 hasFeature 函数来自洛达什。这是提取选择的简单方法。

this.includeModernizr = _.includes(props.features, 'includeModernizr');

关于yeoman - 如何在 yeoman 生成器中获取嵌套提示结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23353361/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com