gulpfile.js
changeset 560 1ee4e482bfe7
parent 491 c9d11caf62fc
equal deleted inserted replaced
559:ee144ed6fb03 560:1ee4e482bfe7
     1 var gulp = require('gulp'),
       
     2 	concat = require('gulp-concat');
       
     3 
     1 
     4 var package = require("./package.json"),
     2 const { src, dest, task, watch, parallel } = require('gulp');
     5 	scripts = package.scripts;
     3 const concat = require('gulp-concat');
       
     4 const less = require('gulp-less');
       
     5 
       
     6 const
       
     7 	package = require('./package.json'),
       
     8 	paths = package.paths;
     6 
     9 
     7 
    10 
     8 /** Fix pipe function */
    11 task('css', function() {
     9 function fixPipe(stream) {
    12 	return src(paths.less_main, { cwd: paths.less_base })
    10 	var origPipe = stream.pipe;
    13 		.pipe(less())
    11 	stream.pipe = function (dest) {
    14 		.pipe(dest(paths.less_target));
    12 		arguments[0] = dest.on('error', function (error) {
    15 });
    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 
    16 
    35 
    17 
    36 // Gulp tasks
    18 task('scripts', function() {
    37 gulp.task('scripts', function() {
    19 	return src(paths.sources, { cwd: paths.base })
    38 	return gulp.src(scripts.sources, {cwd: scripts.base})
    20 		.pipe(concat(paths.target.replace(/{version}/, package.version)))
    39 		.pipe(concat(scripts.target.replace(/{version}/, package.version)))
    21 		.pipe(dest(paths.base));
    40 		.pipe(gulp.dest(scripts.base));
       
    41 });
    22 });
    42 
    23 
    43 gulp.task('scripts-core', function() {
    24 
    44 	return gulp.src(scripts.core_sources, {cwd: scripts.base})
    25 task('scripts_core', function() {
    45 		.pipe(concat(scripts.core_target.replace(/{version}/, package.version)))
    26 	return src(paths.core_sources, { cwd: paths.base })
    46 		.pipe(gulp.dest(scripts.base));
    27 		.pipe(concat(paths.core_target.replace(/{version}/, package.version)))
       
    28 		.pipe(dest(paths.base));
    47 });
    29 });
    48 
    30 
    49 gulp.task('watch', function() {
       
    50 	gulp.watch(scripts.sources, {cwd: scripts.base}, ['scripts', 'scripts-core']);
       
    51 });
       
    52 
    31 
    53 gulp.task('default', ['scripts', 'scripts-core', 'watch']);
    32 exports.default = function() {
       
    33 	watch(paths.sources, { cwd: paths.base }, parallel('scripts', 'scripts_core'));
       
    34 	watch(paths.less_sources, { cwd: paths.less_base}, parallel('css'));
       
    35 };