mod-build 3.6.22-beta.2 → 3.6.22-beta.4
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/grab-global-images.js +26 -12
- package/package.json +1 -1
|
@@ -6,6 +6,14 @@ var replace = require('gulp-replace');
|
|
|
6
6
|
var images = [];
|
|
7
7
|
|
|
8
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
|
+
|
|
9
17
|
return new Promise(resolve => { // eslint-disable-line no-undef
|
|
10
18
|
request(url)
|
|
11
19
|
.on('response', resp => {
|
|
@@ -16,19 +24,28 @@ function streamToDestination(gulp, siteSettings, url, fileName) {
|
|
|
16
24
|
}
|
|
17
25
|
})
|
|
18
26
|
.pipe(source(fileName))
|
|
19
|
-
.pipe(gulp.dest(`${
|
|
27
|
+
.pipe(gulp.dest(`${finalDestination}/resources/images/`))
|
|
20
28
|
.on('finish', resolve);
|
|
21
29
|
});
|
|
22
30
|
}
|
|
23
31
|
|
|
24
32
|
function replaceImagePath(gulp, siteSettings) {
|
|
25
|
-
|
|
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
|
+
|
|
26
43
|
if (images.length) {
|
|
27
44
|
images.forEach(function(image) {
|
|
28
|
-
stream = stream.pipe(replace(new RegExp(`(
|
|
45
|
+
stream = stream.pipe(replace(new RegExp(`"(?:(?!"|")[\\s\\S])+(${image})"`, 'gm'), '"/resources/images/' + image + '"'))
|
|
29
46
|
});
|
|
30
47
|
}
|
|
31
|
-
return stream.pipe(gulp.dest(
|
|
48
|
+
return stream.pipe(gulp.dest(finalDestination))
|
|
32
49
|
}
|
|
33
50
|
|
|
34
51
|
const getTags = (string) => {
|
|
@@ -71,17 +88,14 @@ const parseImageSources = (gulp, siteSettings) => {
|
|
|
71
88
|
};
|
|
72
89
|
|
|
73
90
|
module.exports = function(gulp, siteSettings, siteData) {
|
|
74
|
-
return function() {
|
|
75
|
-
const { isWhiteLabel } = siteData;
|
|
91
|
+
return async function() {
|
|
76
92
|
const urls = parseImageSources(gulp, siteSettings);
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
const relativePath = ouputPath + url.replace(fileName, '');
|
|
81
|
-
return streamToDestination(gulp, siteSettings, url, fileName, relativePath);
|
|
93
|
+
const urlsPromises = urls.map(async(url) => {
|
|
94
|
+
const fileName = await url.slice(url.lastIndexOf('/') + 1);
|
|
95
|
+
return await streamToDestination(gulp, siteSettings, url, fileName);
|
|
82
96
|
});
|
|
83
97
|
|
|
84
|
-
return Promise.all(urlsPromises).then(function() { // eslint-disable-line no-undef
|
|
98
|
+
return await Promise.all(urlsPromises).then(function() { // eslint-disable-line no-undef
|
|
85
99
|
replaceImagePath(gulp, siteSettings)
|
|
86
100
|
})
|
|
87
101
|
};
|