LoginSignup
10
11

More than 5 years have passed since last update.

Gulp = Vinyl + Stream + Orchestrator

Last updated at Posted at 2015-02-15

この記事はプログラマのためのGulp入門の一部です。

Gulpについて調べていると出会う記事が下記です。

Gulpは「Vinyl + Stream + Orchestrator」なのである。

それはGulpのindex.jsを見れば明らかだった。

確認してみよう。

GulpのAPIには

  • task
  • src
  • dest
  • watch

がある。

gulp.task

gulp.taskはタスクを定義するためのメソッドです。
このメソッドはOrchestratorのaddメソッドだ。

下記はソースコードの抜粋です。

var Orchestrator = require('orchestrator');

function Gulp() {
  Orchestrator.call(this);
}
util.inherits(Gulp, Orchestrator);

Gulp.prototype.task = Gulp.prototype.add;

Gulp.prototype.taskOrchestrator.prototype.addの別名となっています。

GulpはOrchestratorを継承しているので、Gulp.prototype.addOrchestrator.prototype.addなのです。

Orchestratorはタスクを定義するためのライブラリであることがわかりました。

gulp.src & gulp.dest & gulp.watch

gulp.src は VinylのReadableなストリームをつくります。

gulp.dest は VinylのWritableなストリームをつくります。

gulp.watchはローカルファイルストリームの変更を検知します。

このメソッドたちのソースを見てみよう。

var vfs = require('vinyl-fs');

Gulp.prototype.src = vfs.src;
Gulp.prototype.dest = vfs.dest;
Gulp.prototype.watch = function (glob, opt, fn) {
  // (中略)
  return vfs.watch(glob, opt, fn);
};

gulp.src自体がvinyl-fsのsrcメソッドの別名であることがわかる。
gulp.destも同様である。

watchは少しラップされていますが、結局vinyl-fsのwatchを呼び出すことがわかります。

まとめ

OrchestratorはGulpのタスクをつくるライブラリです。

Vinylはファイルを抽象化したライブラリらしいです。
そのローカルファイルシステム用のアダプタであるvinyl-fsというライブラリがgulpのAPIを提供しています。

10
11
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
10
11