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