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