mod-build 3.6.14 → 3.6.15-beta.2
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-shared-scripts.js +187 -283
- package/package.json +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,71 +1,62 @@
|
|
|
1
1
|
var request = require('request');
|
|
2
2
|
var source = require('vinyl-source-stream');
|
|
3
3
|
var replace = require('gulp-replace');
|
|
4
|
-
var hash = require('gulp-hash');
|
|
4
|
+
var hash = require('gulp-hash-filename');
|
|
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
|
-
|
|
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])+(form\/mod-form-beta.*?)js"/, resourcePath + '/mod-form/form/' + fileNames.newModFormFileName))
|
|
38
|
+
.pipe(replace(/"(?:(?!"|")[\s\S])+(qs-form.*?)js"/, resourcePath + '/mod-form/' + fileNames.qsFormFileName))
|
|
43
39
|
.pipe(gulp.dest(siteSettings.srcFolder + '/shared-components/foot-assets'));
|
|
44
|
-
}
|
|
45
40
|
}
|
|
46
41
|
|
|
47
42
|
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 + '"'))
|
|
43
|
+
const resourcePath = isQuotePageOrUseRelativePath ? 'resources/scripts/abandonment/' : '/resources/scripts/abandonment/';
|
|
44
|
+
|
|
45
|
+
return gulp.src(siteSettings.srcFolder + '/templates/abandonment/*.html')
|
|
46
|
+
.pipe(replace(/"(?:(?!"|")[\s\S])+(abandonment\/abandonment.*?)js"/, resourcePath + fileNames.abandonmentJsFileName))
|
|
55
47
|
.pipe(gulp.dest(siteSettings.srcFolder + '/templates/abandonment'));
|
|
56
|
-
}
|
|
57
48
|
}
|
|
58
49
|
|
|
59
50
|
function replaceFooterStylesReference(gulp, gulpPlugins, siteSettings, siteData) {
|
|
60
51
|
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 + '")'))
|
|
52
|
+
return gulp.src(siteSettings.srcFolder + '/resources/scripts/footer/' + fileNames.footerComponentJsFileName)
|
|
53
|
+
.pipe(replace(/concat\((?:(?!concat\(|\))[\s\S])+(components\/footer\/mod.*?)\)/, 'concat("resources/styles/components/footer/' + fileNames.modFooterStylesFileName + '")'))
|
|
54
|
+
.pipe(replace(/concat\((?:(?!concat\(|\))[\s\S])+(components\/footer\/qs.*?)\)/, 'concat("resources/styles/components/footer/' + fileNames.qsFooterStylesFileName + '")'))
|
|
64
55
|
.pipe(gulp.dest(siteSettings.srcFolder + '/resources/scripts/footer'))
|
|
65
56
|
} 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 + '")'))
|
|
57
|
+
return gulp.src(siteSettings.srcFolder + '/resources/scripts/footer/' + fileNames.footerComponentJsFileName)
|
|
58
|
+
.pipe(replace(/concat\((?:(?!concat\(|\))[\s\S])+(components\/footer\/mod.*?)\)/, 'concat("/resources/styles/components/footer/' + fileNames.modFooterStylesFileName + '")'))
|
|
59
|
+
.pipe(replace(/concat\((?:(?!concat\(|\))[\s\S])+(components\/footer\/qs.*?)\)/, 'concat("/resources/styles/components/footer/' + fileNames.qsFooterStylesFileName + '")'))
|
|
69
60
|
.pipe(gulp.dest(siteSettings.srcFolder + '/resources/scripts/footer'))
|
|
70
61
|
}
|
|
71
62
|
}
|
|
@@ -73,285 +64,198 @@ function replaceFooterStylesReference(gulp, gulpPlugins, siteSettings, siteData)
|
|
|
73
64
|
function replaceFooterStylesReferenceInMap(gulp, gulpPlugins, siteSettings, siteData) {
|
|
74
65
|
if (siteData.siteData && siteData.siteData.useRelativePathForResources === true) {
|
|
75
66
|
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 + '`'))
|
|
67
|
+
.pipe(replace(/\`(?:(?!\`|\`)[\s\S])+(components\/footer\/mod.*?)\`/, '`resources/styles/components/footer/' + fileNames.modFooterStylesFileName + '`'))
|
|
68
|
+
.pipe(replace(/\`(?:(?!\`|\`)[\s\S])+(components\/footer\/mod.*?)\`/, '`resources/styles/components/footer/' + fileNames.qsFooterStylesFileName + '`'))
|
|
78
69
|
.pipe(gulp.dest(siteSettings.srcFolder + '/resources/scripts/footer'));
|
|
79
70
|
} else if (!siteData.siteData || siteData.siteData && !siteData.siteData.isQuotePage) {
|
|
80
71
|
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 + '`'))
|
|
72
|
+
.pipe(replace(/\`(?:(?!\`|\`)[\s\S])+(components\/footer\/mod.*?)\`/, '`/resources/styles/components/footer/' + fileNames.modFooterStylesFileName + '`'))
|
|
73
|
+
.pipe(replace(/\`(?:(?!\`|\`)[\s\S])+(components\/footer\/mod.*?)\`/, '`/resources/styles/components/footer/' + fileNames.qsFooterStylesFileName + '`'))
|
|
83
74
|
.pipe(gulp.dest(siteSettings.srcFolder + '/resources/scripts/footer'));
|
|
84
75
|
}
|
|
85
76
|
}
|
|
86
77
|
|
|
87
|
-
function
|
|
88
|
-
return
|
|
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
|
-
});
|
|
78
|
+
function getFileFromURL(url) {
|
|
79
|
+
return url.split('/').pop();
|
|
121
80
|
}
|
|
122
81
|
|
|
123
|
-
function
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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
|
-
}
|
|
82
|
+
function getResource(url, config = {}) {
|
|
83
|
+
if (Object.keys(config).length === 0) {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
156
86
|
|
|
157
|
-
|
|
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
|
-
}
|
|
87
|
+
const file = getFileFromURL(url);
|
|
192
88
|
|
|
193
|
-
function copyFooterComponentJs(gulp, gulpPlugins, siteSettings, siteData) {
|
|
194
89
|
return new Promise(resolve => {
|
|
195
|
-
request(
|
|
90
|
+
request(`${resourceURL}/${url}`)
|
|
196
91
|
.on('response', resp => {
|
|
197
92
|
if (resp.statusCode !== 200) {
|
|
198
|
-
throw new Error(`${resp.statusCode} Error while fetching
|
|
93
|
+
throw new Error(`${resp.statusCode} Error while fetching ${file}`);
|
|
199
94
|
}
|
|
200
95
|
})
|
|
201
|
-
.pipe(source(
|
|
96
|
+
.pipe(source(`${file}`))
|
|
202
97
|
.pipe(hash({
|
|
203
|
-
|
|
204
|
-
template: 'footer-component-<%= hash %>.min.js'
|
|
98
|
+
"format": "{name}.{hash}.{ext}"
|
|
205
99
|
}))
|
|
206
100
|
.pipe(tap(function(file, t){
|
|
207
|
-
|
|
101
|
+
fileNames[config.fileName] = path.basename(file.path);
|
|
208
102
|
}))
|
|
209
|
-
.pipe(gulp.dest(`${siteSettings.srcFolder}/resources
|
|
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
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
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(
|
|
117
|
+
request(`${resourceURL}/${url}`)
|
|
300
118
|
.on('response', resp => {
|
|
301
119
|
if (resp.statusCode !== 200) {
|
|
302
|
-
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
|
+
}
|
|
303
125
|
}
|
|
304
126
|
})
|
|
305
|
-
.pipe(source(
|
|
306
|
-
.pipe(
|
|
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
|
+
copyNewModForm: {
|
|
191
|
+
url: `mod-form/form/mod-form-beta.min.js`,
|
|
192
|
+
mapUrl: `mod-form/form/mod-form-beta.min.js.map`,
|
|
193
|
+
config: {
|
|
194
|
+
fileName: 'newModFormFileName',
|
|
195
|
+
dest: 'scripts/mod-form/form'
|
|
196
|
+
},
|
|
197
|
+
srcReplaceFn: null,
|
|
198
|
+
additionalSrcReplaceFns: []
|
|
199
|
+
},
|
|
200
|
+
copyQsForm: {
|
|
201
|
+
url: `mod-form/qs-form.min.js`,
|
|
202
|
+
mapUrl: `mod-form/qs-form.min.js.map`,
|
|
203
|
+
config: {
|
|
204
|
+
fileName: 'qsFormFileName',
|
|
205
|
+
dest: 'scripts/mod-form'
|
|
206
|
+
},
|
|
207
|
+
srcReplaceFn: replaceFootAssetScripts,
|
|
208
|
+
additionalSrcReplaceFns: []
|
|
209
|
+
},
|
|
210
|
+
copyModFooterComponentStyles: {
|
|
211
|
+
url: `shared-resources/styles/components/footer/mod-footer.min.css`,
|
|
212
|
+
mapUrl: null,
|
|
213
|
+
config: {
|
|
214
|
+
fileName: 'modFooterStylesFileName',
|
|
215
|
+
dest: 'styles/components/footer'
|
|
216
|
+
},
|
|
217
|
+
srcReplaceFn: null,
|
|
218
|
+
additionalSrcReplaceFns: [replaceFooterStylesReference, replaceFooterStylesReferenceInMap]
|
|
219
|
+
},
|
|
220
|
+
copyQsFooterComponentStyles: {
|
|
221
|
+
url: `shared-resources/styles/components/footer/qs-footer.min.css`,
|
|
222
|
+
mapUrl: null,
|
|
223
|
+
config: {
|
|
224
|
+
fileName: 'qsFooterStylesFileName',
|
|
225
|
+
dest: 'styles/components/footer'
|
|
226
|
+
},
|
|
227
|
+
srcReplaceFn: null,
|
|
228
|
+
additionalSrcReplaceFns: [replaceFooterStylesReference, replaceFooterStylesReferenceInMap]
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
|
|
343
232
|
return function() {
|
|
344
233
|
const { nodeEnv } = siteSettings;
|
|
345
234
|
if (!nodeEnv) {
|
|
346
235
|
throw new Error('Missing environment variables. Did you start with gulp instead of npm run...?');
|
|
347
236
|
}
|
|
348
237
|
|
|
349
|
-
return
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
238
|
+
return (function() {
|
|
239
|
+
const tasks = Object.values(TASKS)
|
|
240
|
+
if (tasks.length) {
|
|
241
|
+
tasks.map(async function(task) {
|
|
242
|
+
Object.assign(task.config, { gulp, gulpPlugins, siteSettings, siteData });
|
|
243
|
+
return await getResource(task.url, task.config)
|
|
244
|
+
.then(async () => {
|
|
245
|
+
if (!task.mapUrl) { return false };
|
|
246
|
+
return await getResourceMap(task.mapUrl, task.config, task.srcReplaceFn);
|
|
247
|
+
})
|
|
248
|
+
.then(() => {
|
|
249
|
+
if ('additionalSrcReplaceFns' in task && task.additionalSrcReplaceFns.length) {
|
|
250
|
+
task.additionalSrcReplaceFns.map(function(fn) {
|
|
251
|
+
if (typeof fn === 'function') {
|
|
252
|
+
fn.call(null, gulp, gulpPlugins, siteSettings, siteData)
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
}());
|
|
356
260
|
};
|
|
357
261
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mod-build",
|
|
3
|
-
"version": "3.6.
|
|
3
|
+
"version": "3.6.15-beta.2",
|
|
4
4
|
"description": "Share components for S3 sites.",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
"gulp-filter": "^5.0.0",
|
|
27
27
|
"gulp-handlebars-file-include": "^1.0.0",
|
|
28
28
|
"gulp-hash": "^4.2.2",
|
|
29
|
+
"gulp-hash-filename": "^4.0.0",
|
|
29
30
|
"gulp-htmlmin": "^3.0.0",
|
|
30
31
|
"gulp-if": "^2.0.2",
|
|
31
32
|
"gulp-imagemin": "^3.2.0",
|