mod-build 3.6.23-beta.2 → 3.6.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/gulp-tasks/build.js +1 -1
- package/gulp-tasks/grab-global-images.js +102 -0
- package/gulp-tasks/serve.js +8 -2
- package/gulp-tasks/tasks.js +12 -0
- package/package.json +1 -1
package/gulp-tasks/build.js
CHANGED
|
@@ -10,7 +10,7 @@ module.exports = function(gulp, gulpPlugins, siteSettings, siteData) {
|
|
|
10
10
|
if (siteData.isQSPage) {
|
|
11
11
|
sequenceOpts = ['clean', 'grab-cdn', 'grab-shared-components', 'grab-shared-scripts', 'templates', 'styles', 'grab-theme-json', 'combine-files', 'grab-images', 'copy-json', 'js-lint', 'html-min', 'css-min', 'js-min', 'img-min', 'extras', 'brand', 'copy-files-to-build-path', 'cache-bust', 'grab-tooltips-json', 'build-stat'];
|
|
12
12
|
} else {
|
|
13
|
-
sequenceOpts = ['clean', 'grab-cdn', 'grab-shared-components', 'grab-shared-scripts', 'templates', 'styles', 'combine-files', 'grab-images', 'js-lint', 'html-min', 'css-min', 'js-min', 'img-min', 'extras', 'brand', 'cache-bust', 'grab-tooltips-json', 'build-stat'];
|
|
13
|
+
sequenceOpts = ['clean', 'grab-cdn', 'grab-shared-components', 'grab-shared-scripts', 'templates', 'styles', 'combine-files', 'grab-images', 'js-lint', 'html-min','grab-global-images', 'css-min', 'js-min', 'img-min', 'extras', 'brand', 'cache-bust', 'grab-tooltips-json', 'build-stat'];
|
|
14
14
|
}
|
|
15
15
|
} else {
|
|
16
16
|
sequenceOpts = ['clean', 'grab-cdn', 'grab-shared-components', 'grab-shared-scripts', 'templates', 'styles', 'js-lint', 'html-min', 'css-min', 'js-min', 'img-min', 'extras', 'brand', 'cache-bust', 'build-stat'];
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
var fs = require('fs');
|
|
2
|
+
var request = require('request');
|
|
3
|
+
var source = require('vinyl-source-stream');
|
|
4
|
+
var replace = require('gulp-replace');
|
|
5
|
+
|
|
6
|
+
var images = [];
|
|
7
|
+
|
|
8
|
+
function streamToDestination(gulp, siteSettings, url, fileName) {
|
|
9
|
+
var finalDestination;
|
|
10
|
+
|
|
11
|
+
if (!fs.existsSync(siteSettings.distFolder)) {
|
|
12
|
+
finalDestination = siteSettings.srcFolder;
|
|
13
|
+
} else {
|
|
14
|
+
finalDestination = siteSettings.distFolder;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return new Promise(resolve => { // eslint-disable-line no-undef
|
|
18
|
+
request(url)
|
|
19
|
+
.on('response', resp => {
|
|
20
|
+
if (resp.statusCode !== 200 && resp.statusCode !== 206) {
|
|
21
|
+
throw new Error(`${resp.statusCode} Error while fetching ${fileName}`);
|
|
22
|
+
} else {
|
|
23
|
+
images.push(fileName);
|
|
24
|
+
}
|
|
25
|
+
})
|
|
26
|
+
.pipe(source(fileName))
|
|
27
|
+
.pipe(gulp.dest(`${finalDestination}/resources/images/`))
|
|
28
|
+
.on('finish', resolve);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function replaceImagePath(gulp, siteSettings) {
|
|
33
|
+
var finalDestination;
|
|
34
|
+
|
|
35
|
+
if (!fs.existsSync(siteSettings.distFolder)) {
|
|
36
|
+
finalDestination = siteSettings.tmpFolder;
|
|
37
|
+
} else {
|
|
38
|
+
finalDestination = siteSettings.distFolder;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
var stream = gulp.src(`${finalDestination}/index.html`);
|
|
42
|
+
|
|
43
|
+
if (images.length) {
|
|
44
|
+
images.forEach(function(image) {
|
|
45
|
+
stream = stream.pipe(replace(new RegExp(`"(?:(?!"|")[\\s\\S])+(${image})"`, 'gm'), '"/resources/images/' + image + '"'))
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
return stream.pipe(gulp.dest(finalDestination))
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const getTags = (string) => {
|
|
52
|
+
const regExs = [/<img.*?src="(.*?)"[^\>]+>/g, /<use.*?href="(.*?)".*?>/g, /<source.*?srcset="(.*?)".*?>/g, /url\('#{\$path}.*?'\)/g];
|
|
53
|
+
let tags = [];
|
|
54
|
+
|
|
55
|
+
regExs.forEach((regEx) => {
|
|
56
|
+
const match = string.match(regEx);
|
|
57
|
+
|
|
58
|
+
if (match) {
|
|
59
|
+
tags = [...tags, ...match];
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
return tags;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const getUrls = (tags) => {
|
|
67
|
+
const urls = [];
|
|
68
|
+
|
|
69
|
+
tags.forEach((tag) => {
|
|
70
|
+
if (tag) {
|
|
71
|
+
let url = tag;
|
|
72
|
+
url = url.match(/(https?:\/\/[^\s]+)/gim);
|
|
73
|
+
if (url) {
|
|
74
|
+
url = url[0];
|
|
75
|
+
url = url.replace(/"/g, "")
|
|
76
|
+
urls.push(url)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
return [...new Set(urls)]; // eslint-disable-line no-undef
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const parseImageSources = (gulp, siteSettings) => {
|
|
85
|
+
const text = fs.readFileSync(`${siteSettings.tmpFolder}/index.html`, 'utf8');
|
|
86
|
+
const textMatches = getTags(text);
|
|
87
|
+
return getUrls(textMatches);
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
module.exports = function(gulp, siteSettings, siteData) {
|
|
91
|
+
return async function() {
|
|
92
|
+
const urls = parseImageSources(gulp, siteSettings);
|
|
93
|
+
const urlsPromises = urls.map(async(url) => {
|
|
94
|
+
const fileName = await url.slice(url.lastIndexOf('/') + 1);
|
|
95
|
+
return await streamToDestination(gulp, siteSettings, url, fileName);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
return await Promise.all(urlsPromises).then(function() { // eslint-disable-line no-undef
|
|
99
|
+
replaceImagePath(gulp, siteSettings)
|
|
100
|
+
})
|
|
101
|
+
};
|
|
102
|
+
};
|
package/gulp-tasks/serve.js
CHANGED
|
@@ -8,7 +8,7 @@ module.exports.src = function(gulp, gulpPlugins, siteSettings, siteData) {
|
|
|
8
8
|
} else if (siteData.isQSPage) {
|
|
9
9
|
sequenceOpts = ['clean', 'grab-cdn', 'grab-shared-components', 'grab-shared-scripts', 'templates', 'styles', 'grab-theme-json', 'grab-tooltips-json', 'combine-files', 'grab-images', 'js-lint'];
|
|
10
10
|
} else {
|
|
11
|
-
sequenceOpts = ['clean', 'grab-cdn', 'grab-shared-components', 'grab-shared-scripts', 'templates', 'styles', 'grab-tooltips-json', 'combine-files', 'grab-images', 'js-lint'];
|
|
11
|
+
sequenceOpts = ['clean', 'grab-cdn', 'grab-shared-components', 'grab-shared-scripts', 'templates', 'styles', 'grab-tooltips-json', 'combine-files', 'grab-images','grab-global-images', 'js-lint'];
|
|
12
12
|
}
|
|
13
13
|
runSequence(...sequenceOpts, () => {
|
|
14
14
|
// Run a BrowserSync server
|
|
@@ -36,7 +36,13 @@ module.exports.src = function(gulp, gulpPlugins, siteSettings, siteData) {
|
|
|
36
36
|
]).on('change', gulpPlugins.browserSync.reload);
|
|
37
37
|
|
|
38
38
|
// If templates changed, rerun templates task
|
|
39
|
-
|
|
39
|
+
if (!siteData.useTypescript && !siteData.isQSPage) {
|
|
40
|
+
gulp.watch(siteSettings.srcFolder + '/' + siteSettings.templatesSubfolder + '/**/*.html', function() {
|
|
41
|
+
runSequence('templates','grab-global-images')
|
|
42
|
+
});
|
|
43
|
+
} else {
|
|
44
|
+
gulp.watch(siteSettings.srcFolder + '/' + siteSettings.templatesSubfolder + '/**/*.html', ['templates'])
|
|
45
|
+
}
|
|
40
46
|
|
|
41
47
|
// If styles changed, rerun styles task
|
|
42
48
|
gulp.watch(siteSettings.srcFolder + '/' + siteSettings.stylesSubfolder + '/**/*.scss', ['styles']);
|
package/gulp-tasks/tasks.js
CHANGED
|
@@ -346,6 +346,18 @@ module.exports = function() {
|
|
|
346
346
|
|
|
347
347
|
return require(opts.gulpTasksFolderPath + '/grab-images')(opts.gulp, opts.gulpSettings, opts.siteData);
|
|
348
348
|
}
|
|
349
|
+
},
|
|
350
|
+
|
|
351
|
+
// Get global images
|
|
352
|
+
'grab-global-images': {
|
|
353
|
+
subtasks: [],
|
|
354
|
+
func: function(opts) {
|
|
355
|
+
if ('undefined' === typeof opts.gulpTasksFolderPath) {
|
|
356
|
+
opts.gulpTasksFolderPath = '.';
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
return require(opts.gulpTasksFolderPath + '/grab-global-images')(opts.gulp, opts.gulpSettings, opts.siteData);
|
|
360
|
+
}
|
|
349
361
|
},
|
|
350
362
|
|
|
351
363
|
// Copy json files to dist
|