gulpfile.js
changeset 556 3b84c6308d55
child 491 c9d11caf62fc
equal deleted inserted replaced
-1:000000000000 556:3b84c6308d55
       
     1 var gulp = require('gulp'),
       
     2 	concat = require('gulp-concat');
       
     3 
       
     4 var package = require("./package.json"),
       
     5 	scripts = package.scripts,
       
     6 	sources = scripts.sources;
       
     7 
       
     8 
       
     9 /** Fix pipe function */
       
    10 function fixPipe(stream) {
       
    11 	var origPipe = stream.pipe;
       
    12 	stream.pipe = function (dest) {
       
    13 		arguments[0] = dest.on('error', function (error) {
       
    14 			var nextStreams = dest._nextStreams;
       
    15 			if (nextStreams) {
       
    16 				nextStreams.forEach(function (nextStream) {
       
    17 					nextStream.emit('error', error);
       
    18 				});
       
    19 			} else if (dest.listeners('error').length === 1) {
       
    20 				throw error;
       
    21 			}
       
    22 		});
       
    23 		var nextStream = fixPipe(origPipe.apply(this, arguments));
       
    24 		(this._nextStreams || (this._nextStreams = [])).push(nextStream);
       
    25 		return nextStream;
       
    26 	};
       
    27 	return stream;
       
    28 }
       
    29 
       
    30 var origSrc = gulp.src;
       
    31 
       
    32 gulp.src = function() {
       
    33 	return fixPipe(origSrc.apply(this, arguments));
       
    34 };
       
    35 
       
    36 
       
    37 // Gulp tasks
       
    38 gulp.task('scripts', function() {
       
    39 	return gulp.src(sources, {cwd: scripts.base})
       
    40 		.pipe(concat(scripts.target.replace(/{version}/, package.version)))
       
    41 		.pipe(gulp.dest(scripts.base));
       
    42 });
       
    43 
       
    44 gulp.task('watch', function() {
       
    45 	gulp.watch(sources, {cwd: scripts.base}, ['scripts']);
       
    46 });
       
    47 
       
    48 gulp.task('default', ['scripts', 'watch']);