From e87a8785a8f67a9eff7b722d75bb23c304c186a6 Mon Sep 17 00:00:00 2001 From: Catouse Date: Thu, 8 Dec 2016 14:49:49 +0800 Subject: [PATCH] * change gulp watch task. --- gulpfile.js | 48 +++++++++++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 5b041b7c..647a36a2 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -440,6 +440,34 @@ gulp.task('build', function(callback) { }, type); }); +function startWatchSrc(name) { + if(name === 'lib') name = 'seperate'; + gulp.watch(["./src/less/**/*"], function(event) { + buildBundle(name, function() { + console.log(' √ '.green + (' WATCH ' + name.bold + ' COMPLETED. ').yellow.inverse); + }, 'less'); + }); + + gulp.watch(["./src/js/**/*"], function(event) { + if(event.path && (event.path.lastIndexOf('src/js/colorset.js') > -1) || event.path.lastIndexOf('src\\js\\colorset.js') > -1) return; + buildBundle(name, function() { + console.log(' √ '.green + (' WATCH ' + name.bold + ' COMPLETED. ').yellow.inverse); + }, 'js'); + }); + + gulp.watch(["./src/fonts/**/*"], function(event) { + buildBundle(name, function() { + console.log(' √ '.green + (' WATCH ' + name.bold + ' COMPLETED. ').yellow.inverse); + }, 'resource'); + }); +} + +gulp.task('watch', function(callback) { + var name = process.argv[3] || 'dist'; + if(name && name[0] === '-') name = name.substr(1); + startWatchSrc(name); +}); + ['dist', 'doc', 'theme', 'lib'].forEach(function(name) { var depsTasks = (name == 'dist' || name == 'doc') ? ['minJSON'] : []; gulp.task(name, depsTasks, function(callback) { @@ -451,25 +479,7 @@ gulp.task('build', function(callback) { }); gulp.task('watch:' + name, function() { - if(name === 'lib') name = 'seperate'; - gulp.watch(["./src/less/**/*"], function(event) { - buildBundle(name, function() { - console.log(' √ '.green + (' WATCH ' + name.bold + ' COMPLETED. ').yellow.inverse); - }, 'less'); - }); - - gulp.watch(["./src/js/**/*"], function(event) { - if(event.path && (event.path.lastIndexOf('src/js/colorset.js') > -1) || event.path.lastIndexOf('src\\js\\colorset.js') > -1) return; - buildBundle(name, function() { - console.log(' √ '.green + (' WATCH ' + name.bold + ' COMPLETED. ').yellow.inverse); - }, 'js'); - }); - - gulp.watch(["./src/fonts/**/*"], function(event) { - buildBundle(name, function() { - console.log(' √ '.green + (' WATCH ' + name.bold + ' COMPLETED. ').yellow.inverse); - }, 'resource'); - }); + startWatchSrc(name); }); }); -- GitLab