const Generator = require('yeoman-generator');
module.exports = class extends Generator {
prompting(){
// Yeoman在查询用户环节会自动调用此方法
// 在此方法中可以调用父类的prompt()方法发出对用户的命令行询问
return this.prompt([
{
type: 'input',
name: 'name',
message: 'Your project name',
default: this.appname, // appname 为项目生成目录名称
}
]).then(answers => {
// answers => {name:'user input value'}
this.answers = answers
})
}
writing(){
// 通过模板方式写入文件到目录
// 模板文件路径
const tmpl = this.templatePath('foo.txt');
// 输出目标路径
const output = this.destinationPath('foo.txt');
// 模板数据上下文
const context = this.answers;
this.fs.copyTpl(tmpl,output,context);
}
}
const Generator = require('yeoman-generator');
module.exports = class extends Generator {
prompting(){
// Yeoman在查询用户环节会自动调用此方法
// 在此方法中可以调用父类的prompt()方法发出对用户的命令行询问
return this.prompt([
{
type: 'input',
name: 'name',
message: 'Your project name',
default: this.appname, // appname 为项目生成目录名称
}
]).then(answers => {
// answers => {name:'user input value'}
this.answers = answers
})
}
writing(){
// 通过模板方式写入文件到目录
// 模板文件路径
const tmpl = this.templatePath('foo.txt');
// 输出目标路径
const output = this.destinationPath('foo.txt');
// 模板数据上下文
const context = this.answers;
this.fs.copyTpl(tmpl,output,context);
}
}

浙公网安备 33010602011771号