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 CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 3.6.31
4
+
5
+ - `grab-global-images` task bug fixes.
6
+
3
7
  ## 3.6.30
4
8
 
5
9
  - Adding in the `copy-videos` gulp task needed for native landing pages.
@@ -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 images = [];
7
+ var imagePaths = [];
7
8
 
8
- function streamToDestination(gulp, siteSettings, url, fileName) {
9
- var finalDestination;
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
- images.push(fileName);
34
+ imagePaths.push(url);
24
35
  }
25
36
  })
26
37
  .pipe(source(fileName))
27
- .pipe(gulp.dest(`${finalDestination}/resources/images/`))
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
- var finalDestination;
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
- var stream = gulp.src(`${finalDestination}/index.html`);
52
+ var stream = gulp.src(`${finalDestination}/index.html`);
42
53
 
43
- if (images.length) {
44
- images.forEach(function(image) {
45
- stream = stream.pipe(replace(new RegExp(`"(?:(?!"|")[\\s\\S])+(\/${image})"`, 'gm'), '"/resources/images/' + image + '"'))
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
- const fileName = await url.slice(url.lastIndexOf('/') + 1);
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mod-build",
3
- "version": "3.6.30",
3
+ "version": "3.6.31",
4
4
  "description": "Share components for S3 sites.",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"