gpt4 book ai didi

javascript - 从 yeoman 生成器本身将目录更改为新创建的 yeoman 项目

转载 作者:行者123 更新时间:2023-11-29 21:34:20 25 4
gpt4 key购买 nike

我想将一个项目搭建到同名目录中,在生成器完成其工作后,我希望将消费者重定向到该文件夹​​。

所以我接受项目名称作为参数: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 文件夹中。有人知道如何解决吗?

最佳答案

Yeoman 不会为用户更改目录。

您可以使用 process.chdir() 手动完成此操作

关于javascript - 从 yeoman 生成器本身将目录更改为新创建的 yeoman 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35272760/

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