Last active
January 1, 2016 05:19
-
-
Save Integralist/8098172 to your computer and use it in GitHub Desktop.
Playing around with http://gulpjs.com/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var gulp = require('gulp'); | |
var size = require('gulp-filesize'); | |
var stream = require('stream'); | |
var util = require('util'); | |
var styles = 'Assets/Styles'; | |
var scripts = 'Assets/Scripts'; | |
function aNewWritableStream() { | |
stream.Writable.call(this, { objectMode: true }); // make Stream behave like stream of objects instead of a Buffer with a set size | |
this.on('finish', function() { | |
console.log('Stream has finished, no more events can come through without causing an error'); | |
}); | |
} | |
util.inherits(aNewWritableStream, stream.Writable); | |
aNewWritableStream.prototype._write = function(chunk, encoding, next) { | |
console.log(chunk.contents.toString(encoding)); // logs content of file | |
next(); | |
}; | |
// We need mulitiple Streams to be created for us to pipe the data through to | |
var writableStuff1 = new aNewWritableStream(); | |
var writableStuff2 = new aNewWritableStream(); | |
gulp.task('filesizes', function() { | |
gulp.src(styles + '/**/*.css').pipe(size()).pipe(writableStuff1); | |
gulp.src(scripts + '/**/*.js').pipe(size()).pipe(writableStuff2); | |
}); | |
gulp.task('default', function() { | |
gulp.watch([ | |
styles + '/**/*.css', | |
scripts + '/**/*.js', | |
'./gulpfile.js' | |
], function() { | |
gulp.run('filesizes'); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var gulp = require('gulp'); | |
gulp.task('test', function(cb) { | |
cb(null); // when the async task is done we execute our callback | |
}); | |
gulp.task('default', function() { | |
gulp.watch([ | |
'./gulpfile.js' | |
], function() { | |
gulp.run('test', doSomethingAsync); | |
}); | |
}); | |
function doSomethingAsync(err) { | |
if (err) console.log('Error: ' + err); | |
console.log('Our async task is complete and this is the callback to do something else after the async task'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment