mod-build 3.6.14 → 3.6.15-beta.1

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.15
4
+
5
+ - `grab-shared-scripts` task code refactoring changes.
6
+
3
7
  ## 3.6.14
4
8
 
5
9
  - Updating the `replaceFooterStylesReference` in `grab-shared-scripts` to use relative paths if the `useRelativePathForResources` parameter is set
@@ -5,67 +5,57 @@ var hash = require('gulp-hash');
5
5
  var tap = require('gulp-tap');
6
6
  var path = require('path');
7
7
 
8
- var modAlyticsFileName = '';
9
- var modUtilsFileName = '';
10
- var abandonmentJsFileName = '';
11
- var footerComponentJsFileName = '';
12
- var modFooterStylesFileName = '';
13
- var qsFooterStylesFileName = '';
14
- var modFormFileName = '';
15
- var qsFormFileName = '';
8
+ const fileNames = {
9
+ modAlyticsFileName: '',
10
+ modUtilsFileName: '',
11
+ abandonmentJsFileName: '',
12
+ footerComponentJsFileName: '',
13
+ modFooterStylesFileName: '',
14
+ qsFooterStylesFileName: '',
15
+ modFormFileName: '',
16
+ qsFormFileName: ''
17
+ };
18
+
19
+ var isQuotePageOrUseRelativePath = false;
20
+ var resourceURL = '';
16
21
 
17
22
  function replaceModalyticsSrc(gulp, gulpPlugins, siteSettings, siteData) {
18
- if (siteData.siteData && siteData.siteData.isQuotePage === true || siteData.siteData && siteData.siteData.useRelativePathForResources === true) {
19
- return gulp.src(siteSettings.srcFolder + '/shared-components/head/head.html')
20
- .pipe(replace(/".*(modalytics).*"/, '"{{#if this.src}}{{this.src}}{{/if}}resources/scripts/mod-alytics/' + modAlyticsFileName + '"'))
21
- .pipe(gulp.dest(siteSettings.srcFolder + '/shared-components/head'));
22
- } else {
23
- return gulp.src(siteSettings.srcFolder + '/shared-components/head/head.html')
24
- .pipe(replace(/".*(modalytics).*"/, '"/resources/scripts/mod-alytics/' + modAlyticsFileName + '"'))
23
+ const resourcePath = isQuotePageOrUseRelativePath ? '{{#if this.src}}{{this.src}}{{/if}}resources/scripts/mod-alytics/' : '/resources/scripts/mod-alytics/';
24
+
25
+ return gulp.src(siteSettings.srcFolder + '/shared-components/head/head.html')
26
+ .pipe(replace(/".*(modalytics).*"/, resourcePath + fileNames.modAlyticsFileName))
25
27
  .pipe(gulp.dest(siteSettings.srcFolder + '/shared-components/head'));
26
- }
27
28
  }
28
29
 
