簡體   English   中英

用編程器以編程方式安裝?

[英]Programmatically install with bower?

我正在編寫一個grunt任務,我想以編程方式安裝依賴項。 但是,我似乎無法弄清楚如何使用他們的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

這樣做的正確方法是什么?

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM