【问题标题】:Programmatically install with bower?以编程方式安装凉亭?
【发布时间】:2013-02-08 19:09:13
【问题描述】:

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

这很好用,但解析响应很脆弱,因为它使用 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

这样做的正确方法是什么?

【问题讨论】:

    标签: javascript node.js bower gruntjs


    【解决方案1】:

    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});

    【讨论】:

      猜你喜欢
      • 2013-07-03
      • 2014-02-09
      • 2013-05-23
      • 2017-03-14
      • 2016-06-13
      • 2017-03-18
      • 2015-03-30
      • 2014-08-08
      • 2023-03-07
      相关资源
      最近更新 更多