29
30
  function replaceFootAssetScripts(gulp, gulpPlugins, siteSettings, siteData) {
30
- if (siteData.siteData && siteData.siteData.isQuotePage === true || siteData.siteData && siteData.siteData.useRelativePathForResources === true) {
31
- return gulp.src(siteSettings.srcFolder + '/shared-components/foot-assets/foot-assets.html')
32
- .pipe(replace(/"(?:(?!"|js")[\s\S])+(modutils|mod-utils.*?)js"/, '"{{#if this.nodeModulesPath}}{{this.nodeModulesPath}}{{/if}}resources/scripts/mod-utils/' + modUtilsFileName + '"'))
33
- .pipe(replace(/"(?:(?!"|")[\s\S])+(footer\/footer-component.*?)js"/, '"{{#if this.nodeModulesPath}}{{this.nodeModulesPath}}{{/if}}resources/scripts/footer/' + footerComponentJsFileName + '"'))
34
- .pipe(replace(/"(?:(?!"|")[\s\S])+(mod-form.*?)js"/, '"{{#if this.nodeModulesPath}}{{this.nodeModulesPath}}{{/if}}resources/scripts/mod-form/' + modFormFileName + '"'))
35
- .pipe(replace(/"(?:(?!"|")[\s\S])+(qs-form.*?)js"/, '"{{#if this.nodeModulesPath}}{{this.nodeModulesPath}}{{/if}}resources/scripts/mod-form/' + qsFormFileName + '"'))
36
- .pipe(gulp.dest(siteSettings.srcFolder + '/shared-components/foot-assets'));
37
- } else {
38
- return gulp.src(siteSettings.srcFolder + '/shared-components/foot-assets/foot-assets.html')
39
- .pipe(replace(/"(?:(?!"|js")[\s\S])+(modutils|mod-utils.*?)js"/, '"/resources/scripts/mod-utils/' + modUtilsFileName + '"'))
40
- .pipe(replace(/"(?:(?!"|")[\s\S])+(footer\/footer-component.*?)js"/, '"/resources/scripts/footer/' + footerComponentJsFileName + '"'))
41
- .pipe(replace(/"(?:(?!"|")[\s\S])+(mod-form.*?)js"/, '"/resources/scripts/mod-form/' + modFormFileName + '"'))
42
- .pipe(replace(/"(?:(?!"|")[\s\S])+(qs-form.*?)js"/, '"/resources/scripts/mod-form/' + qsFormFileName + '"'))
31
+ const resourcePath = isQuotePageOrUseRelativePath ? '{{#if this.nodeModulesPath}}{{this.nodeModulesPath}}{{/if}}resources/scripts' : '/resources/scripts';
32
+
33
+ return gulp.src(siteSettings.srcFolder + '/shared-components/foot-assets/foot-assets.html')
34
+ .pipe(replace(/"(?:(?!"|js")[\s\S])+(modutils|mod-utils.*?)js"/, resourcePath + '/mod-utils/' + fileNames.modUtilsFileName))
35
+ .pipe(replace(/"(?:(?!"|")[\s\S])+(footer\/footer-component.*?)js"/, resourcePath + '/footer/' + fileNames.footerComponentJsFileName))
36
+ .pipe(replace(/"(?:(?!"|")[\s\S])+(mod-form.*?)js"/, resourcePath + '/mod-form/' + fileNames.modFormFileName))
37
+ .pipe(replace(/"(?:(?!"|")[\s\S])+(qs-form.*?)js"/, resourcePath + '/mod-form/' + fileNames.qsFormFileName))
43
38
  .pipe(gulp.dest(siteSettings.srcFolder + '/shared-components/foot-assets'));
44
- }
45
39
  }
46
40
 
47
41
  function replaceAbandonmentJsSrc(gulp, gulpPlugins, siteSettings, siteData) {
48
- if (siteData.siteData && siteData.siteData.isQuotePage === true || siteData.siteData && siteData.siteData.useRelativePathForResources === true) {
49
- return gulp.src(siteSettings.srcFolder + '/templates/abandonment/*.html')
50
- .pipe(replace(/"(?:(?!"|")[\s\S])+(abandonment\/abandonment.*?)js"/, '"resources/scripts/abandonment/' + abandonmentJsFileName + '"'))
51
- .pipe(gulp.dest(siteSettings.srcFolder + '/templates/abandonment'));
52
- } else {
53
- return gulp.src(siteSettings.srcFolder + '/templates/abandonment/*.html')
54
- .pipe(replace(/"(?:(?!"|")[\s\S])+(abandonment\/abandonment.*?)js"/, '"/resources/scripts/abandonment/' + abandonmentJsFileName + '"'))
42
+ const resourcePath = isQuotePageOrUseRelativePath ? 'resources/scripts/abandonment/' : '/resources/scripts/abandonment/';
43
+
44
+ return gulp.src(siteSettings.srcFolder + '/templates/abandonment/*.html')
45
+ .pipe(replace(/"(?:(?!"|")[\s\S])+(abandonment\/abandonment.*?)js"/, resourcePath + fileNames.abandonmentJsFileName))
55
46
  .pipe(gulp.dest(siteSettings.srcFolder + '/templates/abandonment'));
56
- }
57
47
  }
58
48
 
