是否可以在yeoman生成器安装后运行grunt命令?
基本上我想在我的生成器完成安装依赖关系后运行grunt
,我发现你可以添加一个callback
函数到installDependencies
方法中,在所有事情都被安装完成后运行:
this.on('end', function () { this.installDependencies({ skipInstall: options['skip-install'], callback: function () { console.log('All done!'); } }); });
但是我不知道如何运行这个grunt
任务(就像去往terminal并运行“grunt”一样)
在此之后('结束')添加这些行
// Now you can bind to the dependencies installed event this.on('dependenciesInstalled', function() { this.spawnCommand('grunt', ['build']); });
检查这个主题了解更多细节。
但是如果你使用的是最新的更新版本,你需要这样做
this.on('end', function () { if (!this.options['skip-install']) { this.npmInstall(); this.spawnCommand('grunt', ['prepare']); // change 'prepare' with your task. } });