Michael Hsu
Try to Keep everything in Mind
Michael Hsu.tw Sep, 2014
Read in data and output data.
Everything can be processed in memory.
$ npm install -g gulp
// gulpfile.js
var gulp = require('gulp');
gulp.task('task1', function() {
// place code for your default task here
});
$ gulp task1
// gulpfile.js
var gulp = require('gulp'),
gulpConvert = require('gulp-convert');
gulp.task('yml2json', function(){
return gulp.src('documents/*.yml').pipe(gulpConvert({
from: 'yml',
to: 'json'
})).pipe(gulp.dest('documents'));
});
$ gulp yml2json
[22:15:11] Using gulpfile ~/code/gulpfile.js
[22:15:11] Starting 'yml2json'...
[22:15:11] Finished 'yml2json' after 47 ms
// gulpfile.js
var gulp = require('gulp'),
gulpConvert = require('gulp-convert');
gulp.task('yml2json', function(){
return gulp.src('documents/*.yml').pipe(gulpConvert({
from: 'yml',
to: 'json'
})).pipe(gulp.dest('documents'));
});
# gulpfile.ls
require! { gulp, gulpConvert }
gulp.task \yml2json, ->
gulp.src \documents/*.yml
.pipe gulpConvert { from: \yml, to: \json }
.pipe gulp.dest \documents
# gulpfile.ls
gulp.task \publish, <[ cleanDist usemin productionexpress mobileusemin htmlmin copy ]>
// gulpfile.js
gulp.task('publish', ['cleanDist', 'usemin', 'productionexpress', 'mobileusemin', 'htmlmin', 'copy']);
$ gulp publish
[17:30:03] Using gulpfile ~/code/gulpfile.js
[17:30:03] Starting 'cleanDist'...
[17:30:03] Starting 'usemin'...
[17:30:03] Starting 'productionexpress'...
[17:30:03] Listening on port: 1609
[17:30:03] Finished 'productionexpress' after 3.89 ms
[17:30:03] Starting 'mobileusemin'...
[17:30:03] Starting 'htmlmin'...
[17:30:03] Starting 'copy'...
[17:30:03] Finished 'cleanDist' after 20 ms
[17:30:33] Finished 'htmlmin' after 30 s
[17:30:33] Finished 'usemin' after 30 s
[17:30:33] Finished 'copy' after 30 s
[17:30:34] Finished 'mobileusemin' after 30 s
[17:30:34] Starting 'publish'...
[17:30:34] Finished 'publish' after 8.27 μs
gulp.watch('js/**/*.js', function(event) {
console.log('File ' + event.path + ' was running tasks...');
});
# gulpfile.ls
require! { gulp, \gulp-livereload, \tiny-lr }
server = tiny-lr!
gulp.task \html, ->
gulp.src \views/*.html
.pipe gulp-livereload server
gulp.task \watch, ->
server.listen 35799, ->
gulp.watch \views/*.html, <[ html ]>
gulp.watch \views/**/*.html, <[ html ]>
By Michael Hsu
Gulp.js Intro