是否可以在安装yeoman发生器后运行grunt命令?

时间:2013-10-25 00:44:15

标签: node.js gruntjs yeoman yeoman-generator

基本上我想在生成器完成安装依赖项后运行grunt,我发现你可以在callback方法中添加installDependencies函数,以便在安装完所有内容后运行像这样:

this.on('end', function () {
    this.installDependencies({
        skipInstall: options['skip-install'],
        callback: function () {
            console.log('All done!');
        }
    });
});

但是我不确定如何运行grunt任务(如去往终端并运行“grunt”)

1 个答案:

答案 0 :(得分:5)

在this.on('end')之后添加这行

// Now you can bind to the dependencies installed event
this.on('dependenciesInstalled', function() {
    this.spawnCommand('grunt', ['build']);
});

查看此topic了解详情。

但是如果你使用的是最新的yeomen更新,你需要像这样做

this.on('end', function () {
  if (!this.options['skip-install']) {
    this.npmInstall();
    this.spawnCommand('grunt', ['prepare']); // change 'prepare' with your task.
  }
});