【发布时间】:2016-02-08 15:04:54
【问题描述】:
我想将一个项目搭建到同名目录中,并且在生成器完成其工作后,我希望消费者被重定向到该文件夹。
所以我接受项目名称作为参数:this.argument('name', { type: String, required: false });,然后创建该文件夹并将 destinationRoot 更改为它:
if (this.name) {
mkdirp(this.name);
this.destinationRoot(this.destinationPath(this.name));
}
毕竟我想在runContext cycle 的最后阶段制作一个cd this.name。我尝试将destinationRoot 更改为父目录,然后将cd 更改为它,它应该可以工作,但它没有:
end: function () {
if (this.name) {
console.log('BEFORE', ls('.'))
this.destinationRoot('..');
console.log('AFTER', ls('.'))
cd(this.name);
}
},
这里是日志:
BEFORE [ 'README.md', 'index.js', 'package.json', 'test.js' ]
AFTER [ 'meow' ]
但它不起作用,因为一旦 yeoman 完成它的工作,我仍然在当前文件夹中,而不是在 meow 文件夹中。有人知道怎么解决吗?
【问题讨论】:
标签: javascript yeoman scaffolding yeoman-generator cd