mod-build 3.6.21 → 3.6.22-beta.2
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 +88 -0
- package/gulp-tasks/serve.js +1 -1
- 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','grab-global-images', 'js-lint', 'html-min', '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,88 @@
|
|
|
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
|
+
return new Promise(resolve => { // eslint-disable-line no-undef
|
|
10
|
+
request(url)
|
|
11
|
+
.on('response', resp => {
|
|
12
|
+
if (resp.statusCode !== 200 && resp.statusCode !== 206) {
|
|
13
|
+
throw new Error(`${resp.statusCode} Error while fetching ${fileName}`);
|
|
14
|
+
} else {
|
|
15
|
+
images.push(fileName);
|
|
16
|
+
}
|
|
17
|
+
})
|
|
18
|
+
.pipe(source(fileName))
|
|
19
|
+
.pipe(gulp.dest(`${siteSettings.srcFolder}/resources/images/`))
|
|
20
|
+
.on('finish', resolve);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function replaceImagePath(gulp, siteSettings) {
|
|
25
|
+
var stream = gulp.src(`${siteSettings.tmpFolder}/index.html`);
|
|
26
|
+
if (images.length) {
|
|
27
|
+
images.forEach(function(image) {
|
|
28
|
+
stream = stream.pipe(replace(new RegExp(`(https?:\/\/.*${image})`, 'gm'), '/resources/images/' + image))
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
return stream.pipe(gulp.dest(siteSettings.tmpFolder))
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const getTags = (string) => {
|
|
35
|
+
const regExs = [/<img.*?src="(.*?)"[^\>]+>/g, /<use.*?href="(.*?)".*?>/g, /<source.*?srcset="(.*?)".*?>/g, /url\('#{\$path}.*?'\)/g];
|
|
36
|
+
let tags = [];
|
|
37
|
+
|
|
38
|
+
regExs.forEach((regEx) => {
|
|
39
|
+
const match = string.match(regEx);
|
|
40
|
+
|
|
41
|
+
if (match) {
|
|
42
|
+
tags = [...tags, ...match];
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
return tags;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const getUrls = (tags) => {
|
|
50
|
+
const urls = [];
|
|
51
|
+
|
|
52
|
+
tags.forEach((tag) => {
|
|
53
|
+
if (tag) {
|
|
54
|
+
let url = tag;
|
|
55
|
+
url = url.match(/(https?:\/\/[^\s]+)/gim);
|
|
56
|
+
if (url) {
|
|
57
|
+
url = url[0];
|
|
58
|
+
url = url.replace(/"/g, "")
|
|
59
|
+
urls.push(url)
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
return [...new Set(urls)]; // eslint-disable-line no-undef
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const parseImageSources = (gulp, siteSettings) => {
|
|
68
|
+
const text = fs.readFileSync(`${siteSettings.tmpFolder}/index.html`, 'utf8');
|
|
69
|
+
const textMatches = getTags(text);
|
|
70
|
+
return getUrls(textMatches);
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
module.exports = function(gulp, siteSettings, siteData) {
|
|
74
|
+
return function() {
|
|
75
|
+
const { isWhiteLabel } = siteData;
|
|
76
|
+
const urls = parseImageSources(gulp, siteSettings);
|
|
77
|
+
const ouputPath = isWhiteLabel ? 'images/' : 'temp/assets/images/';
|
|
78
|
+
const urlsPromises = urls.map((url) => {
|
|
79
|
+
const fileName = url.slice(url.lastIndexOf('/') + 1);
|
|
80
|
+
const relativePath = ouputPath + url.replace(fileName, '');
|
|
81
|
+
return streamToDestination(gulp, siteSettings, url, fileName, relativePath);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
return Promise.all(urlsPromises).then(function() { // eslint-disable-line no-undef
|
|
85
|
+
replaceImagePath(gulp, siteSettings)
|
|
86
|
+
})
|
|
87
|
+
};
|
|
88
|
+
};
|
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
|
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
|