我正在尝试使用yeoman自定义生成器搭建应用程序时启动git repo,这是我在install
步骤中得到的:
install: function () {
this.installDependencies();
this.spawnCommand('npm', ['i', '--save' , 'express', 'mongodb', 'mongoose', 'lodash', 'bluebird', 'async', 'morgan']);
this.spawnCommand('git' ['init']); // Here fails
this.spawnCommand('git', ['add', '.']);
this.spawnCommand('git', ['commit', '-am', '"yo scaffolded app"']);
}
然而,当我试图运行时,我得到:
events.js:85
throw er; // Unhandled 'error' event
^
TypeError: Bad argument
at TypeError (native)
at ChildProcess.spawn (child_process.js:1136:26)
at Object.exports.spawn (child_process.js:995:9)
at spawn (/storage/home/dev/generator-koala/node_modules/yeoman-generator/node_modules/cross-spawn/index.js:87:19)
at spawnCommand (/storage/home/dev/generator-koala/node_modules/yeoman-generator/lib/actions/spawn_command.js:17:10)
at module.exports.yeoman.generators.Base.extend.install (/storage/home/dev/generator-koala/generators/app/index.js:72:10)
at /storage/home/dev/generator-koala/node_modules/yeoman-generator/lib/base.js:421:16
at processImmediate [as _immediateCallback] (timers.js:367:17)
我安装了git,我应该如何解决这个问题?
答案 0 :(得分:0)
您没有使用回调,因此将spawnCommand
更改为spawnCommandSync
install: function () {
this.installDependencies();
this.spawnCommandSync('npm', ['i', '--save' , 'express', 'mongodb', 'mongoose', 'lodash', 'bluebird', 'async', 'morgan']);
this.spawnCommandSync('git' ['init']);
this.spawnCommandSync('git', ['add', '.']);
this.spawnCommandSync('git', ['commit', '-am', '"yo scaffolded app"']);
}