Upgrade to Pro — share decks privately, control downloads, hide ads and more …

プログラマのためのGulp入門

 プログラマのためのGulp入門

オープンセミナー2015@広島の懇親会という名のLT駆動開発11のLTスライドです。(実は2週目に突入しなかったのでLTしてない)

http://osh-web.github.io/2015/
https://github.com/LTDD/Sessions/wiki/LT%E9%A7%86%E5%8B%95%E9%96%8B%E7%99%BA11

Qiita版
http://qiita.com/eielh/items/0ed141c0bda3663872b7
解説
http://blog.eiel.info/blog/2015/02/16/ltdd-11-gulp/

Tomohiko Himura

February 15, 2015
Tweet

More Decks by Tomohiko Himura

Other Decks in Programming

Transcript

  1. var gulp = require('gulp'); // λεΫఆٛ gulp.task('hoge', function () {

    // λεΫͷ಺༰ gulp.src('src/*') .pipe(gulp.dest('dest')); }); // $ gulp hoge ͷ୅ΘΓ gulp.start(['hoge']);
  2. for file in src/* do cat < $file > dest/`basename

    $file` done ࣮ࡍʹ΍ͬͯΔ͜ͱ
  3. for file in src/* do cat < $file > dest/`basename

    $file` done ࣮ࡍʹ΍ͬͯΔ͜ͱ ϑΝΠϧҰཡͷετϦʔϜΛͭ͘Δ ͻͱͭͻͱͭͷϑΝΠϧͷετϦʔϜΛͻΒ͍ͯ EFTUσΟϨΫτϦ΁ಉ໊͡લͰ
  4. gulp.task var Orchestrator = require('orchestrator'); function Gulp() { Orchestrator.call(this); }

    util.inherits(Gulp, Orchestrator); Gulp.prototype.task = Gulp.prototype.add;
  5. gulp.task var Orchestrator = require('orchestrator'); function Gulp() { Orchestrator.call(this); }

    util.inherits(Gulp, Orchestrator); Gulp.prototype.task = Gulp.prototype.add; HVMQUBTL0SDIFTUSBUPSQSPUPUZQFBEE
  6. 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); };
  7. 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); }; HVMQTSDWJOZMGTTSD HVMQEFTUWJOZMGTETU HVMQXBUDIWJOZMGTXBUDI
  8. event-stream.map var es = require('event-stream') transformer = function (n,callback) {

    // nΛ΄͛΄͛͢Δ callbalk(null,n); } es.map(transformer) // => TransformετϦʔϜ
  9. VinylετϦʔϜΛͭͬͯ͘ΈΔ var gulp = require('gulp'); var es = require('event-stream'); var

    Vinyl = require('vinyl'); var file = new Vinyl({ path: 'hoge.txt', contenst: new Buffer('hoge') }); es.readArray([file]) // Ϧετ͔ΒετϦʔϜ΁ .pipe(gulp.dest('src')); // create src/hoge.txt
  10. VinylετϦʔϜΛͭͬͯ͘ΈΔ var gulp = require('gulp'); var es = require('event-stream'); var

    Vinyl = require('vinyl'); var file = new Vinyl({ path: 'hoge.txt', contenst: new Buffer('hoge') }); es.readArray([file]) // Ϧετ͔ΒετϦʔϜ΁ .pipe(gulp.dest('src')); // create src/hoge.txt DBUTSDIPHFUYU IPHF
  11. cat src/hoge.txt | nl > dst/hoge.txt var gulp = require('gulp');

    var run = require('gulp-run'); gulp.src('src/hoge.txt') .pipe(run("nl")) .pipe(gulp.dest('dest'));
  12. cat src/hoge.txt | nl > dst/hoge.txt var gulp = require('gulp');

    var run = require('gulp-run'); gulp.src('src/hoge.txt') .pipe(run("nl")) .pipe(gulp.dest('dest')); DBUEFTUIPHFUYU IPHF
  13. mypluginͷத਎ var myplugin = function () { var line_process =

    function (line,callback) { if (line == "") { callback(); } else { callback(null,"prefix " + line + "\n"); } }; var plugin = function (file,callback) { file.contents = file.contents .pipe(es.split("\n")) .pipe(es.map(line_process)); callback(null,file); }; return es.map(plugin); };
  14. mypluginͷத਎ var myplugin = function () { var line_process =

    function (line,callback) { if (line == "") { callback(); } else { callback(null,"prefix " + line + "\n"); } }; var plugin = function (file,callback) { file.contents = file.contents .pipe(es.split("\n")) .pipe(es.map(line_process)); callback(null,file); }; return es.map(plugin); }; ϑΝΠϧͷத਎Λ͍͡Δ৔߹͸ೋ౓ͷNBQ
  15. ·ͱΊ • Gulp = make + ϑΝΠϧ؂ࢹ • Gulp͸ VinylετϦʔϜΛܨ͍ͰॲཧΛ͢Δ

    • ϑΝΠϧͷத਎ͷετϦʔϜͰ͸ͳ͍ • Vinyl ͸ϑΝΠϧͷந৅Խͨ͠΋ͷ