mod-build 3.6.30 → 3.6.31
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/CHANGELOG.md +4 -0
- package/gulp-tasks/grab-global-images.js +26 -14
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,11 +2,22 @@ var fs = require('fs');
|
|
|
2
2
|
var request = require('request');
|
|
3
3
|
var source = require('vinyl-source-stream');
|
|
4
4
|
var replace = require('gulp-replace');
|
|
5
|
+
var path = require('path')
|
|
5
6
|
|
|
6
|
-
var
|
|
7
|
+
var imagePaths = [];
|
|
7
8
|
|
|
8
|
-
function
|
|
9
|
-
|
|
9
|
+
function getFilePathFromURL(url) {
|
|
10
|
+
let pathName = new URL(url).pathname;
|
|
11
|
+
pathName = pathName.substring(0, pathName.lastIndexOf('/'));
|
|
12
|
+
pathName = pathName.replace('/quote/resources/', '');
|
|
13
|
+
|
|
14
|
+
return pathName;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function streamToDestination(gulp, siteSettings, url) {
|
|
18
|
+
let finalDestination;
|
|
19
|
+
const fileName = path.basename(url);
|
|
20
|
+
const filePath = getFilePathFromURL(url);
|
|
10
21
|
|
|
11
22
|
if (!fs.existsSync(siteSettings.distFolder)) {
|
|
12
23
|
finalDestination = siteSettings.srcFolder;
|
|
@@ -20,29 +31,31 @@ function streamToDestination(gulp, siteSettings, url, fileName) {
|
|
|
20
31
|
if (resp.statusCode !== 200 && resp.statusCode !== 206) {
|
|
21
32
|
throw new Error(`${resp.statusCode} Error while fetching ${fileName}`);
|
|
22
33
|
} else {
|
|
23
|
-
|
|
34
|
+
imagePaths.push(url);
|
|
24
35
|
}
|
|
25
36
|
})
|
|
26
37
|
.pipe(source(fileName))
|
|
27
|
-
.pipe(gulp.dest(`${finalDestination}/resources
|
|
38
|
+
.pipe(gulp.dest(`${finalDestination}/resources/${filePath}`))
|
|
28
39
|
.on('finish', resolve);
|
|
29
40
|
});
|
|
30
41
|
}
|
|
31
42
|
|
|
32
43
|
function replaceImagePath(gulp, siteSettings) {
|
|
33
|
-
|
|
44
|
+
var finalDestination;
|
|
34
45
|
|
|
35
46
|
if (!fs.existsSync(siteSettings.distFolder)) {
|
|
36
47
|
finalDestination = siteSettings.tmpFolder;
|
|
37
48
|
} else {
|
|
38
49
|
finalDestination = siteSettings.distFolder;
|
|
39
|
-
|
|
50
|
+
}
|
|
40
51
|
|
|
41
|
-
|
|
52
|
+
var stream = gulp.src(`${finalDestination}/index.html`);
|
|
42
53
|
|
|
43
|
-
if (
|
|
44
|
-
|
|
45
|
-
|
|
54
|
+
if (imagePaths.length) {
|
|
55
|
+
imagePaths.forEach(function(imagePath) {
|
|
56
|
+
const fileName = path.basename(imagePath);
|
|
57
|
+
const filePath = getFilePathFromURL(imagePath);
|
|
58
|
+
stream = stream.pipe(replace(new RegExp(`"${imagePath}"`, 'gm'), `"/resources/${filePath}/${fileName}"`))
|
|
46
59
|
});
|
|
47
60
|
}
|
|
48
61
|
return stream.pipe(gulp.dest(finalDestination))
|
|
@@ -90,9 +103,8 @@ const parseImageSources = (gulp, siteSettings) => {
|
|
|
90
103
|
module.exports = function(gulp, siteSettings, siteData) {
|
|
91
104
|
return async function() {
|
|
92
105
|
const urls = parseImageSources(gulp, siteSettings);
|
|
93
|
-
const urlsPromises = urls.map(async(url) => {
|
|
94
|
-
|
|
95
|
-
return await streamToDestination(gulp, siteSettings, url, fileName);
|
|
106
|
+
const urlsPromises = urls.map(async (url) => {
|
|
107
|
+
return await streamToDestination(gulp, siteSettings, url);
|
|
96
108
|
});
|
|
97
109
|
|
|
98
110
|
return await Promise.all(urlsPromises).then(function() { // eslint-disable-line no-undef
|