59
49
  function replaceFooterStylesReference(gulp, gulpPlugins, siteSettings, siteData) {
60
50
  if (siteData.siteData && siteData.siteData.useRelativePathForResources === true) {
61
- return gulp.src(siteSettings.srcFolder + '/resources/scripts/footer/' + footerComponentJsFileName)
62
- .pipe(replace(/concat\((?:(?!concat\(|\))[\s\S])+(components\/footer\/mod.*?)\)/, 'concat("resources/styles/components/footer/' + modFooterStylesFileName + '")'))
63
- .pipe(replace(/concat\((?:(?!concat\(|\))[\s\S])+(components\/footer\/qs.*?)\)/, 'concat("resources/styles/components/footer/' + qsFooterStylesFileName + '")'))
51
+ return gulp.src(siteSettings.srcFolder + '/resources/scripts/footer/' + fileNames.footerComponentJsFileName)
52
+ .pipe(replace(/concat\((?:(?!concat\(|\))[\s\S])+(components\/footer\/mod.*?)\)/, 'concat("resources/styles/components/footer/' + fileNames.modFooterStylesFileName + '")'))
53
+ .pipe(replace(/concat\((?:(?!concat\(|\))[\s\S])+(components\/footer\/qs.*?)\)/, 'concat("resources/styles/components/footer/' + fileNames.qsFooterStylesFileName + '")'))
64
54
  .pipe(gulp.dest(siteSettings.srcFolder + '/resources/scripts/footer'))
65
55
  } else if (!siteData.siteData || siteData.siteData && !siteData.siteData.isQuotePage) {
66
- return gulp.src(siteSettings.srcFolder + '/resources/scripts/footer/' + footerComponentJsFileName)
67
- .pipe(replace(/concat\((?:(?!concat\(|\))[\s\S])+(components\/footer\/mod.*?)\)/, 'concat("/resources/styles/components/footer/' + modFooterStylesFileName + '")'))
68
- .pipe(replace(/concat\((?:(?!concat\(|\))[\s\S])+(components\/footer\/qs.*?)\)/, 'concat("/resources/styles/components/footer/' + qsFooterStylesFileName + '")'))
56
+ return gulp.src(siteSettings.srcFolder + '/resources/scripts/footer/' + fileNames.footerComponentJsFileName)
57
+ .pipe(replace(/concat\((?:(?!concat\(|\))[\s\S])+(components\/footer\/mod.*?)\)/, 'concat("/resources/styles/components/footer/' + fileNames.modFooterStylesFileName + '")'))
58
+ .pipe(replace(/concat\((?:(?!concat\(|\))[\s\S])+(components\/footer\/qs.*?)\)/, 'concat("/resources/styles/components/footer/' + fileNames.qsFooterStylesFileName + '")'))
69
59
  .pipe(gulp.dest(siteSettings.srcFolder + '/resources/scripts/footer'))
70
60
  }
71
61
  }
