我正在建造一个自耕农发电机。我提示用户将项目命名为:
SimplesiteGenerator.prototype.askFor = function askFor() {
var cb = this.async();
console.log(this.yeoman);
var prompts = [{
name: 'siteName',
message: 'What do you want to call your site?'
}];
this.prompt(prompts, function (props) {
this.siteName = props.siteName;
cb();
}.bind(this));
};
接下来,我构建了文件系统:
SimplesiteGenerator.prototype.app = function app() {
this.mkdir( 'app');
this.mkdir('app/templates');
this.mkdir( 'img');
我想在与项目同名的目录中构建文件系统。如何获取用户提供的选项并将其传递到app?
答案 0 :(得分:0)
您需要创建一个空的全局变量,然后为其分配用户答案的值,如此
var projectFolderName = '';
this.prompt(prompts, function (props) {
this.siteName = props.siteName;
projectFolderName = props.siteName;
cb();
}.bind(this));
然后通过串联将此变量注入构建路径字符串
SimplesiteGenerator.prototype.app = function app() {
this.mkdir( 'app/' + projectFolderName);
this.mkdir('app/templates');
this.mkdir( 'img');
}