Skip to content

Commit a3a4f7e

Browse files
authored
Merge pull request #156 from IgniteUI/hPopov/fix-issue-155
Migrate to gulp4 and update stackblitz to handle multiple demos base urls
2 parents 22defc7 + df65a26 commit a3a4f7e

File tree

9 files changed

+13874
-589
lines changed

9 files changed

+13874
-589
lines changed

gulpfile.js

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const path = require("path");
33
const fs = require("fs");
44
const util = require("gulp-util");
55
const concat = require("gulp-concat");
6-
const uglify = require("gulp-uglify");
6+
const uglify = require("gulp-uglify-es").default;
77
const saveLicense = require("uglify-save-license");
88
const cleanCSS = require("gulp-clean-css");
99
const md5File = require('md5-file')
@@ -52,7 +52,7 @@ const bundles = [
5252

5353
var md5HashMap = {};
5454

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

66-
return Promise.all(promises).then(function () {
67-
gulp.start("generate-bundling-global-metadata");
68-
});
69-
});
66+
return Promise.all(promises).then(generateBundlingGlobalMetadata(done));
67+
}
7068

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

77-
gulp.watch([allFiles], { cwd: baseFolder }).on('change', function(file) {
78-
var hash = md5File.sync(file.path);
79-
if (md5HashMap[file.path] !== hash) {
80-
md5HashMap[file.path] = hash;
81-
gulp.start("bundle-and-minify");
75+
gulp.watch(allFiles, { cwd: baseFolder }, gulp.series(bundleAndMinify)).on("change", function(file) {
76+
var filePath = path.join(`${__dirname}\\${baseFolder + file}`);
77+
var hash = md5File.sync(filePath);
78+
if (md5HashMap[filePath] !== hash) {
79+
md5HashMap[filePath] = hash;
8280
}
81+
8382
});
84-
});
83+
done();
84+
}
8585

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

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

110111
fs.writeFileSync(path.join(__dirname, "template", "bundling.global.json"), JSON.stringify(metadata));
111-
})
112+
113+
done();
114+
}
112115

113116
function bundleAndMinifyJS(files, fileName, outputFolder, isDebugMode) {
114117
return new Promise(function(resolve, reject) {
@@ -138,3 +141,6 @@ function bundleAndMinifyCSS(files, fileName, outputFolder, isDebugMode) {
138141
.on('end', resolve);
139142
});
140143
}
144+
145+
exports.bundleAndMinify = bundleAndMinify;
146+
exports.bundleAndMinifyWatch = gulp.series(bundleAndMinify, generateFileCheckSumMap, addWatcher);

0 commit comments

Comments
 (0)