以编程方式安装与凉亭?

我正在写一个咕task任务,我想以编程方式安装依赖项。 但是,我似乎无法弄清楚如何使用他们的API。

这工作得很好,但parsing响应是脆弱的,因为它使用CLI:

grunt.util.spawn({ cmd: 'bower', args: ['install', '--save', 'git@github.com:foo/bar.git'] }, function(none, message) { grunt.log.writeln(message); }); 

这不起作用:

 bower.commands.install.line(['--save', 'git@github.com:foo/bar.git']) .on('end', function(data) { grunt.log.writeln(data); done(); }) .on('err', function(err) { grunt.log.fail(err); done(); }); 

我得到以下错误:

 $ grunt my-task Running "my-task:default_options" (my-task) task Fatal error: Could not find any dependencies 

什么是正确的方法来做到这一点?

line()函数期望整个argv,所以应该是:

bower.commands.install.line(['node', 'bower', '--save', 'git@github.com:foo/bar.git']);

但是,您应该直接将path和选项直接传递给install()方法:

bower.commands.install(['git@github.com:foo/bar.git'], {save: true});