mod-build 3.6.22-beta.1 → 3.6.22-beta.3

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.
@@ -3,28 +3,48 @@ var request = require('request');
3
3
  var source = require('vinyl-source-stream');
4
4
  var replace = require('gulp-replace');
5
5
 
6
+ var images = [];
7
+
6
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
+
7
17
  return new Promise(resolve => { // eslint-disable-line no-undef
8
18
  request(url)
9
19
  .on('response', resp => {
10
20
  if (resp.statusCode !== 200 && resp.statusCode !== 206) {
11
21
  throw new Error(`${resp.statusCode} Error while fetching ${fileName}`);
12
22
  } else {
13
- replaceImgSrc(gulp, siteSettings, fileName);
23
+ images.push(fileName);
14
24
  }
15
25
  })
16
26
  .pipe(source(fileName))
17
- .pipe(gulp.dest(`${siteSettings.srcFolder}/resources/images/`))
27
+ .pipe(gulp.dest(`${finalDestination}/resources/images/`))
18
28
  .on('finish', resolve);
19
29
  });
20
30
  }
21
31
 
22
- function replaceImgSrc(gulp, siteSettings, fileName) {
23
- const fileRegex = new RegExp(`(https?:\/\/.*${fileName})`, 'gm');
32
+ function replaceImagePath(gulp, siteSettings) {
33
+ var finalDestination;
34
+ var stream = gulp.src(`${finalDestination}/index.html`);
24
35
 
25
- return gulp.src(`${siteSettings.tmpFolder}/index.html`)
26
- .pipe(replace(fileRegex, '/resources/images/' + fileName))
27
- .pipe(gulp.dest('.'));
36
+ if (!fs.existsSync(siteSettings.distFolder)) {
37
+ finalDestination = siteSettings.tmpFolder;
38
+ } else {
39
+ finalDestination = siteSettings.distFolder;
40
+ }
41
+
42
+ if (images.length) {
43
+ images.forEach(function(image) {
44
+ stream = stream.pipe(replace(new RegExp(`"(?:(?!"|")[\\s\\S])+(${image})"`, 'gm'), '"/resources/images/' + image + '"'))
45
+ });
46
+ }
47
+ return stream.pipe(gulp.dest(finalDestination))
28
48
  }
29
49
 
30
50
  const getTags = (string) => {
@@ -67,16 +87,15 @@ const parseImageSources = (gulp, siteSettings) => {
67
87
  };
68
88
 
69
89
  module.exports = function(gulp, siteSettings, siteData) {
70
- return function() {
71
- const { isWhiteLabel } = siteData;
90
+ return async function() {
72
91
  const urls = parseImageSources(gulp, siteSettings);
73
- const ouputPath = isWhiteLabel ? 'images/' : 'temp/assets/images/';
74
- const urlsPromises = urls.map((url) => {
75
- const fileName = url.slice(url.lastIndexOf('/') + 1);
76
- const relativePath = ouputPath + url.replace(fileName, '');
77
- return streamToDestination(gulp, siteSettings, url, fileName, relativePath);
92
+ const urlsPromises = urls.map(async(url) => {
93
+ const fileName = await url.slice(url.lastIndexOf('/') + 1);
94
+ return await streamToDestination(gulp, siteSettings, url, fileName);
78
95
  });
79
96
 
80
- return Promise.all(urlsPromises); // eslint-disable-line no-undef
97
+ return await Promise.all(urlsPromises).then(function() { // eslint-disable-line no-undef
98
+ replaceImagePath(gulp, siteSettings)
99
+ })
81
100
  };
82
101
  };
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mod-build",
3
- "version": "3.6.22-beta.1",
3
+ "version": "3.6.22-beta.3",
4
4
  "description": "Share components for S3 sites.",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"