@@ -73,285 +63,189 @@ function replaceFooterStylesReference(gulp, gulpPlugins, siteSettings, siteData)
73
63
  function replaceFooterStylesReferenceInMap(gulp, gulpPlugins, siteSettings, siteData) {
74
64
  if (siteData.siteData && siteData.siteData.useRelativePathForResources === true) {
75
65
  return gulp.src(siteSettings.srcFolder + '/resources/scripts/footer/footer-component.min.js.map')
76
- .pipe(replace(/\`(?:(?!\`|\`)[\s\S])+(components\/footer\/mod.*?)\`/, '`resources/styles/components/footer/' + modFooterStylesFileName + '`'))
77
- .pipe(replace(/\`(?:(?!\`|\`)[\s\S])+(components\/footer\/mod.*?)\`/, '`resources/styles/components/footer/' + qsFooterStylesFileName + '`'))
66
+ .pipe(replace(/\`(?:(?!\`|\`)[\s\S])+(components\/footer\/mod.*?)\`/, '`resources/styles/components/footer/' + fileNames.modFooterStylesFileName + '`'))
67
+ .pipe(replace(/\`(?:(?!\`|\`)[\s\S])+(components\/footer\/mod.*?)\`/, '`resources/styles/components/footer/' + fileNames.qsFooterStylesFileName + '`'))
78
68
  .pipe(gulp.dest(siteSettings.srcFolder + '/resources/scripts/footer'));
79
69
  } else if (!siteData.siteData || siteData.siteData && !siteData.siteData.isQuotePage) {
80
70
  return gulp.src(siteSettings.srcFolder + '/resources/scripts/footer/footer-component.min.js.map')
81
- .pipe(replace(/\`(?:(?!\`|\`)[\s\S])+(components\/footer\/mod.*?)\`/, '`/resources/styles/components/footer/' + modFooterStylesFileName + '`'))
82
- .pipe(replace(/\`(?:(?!\`|\`)[\s\S])+(components\/footer\/mod.*?)\`/, '`/resources/styles/components/footer/' + qsFooterStylesFileName + '`'))
71
+ .pipe(replace(/\`(?:(?!\`|\`)[\s\S])+(components\/footer\/mod.*?)\`/, '`/resources/styles/components/footer/' + fileNames.modFooterStylesFileName + '`'))
72
+ .pipe(replace(/\`(?:(?!\`|\`)[\s\S])+(components\/footer\/mod.*?)\`/, '`/resources/styles/components/footer/' + fileNames.qsFooterStylesFileName + '`'))
83
73
  .pipe(gulp.dest(siteSettings.srcFolder + '/resources/scripts/footer'));
84
74
  }
85
75
  }
86
76
 
87
- function copyModalytics(gulp, gulpPlugins, siteSettings, siteData) {
88
- return new Promise(resolve => {
89
- request(`https://${siteSettings.nodeEnv}/quote/resources/mod-alytics/modalytics.min.js`)
90
- .on('response', resp => {
91
- if (resp.statusCode !== 200) {
92
- throw new Error(`${resp.statusCode} Error while fetching modalytics.min.js`);
93
- }
94
- })
95
- .pipe(source('modalytics.min.js'))
96
- .pipe(hash({
97
- hashLength: 20,
98
- template: 'modalytics-<%= hash %>.min.js'
99
- }))
100
- .pipe(tap(function(file, t){
101
- modAlyticsFileName = path.basename(file.path);
102
- }))
103
- .pipe(gulp.dest(`${siteSettings.srcFolder}/resources/scripts/mod-alytics`))
104
- .on('finish', resolve);
105
- })
106
- .then(() => {
107
- return new Promise(resolve => {
108
- request(`https://${siteSettings.nodeEnv}/quote/resources/mod-alytics/modalytics.min.js.map`)
109
- .on('response', resp => {
110
- if (resp.statusCode !== 200) {
111
- throw new Error(`${resp.statusCode} Error while fetching modalytics.min.js.map`);
112
- } else {
113
- replaceModalyticsSrc(gulp, gulpPlugins, siteSettings, siteData);
114
- }
115
- })
116
- .pipe(source('modalytics.min.js.map'))
117
- .pipe(gulp.dest(`${siteSettings.srcFolder}/resources/scripts/mod-alytics`))
118
- .on('finish', resolve);
119
- });
120
- });
77
+ function getFileFromURL(url) {
78
+ return url.split('/').pop();
121
79
  }
122
80
 
123
- function copyModutils(gulp, gulpPlugins, siteSettings, siteData) {
124
- return new Promise(resolve => {
125
- request(`https://${siteSettings.nodeEnv}/quote/resources/mod-utils/modutils.min.js`)
126
- .on('response', resp => {
127
- if (resp.statusCode !== 200) {
128
- throw new Error(`${resp.statusCode} Error while fetching modutils.min.js`);
129
- }
130
- })
131
- .pipe(source('modutils.min.js'))
132
- .pipe(hash({
133
- hashLength: 20,
134
- template: 'modutils-<%= hash %>.min.js'
135
- }))
136
- .pipe(tap(function(file, t){
137
- modUtilsFileName = path.basename(file.path);
138
- }))
139
- .pipe(gulp.dest(`${siteSettings.srcFolder}/resources/scripts/mod-utils`))
140
- .on('finish', resolve);
141
- })
142
- .then(() => {
143
- return new Promise(resolve => {
144
- request(`https://${siteSettings.nodeEnv}/quote/resources/mod-utils/modutils.min.js.map`)
145
- .on('response', resp => {
146
- if (resp.statusCode !== 200) {
147
- throw new Error(`${resp.statusCode} Error while fetching modutils.min.js.map`);
148
- }
149
- })
150
- .pipe(source('modutils.min.js.map'))
151
- .pipe(gulp.dest(`${siteSettings.srcFolder}/resources/scripts/mod-utils`))
152
- .on('finish', resolve);
153
- });
154
- });
155
- }
81
+ function getResource(url, config = {}) {
82
+ if (Object.keys(config).length === 0) {
83
+ return false;
84
+ }
156
85
 
157
- function copyAbandonmentJs(gulp, gulpPlugins, siteSettings, siteData) {
158
- return new Promise(resolve => {
159
- request(`https://${siteSettings.nodeEnv}/quote/resources/shared-resources/scripts/abandonment/abandonment.min.js`)
160
- .on('response', resp => {
161
- if (resp.statusCode !== 200) {
162
- throw new Error(`${resp.statusCode} Error while fetching abandonment.min.js`);
163
- }
164
- })
165
- .pipe(source('abandonment.min.js'))
166
- .pipe(hash({
167
- hashLength: 20,
168
- template: 'abandonment-<%= hash %>.min.js'
169
- }))
170
- .pipe(tap(function(file, t){
171
- abandonmentJsFileName = path.basename(file.path);
172
- }))
173
- .pipe(gulp.dest(`${siteSettings.srcFolder}/resources/scripts/abandonment`))
174
- .on('finish', resolve);
175
- })
176
- .then(() => {
177
- return new Promise(resolve => {
178
- request(`https://${siteSettings.nodeEnv}/quote/resources/shared-resources/scripts/abandonment/abandonment.min.js.map`)
179
- .on('response', resp => {
180
- if (resp.statusCode !== 200) {
181
- throw new Error(`${resp.statusCode} Error while fetching abandonment.min.js.map`);
182
- } else {
183
- replaceAbandonmentJsSrc(gulp, gulpPlugins, siteSettings, siteData);
184
- }
185
- })
186
- .pipe(source('abandonment.min.js.map'))
187
- .pipe(gulp.dest(`${siteSettings.srcFolder}/resources/scripts/abandonment`))
188
- .on('finish', resolve);
189
- });
190
- });
191
- }
86
+ const file = getFileFromURL(url);
192
87
 
193
- function copyFooterComponentJs(gulp, gulpPlugins, siteSettings, siteData) {
194
88
  return new Promise(resolve => {
195
- request(`https://${siteSettings.nodeEnv}/quote/resources/shared-resources/scripts/footer/footer-component.min.js`)
89
+ request(`${resourceURL}/${url}`)
196
90
  .on('response', resp => {
197
91
  if (resp.statusCode !== 200) {
198
- throw new Error(`${resp.statusCode} Error while fetching footer-component.min.js`);
92
+ throw new Error(`${resp.statusCode} Error while fetching ${file}`);
199
93
  }
200
94
  })
201
- .pipe(source('footer-component.min.js'))
95
+ .pipe(source(`${file}`))
202
96
  .pipe(hash({
203
97
  hashLength: 20,
204
- template: 'footer-component-<%= hash %>.min.js'
98
+ template: file.replace(/^([^.]*)\.(.*)$/, '$1-<%= hash %>.$2')
205
99
  }))
206
100
  .pipe(tap(function(file, t){
207
- footerComponentJsFileName = path.basename(file.path);
101
+ fileNames[config.fileName] = path.basename(file.path);
208
102
  }))
209
- .pipe(gulp.dest(`${siteSettings.srcFolder}/resources/scripts/footer`))
103
+ .pipe(config.gulp.dest(`${config.siteSettings.srcFolder}/resources/${config.dest}`))
210
104
  .on('finish', resolve);
211
105
  })
212
- .then(() => {
213
- return new Promise(resolve => {
214
- request(`https://${siteSettings.nodeEnv}/quote/resources/shared-resources/scripts/footer/footer-component.min.js.map`)
215
- .on('response', resp => {
216
- if (resp.statusCode !== 200) {
217
- throw new Error(`${resp.statusCode} Error while fetching footer-component.min.js.map`);
218
- }
219
- })
220
- .pipe(source('footer-component.min.js.map'))
221
- .pipe(gulp.dest(`${siteSettings.srcFolder}/resources/scripts/footer`))
222
- .on('finish', resolve);
223
- });
224
- });
225
- }
226
106
 
227
- function copyModForm(gulp, gulpPlugins, siteSettings, siteData) {
228
- return new Promise(resolve => {
229
- request(`https://${siteSettings.nodeEnv}/quote/resources/mod-form/mod-form.min.js`)
230
- .on('response', resp => {
231
- if (resp.statusCode !== 200) {
232
- throw new Error(`${resp.statusCode} Error while fetching mod-form.min.js`);
233
- }
234
- })
235
- .pipe(source('mod-form.min.js'))
236
- .pipe(hash({
237
- hashLength: 20,
238
- template: 'mod-form-<%= hash %>.min.js'
239
- }))
240
- .pipe(tap(function(file, t){
241
- modFormFileName = path.basename(file.path);
242
- }))
243
- .pipe(gulp.dest(`${siteSettings.srcFolder}/resources/scripts/mod-form`))
244
- .on('finish', resolve);
245
- })
246
- .then(() => {
247
- return new Promise(resolve => {
248
- request(`https://${siteSettings.nodeEnv}/quote/resources/mod-form/mod-form.min.js.map`)
249
- .on('response', resp => {
250
- if (resp.statusCode !== 200) {
251
- throw new Error(`${resp.statusCode} Error while fetching mod-form.min.js.map`);
252
- }
253
- })
254
- .pipe(source('mod-form.min.js.map'))
255
- .pipe(gulp.dest(`${siteSettings.srcFolder}/resources/scripts/mod-form`))
256
- .on('finish', resolve);
257
- });
258
- });
259
107
  }
260
108
 
261
- function copyQsForm(gulp, gulpPlugins, siteSettings, siteData) {
262
- return new Promise(resolve => {
263
- request(`https://${siteSettings.nodeEnv}/quote/resources/mod-form/qs-form.min.js`)
264
- .on('response', resp => {
265
- if (resp.statusCode !== 200) {
266
- throw new Error(`${resp.statusCode} Error while fetching qs-form.min.js`);
267
- }
268
- })
269
- .pipe(source('qs-form.min.js'))
270
- .pipe(hash({
271
- hashLength: 20,
272
- template: 'qs-form-<%= hash %>.min.js'
273
- }))
274
- .pipe(tap(function(file, t){
275
- qsFormFileName = path.basename(file.path);
276
- }))
277
- .pipe(gulp.dest(`${siteSettings.srcFolder}/resources/scripts/mod-form`))
278
- .on('finish', resolve);
279
- })
280
- .then(() => {
281
- return new Promise(resolve => {
282
- request(`https://${siteSettings.nodeEnv}/quote/resources/mod-form/qs-form.min.js.map`)
283
- .on('response', resp => {
284
- if (resp.statusCode !== 200) {
285
- throw new Error(`${resp.statusCode} Error while fetching qs-form.min.js.map`);
286
- } else {
287
- replaceFootAssetScripts(gulp, gulpPlugins, siteSettings, siteData);
288
- }
289
- })
290
- .pipe(source('qs-form.min.js.map'))
291
- .pipe(gulp.dest(`${siteSettings.srcFolder}/resources/scripts/mod-form`))
292
- .on('finish', resolve);
293
- });
294
- });
295
- }
109
+ function getResourceMap(url, config = {}, fn) {
110
+ if (Object.keys(config).length === 0) {
111
+ return false;
112
+ }
113
+
114
+ const file = getFileFromURL(url);
296
115
 
297
- function copyFooterComponentStyles(gulp, gulpPlugins, siteSettings, siteData) {
298
116
  return new Promise(resolve => {
299
- request(`https://${siteSettings.nodeEnv}/quote/resources/shared-resources/styles/components/footer/mod-footer.min.css`)
117
+ request(`${resourceURL}/${url}`)
300
118
  .on('response', resp => {
301
119
  if (resp.statusCode !== 200) {
302
- throw new Error(`${resp.statusCode} Error while fetching mod-footer.min.css`);
120
+ throw new Error(`${resp.statusCode} Error while fetching ${file}`);
121
+ } else {
122
+ if (typeof fn === 'function') {
123
+ fn.call(null, config.gulp, config.gulpSettings, config.siteSettings, config.siteData);
124
+ }
303
125
  }
304
126
  })
305
- .pipe(source('mod-footer.min.css'))
306
- .pipe(hash({
307
- hashLength: 20,
308
- template: 'mod-footer-<%= hash %>.min.css'
309
- }))
310
- .pipe(tap(function(file, t){
311
- modFooterStylesFileName = path.basename(file.path);
312
- }))
313
- .pipe(gulp.dest(`${siteSettings.srcFolder}/resources/styles/components/footer`))
127
+ .pipe(source(`${file}`))
128
+ .pipe(config.gulp.dest(`${config.siteSettings.srcFolder}/resources/${config.dest}`))
314
129
  .on('finish', resolve);
315
- })
316
- .then(() => {
317
- return new Promise(resolve => {
318
- request(`https://${siteSettings.nodeEnv}/quote/resources/shared-resources/styles/components/footer/qs-footer.min.css`)
319
- .on('response', resp => {
320
- if (resp.statusCode !== 200) {
321
- throw new Error(`${resp.statusCode} Error while fetching qs-footer.min.css`);
322
- }
323
- })
324
- .pipe(source('qs-footer.min.css'))
325
- .pipe(hash({
326
- hashLength: 20,
327
- template: 'qs-footer-<%= hash %>.min.css'
328
- }))
329
- .pipe(tap(function(file, t){
330
- qsFooterStylesFileName = path.basename(file.path);
331
- }))
332
- .pipe(gulp.dest(`${siteSettings.srcFolder}/resources/styles/components/footer`))
333
- .on('finish', resolve);
334
- });
335
- })
336
- .then(() => {
337
- replaceFooterStylesReference(gulp, gulpPlugins, siteSettings, siteData);
338
- replaceFooterStylesReferenceInMap(gulp, gulpPlugins, siteSettings, siteData);
339
130
  });
131
+
340
132
  }
341
133
 
342
134
  module.exports = function(gulp, gulpPlugins, siteSettings, siteData) {
135
+ const { siteData: data } = siteData || null;
136
+ isQuotePageOrUseRelativePath = data && data.isQuotePage === true || data.useRelativePathForResources === true;
137
+ resourceURL = `https://${siteSettings.nodeEnv}/quote/resources`;
138
+
139
+ const TASKS = {
140
+ copyModalytics: {
141
+ url: `mod-alytics/modalytics.min.js`,
142
+ mapUrl: `mod-alytics/modalytics.min.js.map`,
143
+ config: {
144
+ fileName: 'modAlyticsFileName',
145
+ dest: 'scripts/mod-alytics'
146
+ },
147
+ srcReplaceFn: replaceModalyticsSrc,
148
+ additionalSrcReplaceFns: []
149
+ },
150
+ copyModutils: {
151
+ url: `mod-utils/modutils.min.js`,
152
+ mapUrl: `mod-utils/modutils.min.js.map`,
153
+ config: {
154
+ fileName: 'modUtilsFileName',
155
+ dest: 'scripts/mod-utils'
156
+ },
157
+ srcReplaceFn: null,
158
+ additionalSrcReplaceFns: []
159
+ },
160
+ copyAbandonmentJs: {
161
+ url: `shared-resources/scripts/abandonment/abandonment.min.js`,
162
+ mapUrl: `shared-resources/scripts/abandonment/abandonment.min.js.map`,
163
+ config: {
164
+ fileName: 'abandonmentJsFileName',
165
+ dest: 'scripts/abandonment'
166
+ },
167
+ srcReplaceFn: replaceAbandonmentJsSrc,
168
+ additionalSrcReplaceFns: []
169
+ },
170
+ copyFooterComponentJs: {
171
+ url: `shared-resources/scripts/footer/footer-component.min.js`,
172
+ mapUrl: `shared-resources/scripts/footer/footer-component.min.js.map`,
173
+ config: {
174
+ fileName: 'footerComponentJsFileName',
175
+ dest: 'scripts/footer'
176
+ },
177
+ srcReplaceFn: null,
178
+ additionalSrcReplaceFns: []
179
+ },
180
+ copyModForm: {
181
+ url: `mod-form/mod-form.min.js`,
182
+ mapUrl: `mod-form/mod-form.min.js.map`,
183
+ config: {
184
+ fileName: 'modFormFileName',
185
+ dest: 'scripts/mod-form'
186
+ },
187
+ srcReplaceFn: null,
188
+ additionalSrcReplaceFns: []
189
+ },
190
+ copyQsForm: {
191
+ url: `mod-form/qs-form.min.js`,
192
+ mapUrl: `mod-form/qs-form.min.js.map`,
193
+ config: {
194
+ fileName: 'qsFormFileName',
195
+ dest: 'scripts/mod-form'
196
+ },
197
+ srcReplaceFn: replaceFootAssetScripts,
198
+ additionalSrcReplaceFns: []
199
+ },
200
+ copyModFooterComponentStyles: {
201
+ url: `shared-resources/styles/components/footer/mod-footer.min.css`,
202
+ mapUrl: null,
203
+ config: {
204
+ fileName: 'modFooterStylesFileName',
205
+ dest: 'styles/components/footer'
206
+ },
207
+ srcReplaceFn: null,
208
+ additionalSrcReplaceFns: [replaceFooterStylesReference, replaceFooterStylesReferenceInMap]
209
+ },
210
+ copyQsFooterComponentStyles: {
211
+ url: `shared-resources/styles/components/footer/qs-footer.min.css`,
212
+ mapUrl: null,
213
+ config: {
214
+ fileName: 'qsFooterStylesFileName',
215
+ dest: 'styles/components/footer'
216
+ },
217
+ srcReplaceFn: null,
218
+ additionalSrcReplaceFns: [replaceFooterStylesReference, replaceFooterStylesReferenceInMap]
219
+ }
220
+ };
221
+
343
222
  return function() {
344
223
  const { nodeEnv } = siteSettings;
345
224
  if (!nodeEnv) {
346
225
  throw new Error('Missing environment variables. Did you start with gulp instead of npm run...?');
347
226
  }
348
227
 
349
- return copyModalytics(gulp, gulpPlugins, siteSettings, siteData) &&
350
- copyAbandonmentJs(gulp, gulpPlugins, siteSettings, siteData) &&
351
- copyFooterComponentJs(gulp, gulpPlugins, siteSettings, siteData) &&
352
- copyFooterComponentStyles(gulp, gulpPlugins, siteSettings, siteData) &&
353
- copyModutils(gulp, gulpPlugins, siteSettings, siteData) &&
354
- copyModForm(gulp, gulpPlugins, siteSettings, siteData) &&
355
- copyQsForm(gulp, gulpPlugins, siteSettings, siteData);
228
+ return (function() {
229
+ const tasks = Object.values(TASKS)
230
+ if (tasks.length) {
231
+ tasks.map(async function(task) {
232
+ Object.assign(task.config, { gulp, gulpPlugins, siteSettings, siteData });
233
+ return await getResource(task.url, task.config)
234
+ .then(async () => {
235
+ if (!task.mapUrl) { return false };
236
+ return await getResourceMap(task.mapUrl, task.config, task.srcReplaceFn);
237
+ })
238
+ .then(() => {
239
+ if ('additionalSrcReplaceFns' in task && task.additionalSrcReplaceFns.length) {
240
+ task.additionalSrcReplaceFns.map(function(fn) {
241
+ if (typeof fn === 'function') {
242
+ fn.call(null, gulp, gulpPlugins, siteSettings, siteData)
243
+ }
244
+ });
245
+ }
246
+ });
247
+ });
248
+ }
249
+ }());
356
250
  };
357
251
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mod-build",
3
- "version": "3.6.14",
3
+ "version": "3.6.15-beta.1",
4
4
  "description": "Share components for S3 sites.",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"