gulpfile.js
changeset 556 3b84c6308d55
child 491 c9d11caf62fc
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gulpfile.js	Wed Dec 05 13:13:47 2018 +0100
@@ -0,0 +1,48 @@
+var gulp = require('gulp'),
+	concat = require('gulp-concat');
+
+var package = require("./package.json"),
+	scripts = package.scripts,
+	sources = scripts.sources;
+
+
+/** Fix pipe function */
+function fixPipe(stream) {
+	var origPipe = stream.pipe;
+	stream.pipe = function (dest) {
+		arguments[0] = dest.on('error', function (error) {
+			var nextStreams = dest._nextStreams;
+			if (nextStreams) {
+				nextStreams.forEach(function (nextStream) {
+					nextStream.emit('error', error);
+				});
+			} else if (dest.listeners('error').length === 1) {
+				throw error;
+			}
+		});
+		var nextStream = fixPipe(origPipe.apply(this, arguments));
+		(this._nextStreams || (this._nextStreams = [])).push(nextStream);
+		return nextStream;
+	};
+	return stream;
+}
+
+var origSrc = gulp.src;
+
+gulp.src = function() {
+	return fixPipe(origSrc.apply(this, arguments));
+};
+
+
+// Gulp tasks
+gulp.task('scripts', function() {
+	return gulp.src(sources, {cwd: scripts.base})
+		.pipe(concat(scripts.target.replace(/{version}/, package.version)))
+		.pipe(gulp.dest(scripts.base));
+});
+
+gulp.task('watch', function() {
+	gulp.watch(sources, {cwd: scripts.base}, ['scripts']);
+});
+
+gulp.task('default', ['scripts', 'watch']);