Nic*_*ner 4 javascript node.js gruntjs bower
我正在编写一个笨拙的任务,我想以编程方式安装依赖项.但是,我似乎无法弄清楚如何使用他们的API.
这很好用,但解析响应很脆弱,因为它使用CLI:
grunt.util.spawn({
cmd: 'bower',
args: ['install', '--save', 'git@github.com:foo/bar.git']
}, function(none, message) {
grunt.log.writeln(message);
});
Run Code Online (Sandbox Code Playgroud)
这不起作用:
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();
});
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
$ grunt my-task
Running "my-task:default_options" (my-task) task
Fatal error: Could not find any dependencies
Run Code Online (Sandbox Code Playgroud)
这样做的正确方法是什么?
该line()函数需要整个argv,所以应该是:
bower.commands.install.line(['node', 'bower', '--save', 'git@github.com:foo/bar.git']);
但是,您应该直接将路径和选项install()直接传递给方法:
bower.commands.install(['git@github.com:foo/bar.git'], {save: true});
| 归档时间: |
|
| 查看次数: |
1886 次 |
| 最近记录: |