Refactored client-side asset build automation to fix watch triggering.

This commit is contained in:
Daniel Stolt
2015-06-10 16:26:51 +03:00
parent 9fbaed9123
commit c1eff70f4a
2 changed files with 14 additions and 17 deletions

View File

@@ -1,7 +1,7 @@
/// <binding BeforeBuild='build' ProjectOpened='watch' /> /// <binding BeforeBuild='build' ProjectOpened='watch' />
/* /*
* This gulpfile enables building of front-end assets in this project. * This gulpfile provides an automated build pipeline for client-side assets in this project.
* *
* To use this file you will need to: * To use this file you will need to:
* - Install Node.js on your machine * - Install Node.js on your machine
@@ -13,9 +13,7 @@
*/ */
var gulp = require("gulp"), var gulp = require("gulp"),
watch = require("gulp-watch"), newer = require("gulp-newer"),
watchLess = require("gulp-watch-less"),
batch = require("gulp-batch"),
plumber = require("gulp-plumber"), plumber = require("gulp-plumber"),
sourcemaps = require("gulp-sourcemaps"), sourcemaps = require("gulp-sourcemaps"),
less = require("gulp-less"), less = require("gulp-less"),
@@ -65,14 +63,15 @@ gulp.task("buildLess", function () {
}); });
gulp.task("watchLess", function () { gulp.task("watchLess", function () {
return merge([ var watcher = gulp.watch([srcLessLib, srcLessLayoutEditor], ["buildLess"]);
lessPipelineFrom(watchLess(srcLessLib, { maxListeners: 64 }), "Styles", "Lib.css"), watcher.on("change", function (event) {
lessPipelineFrom(watchLess(srcLessLayoutEditor, { maxListeners: 64 }), "Styles", "LayoutEditor.css") console.log("LESS file " + event.path + " was " + event.type + ", running the 'buildLess' task...");
]); });
}); });
function lessPipelineFrom(inputStream, outputFolder, outputFile) { function lessPipelineFrom(inputStream, outputFolder, outputFile) {
return inputStream return inputStream
.pipe(newer(outputFolder + "/" + outputFile))
.pipe(plumber()) .pipe(plumber())
.pipe(sourcemaps.init()) .pipe(sourcemaps.init())
.pipe(less()) .pipe(less())
@@ -138,15 +137,15 @@ gulp.task("buildJs", function () {
}); });
gulp.task("watchJs", function () { gulp.task("watchJs", function () {
return merge([ var watcher = gulp.watch([srcJsLib, srcJsLayoutEditor, srcJsModels], ["buildJs"]);
jsPipelineFrom(watch(srcJsLib)), watcher.on("change", function (event) {
jsPipelineFrom(watch(srcJsLayoutEditor)), console.log("JavaScript file " + event.path + " was " + event.type + ", running the 'buildJs' task...");
jsPipelineFrom(watch(srcJsModels)) });
]);
}); });
function jsPipelineFrom(inputStream, outputFolder, outputFile) { function jsPipelineFrom(inputStream, outputFolder, outputFile) {
return inputStream return inputStream
.pipe(newer(outputFolder + "/" + outputFile))
.pipe(plumber()) .pipe(plumber())
.pipe(sourcemaps.init()) .pipe(sourcemaps.init())
.pipe(concat(outputFile)) .pipe(concat(outputFile))

View File

@@ -1,9 +1,7 @@
{ {
"devDependencies": { "devDependencies": {
"gulp": "^3.8.11", "gulp": "^3.8.11",
"gulp-watch": "^4.2.4", "gulp-newer": "^0.5.0",
"gulp-watch-less": "^1.0.1",
"gulp-batch": "^1.0.5",
"gulp-plumber": "^1.0.0", "gulp-plumber": "^1.0.0",
"gulp-sourcemaps": "^1.5.2", "gulp-sourcemaps": "^1.5.2",
"gulp-less": "^3.0.3", "gulp-less": "^3.0.3",
@@ -12,7 +10,7 @@
"gulp-uglify": "^1.2.0", "gulp-uglify": "^1.2.0",
"gulp-rename": "^1.2.2", "gulp-rename": "^1.2.2",
"gulp-concat": "^2.5.2", "gulp-concat": "^2.5.2",
"merge-stream": "^0.1.7" "del": "^1.1.1"
}, },
"dependencies": { } "dependencies": { }
} }