Skip to content

Commit

Permalink
Merge pull request #156 from IgniteUI/hPopov/fix-issue-155
Browse files Browse the repository at this point in the history
Migrate to gulp4 and update stackblitz to handle multiple demos base urls
  • Loading branch information
zdrawku authored Feb 4, 2020
2 parents 22defc7 + df65a26 commit a3a4f7e
Show file tree
Hide file tree
Showing 9 changed files with 13,874 additions and 589 deletions.
40 changes: 23 additions & 17 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const path = require("path");
const fs = require("fs");
const util = require("gulp-util");
const concat = require("gulp-concat");
const uglify = require("gulp-uglify");
const uglify = require("gulp-uglify-es").default;
const saveLicense = require("uglify-save-license");
const cleanCSS = require("gulp-clean-css");
const md5File = require('md5-file')
Expand Down Expand Up @@ -52,7 +52,7 @@ const bundles = [

var md5HashMap = {};

gulp.task("bundle-and-minify", () => {
const bundleAndMinify = (done) => {
var isDebugMode = argv.debugMode !== undefined && argv.debugMode.toLowerCase().trim() === "true";
var promises = [];
bundles.forEach(bundle => {
Expand All @@ -63,29 +63,29 @@ gulp.task("bundle-and-minify", () => {
}
});

return Promise.all(promises).then(function () {
gulp.start("generate-bundling-global-metadata");
});
});
return Promise.all(promises).then(generateBundlingGlobalMetadata(done));
}

gulp.task("bundle-and-minify:watch", ["bundle-and-minify", "generate-file-check-sum-map"], () => {
const addWatcher = (done) => {
var allFiles = [];
bundles.forEach(bundle => {
allFiles = allFiles.concat(bundle.files);
});

gulp.watch([allFiles], { cwd: baseFolder }).on('change', function(file) {
var hash = md5File.sync(file.path);
if (md5HashMap[file.path] !== hash) {
md5HashMap[file.path] = hash;
gulp.start("bundle-and-minify");
gulp.watch(allFiles, { cwd: baseFolder }, gulp.series(bundleAndMinify)).on("change", function(file) {
var filePath = path.join(`${__dirname}\\${baseFolder + file}`);
var hash = md5File.sync(filePath);
if (md5HashMap[filePath] !== hash) {
md5HashMap[filePath] = hash;
}

});
});
done();
}

// Generating hash per each file in the bundles based on its content.
// It is used to generate a new bundle only if the content of a file is changed.
gulp.task("generate-file-check-sum-map", () => {
const generateFileCheckSumMap = (done) => {
var allFiles = [];
bundles.forEach(bundle => {
allFiles = allFiles.concat(bundle.files);
Expand All @@ -96,9 +96,10 @@ gulp.task("generate-file-check-sum-map", () => {
var hash = md5File.sync(filePath);
md5HashMap[filePath] = hash;
});
})
done();
}

gulp.task("generate-bundling-global-metadata", () => {
const generateBundlingGlobalMetadata = (done) => {
var metadata = {};
// for general cache invalidation purposes
metadata["_timestamp"] = new Date().getTime();
Expand All @@ -108,7 +109,9 @@ gulp.task("generate-bundling-global-metadata", () => {
});

fs.writeFileSync(path.join(__dirname, "template", "bundling.global.json"), JSON.stringify(metadata));
})

done();
}

function bundleAndMinifyJS(files, fileName, outputFolder, isDebugMode) {
return new Promise(function(resolve, reject) {
Expand Down Expand Up @@ -138,3 +141,6 @@ function bundleAndMinifyCSS(files, fileName, outputFolder, isDebugMode) {
.on('end', resolve);
});
}

exports.bundleAndMinify = bundleAndMinify;
exports.bundleAndMinifyWatch = gulp.series(bundleAndMinify, generateFileCheckSumMap, addWatcher);
Loading

0 comments on commit a3a4f7e

Please sign in to comment.