Added Gulp asset manifest change detection for non-bundled asset groups.

When running the 'build' task, a non-bundled asset group will now be rebuilt if the asset manifest file itself is newer than any of the output files.
This commit is contained in:
Daniel Stolt 2017-01-13 19:08:41 +01:00
parent 937a8f9783
commit a927cc0e1c

View File

@ -113,12 +113,6 @@ function resolveAssetGroupPaths(assetGroup, assetManifestPath) {
function createAssetGroupTask(assetGroup, doRebuild) { function createAssetGroupTask(assetGroup, doRebuild) {
var outputExt = path.extname(assetGroup.output).toLowerCase(); var outputExt = path.extname(assetGroup.output).toLowerCase();
var doConcat = path.basename(assetGroup.outputFileName, outputExt) !== "@"; var doConcat = path.basename(assetGroup.outputFileName, outputExt) !== "@";
if (doConcat && !doRebuild) {
// Force a rebuild of this asset group is the asset manifest file itself is newer than the output.
var assetManifestStats = fs.statSync(assetGroup.manifestPath);
var outputStats = fs.existsSync(assetGroup.outputPath) ? fs.statSync(assetGroup.outputPath) : null;
doRebuild = !outputStats || assetManifestStats.mtime > outputStats.mtime;
}
switch (outputExt) { switch (outputExt) {
case ".css": case ".css":
return buildCssPipeline(assetGroup, doConcat, doRebuild); return buildCssPipeline(assetGroup, doConcat, doRebuild);
@ -147,12 +141,12 @@ function buildCssPipeline(assetGroup, doConcat, doRebuild) {
generateSourceMaps = false; generateSourceMaps = false;
var minifiedStream = gulp.src(assetGroup.inputPaths) // Minified output, source mapping completely disabled. var minifiedStream = gulp.src(assetGroup.inputPaths) // Minified output, source mapping completely disabled.
.pipe(gulpif(!doRebuild, .pipe(gulpif(!doRebuild,
gulpif(doConcat, newer({
newer(assetGroup.outputPath), dest: doConcat ? assetGroup.outputPath : assetGroup.outputDir,
newer({ ext: doConcat ? null : ".css",
dest: assetGroup.outputDir, extra: assetGroup.manifestPath // Force a rebuild of this asset group is the asset manifest file itself is newer than the output(s).
ext: ".css" })
})))) ))
.pipe(plumber()) .pipe(plumber())
.pipe(gulpif("*.less", less())) .pipe(gulpif("*.less", less()))
.pipe(gulpif("*.scss", sass({ .pipe(gulpif("*.scss", sass({
@ -176,12 +170,12 @@ function buildCssPipeline(assetGroup, doConcat, doRebuild) {
.pipe(gulp.dest(assetGroup.outputDir)); .pipe(gulp.dest(assetGroup.outputDir));
var devStream = gulp.src(assetGroup.inputPaths) // Non-minified output, with source mapping. var devStream = gulp.src(assetGroup.inputPaths) // Non-minified output, with source mapping.
.pipe(gulpif(!doRebuild, .pipe(gulpif(!doRebuild,
gulpif(doConcat, newer({
newer(assetGroup.outputPath), dest: doConcat ? assetGroup.outputPath : assetGroup.outputDir,
newer({ ext: doConcat ? null : ".css",
dest: assetGroup.outputDir, extra: assetGroup.manifestPath // Force a rebuild of this asset group is the asset manifest file itself is newer than the output(s).
ext: ".css" })
})))) ))
.pipe(plumber()) .pipe(plumber())
.pipe(gulpif(generateSourceMaps, sourcemaps.init())) .pipe(gulpif(generateSourceMaps, sourcemaps.init()))
.pipe(gulpif("*.less", less())) .pipe(gulpif("*.less", less()))
@ -214,18 +208,18 @@ function buildJsPipeline(assetGroup, doConcat, doRebuild) {
if ((!doConcat || assetGroup.inputPaths.length < 2) && !assetGroup.inputPaths.some(function (inputPath) { return path.extname(inputPath).toLowerCase() === ".ts"; })) if ((!doConcat || assetGroup.inputPaths.length < 2) && !assetGroup.inputPaths.some(function (inputPath) { return path.extname(inputPath).toLowerCase() === ".ts"; }))
generateSourceMaps = false; generateSourceMaps = false;
var typeScriptOptions = { allowJs: true, noImplicitAny: true, noEmitOnError: true }; var typeScriptOptions = { allowJs: true, noImplicitAny: true, noEmitOnError: true };
if (assetGroup.typeScriptOptions) if (assetGroup.typeScriptOptions)
typeScriptOptions = Object.assign(typeScriptOptions, assetGroup.typeScriptOptions); // Merge override options from asset group if any. typeScriptOptions = Object.assign(typeScriptOptions, assetGroup.typeScriptOptions); // Merge override options from asset group if any.
if (doConcat) if (doConcat)
typeScriptOptions.outFile = assetGroup.outputFileName; typeScriptOptions.outFile = assetGroup.outputFileName;
return gulp.src(assetGroup.inputPaths) return gulp.src(assetGroup.inputPaths)
.pipe(gulpif(!doRebuild, .pipe(gulpif(!doRebuild,
gulpif(doConcat, newer({
newer(assetGroup.outputPath), dest: doConcat ? assetGroup.outputPath : assetGroup.outputDir,
newer({ ext: doConcat ? null : ".js",
dest: assetGroup.outputDir, extra: assetGroup.manifestPath // Force a rebuild of this asset group is the asset manifest file itself is newer than the output(s).
ext: ".js" })
})))) ))
.pipe(plumber()) .pipe(plumber())
.pipe(gulpif(generateSourceMaps, sourcemaps.init())) .pipe(gulpif(generateSourceMaps, sourcemaps.init()))
.pipe(typescript(typeScriptOptions)) .pipe(typescript(typeScriptOptions))