【问题标题】:change dir to newly created yeoman project from yeoman generator itself将目录从 yeoman 生成器本身更改为新创建的 yeoman 项目
【发布时间】: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


    【解决方案1】:

    Yeoman 不会为用户更改目录。

    您也许可以使用 process.chdir() 手动执行此操作

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-18
    相关资源
    最近更新 更多