6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

gulpポリスに怒られないタスクの書き方:自動bowerインストール編

Posted at

タスクの中でbower install的なことをしたかった話。

ダメだった方

最初に目についたgulp-installというのを使ってざっくり下記な感じでやってみた。

が、これが癖者。finishのイベントのハンドリングがうまくいかない

bad-case.js
gulp.task('install', function(cb){
  gulp.src(["./bower.json"])
    .pipe(install())
    .on('finish', function(){
      cb();
 	 });
  });
});

もっかい調べてみる。

調べると類似でgulp-bowerなんかを見つけたりした。
が、ここでひとまず落ち着いてblacklistを見てみる。

gulp-installgulp-bower、どっちも載っている。
これではgulpポリスに怒られてしまう。

なおす

gulp-installについては "use gulp-spawn"だそうな。

今回やりたい事はbowerを自動でインストールしたいというところなので、gulp-bowerあたりをみる。

"use the bower module directly"

なるほど。bower直接使えと。

bowerの公式を見ながらこんな感じで書いてみる

bower-directory.js
gulp.task('install', function(cb){
  bower.commands.install()
    .on("log", function(log){
      gutil.log(log.message);
    })
    .on("end", function(){
      cb();
    });
});

なるほど。うまく動いたっぽい。

締め

blacklist、普段はあのやり方好きじゃないなーと思って最初見てなかったけど、今回は普通に役に立った。

6
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?