mod-build 3.6.17 → 3.6.18--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 +1 -1
- package/gulp-tasks/grab-shared-scripts.js +186 -213
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,248 +4,221 @@ var replace = require('gulp-replace');
|
|
|
4
4
|
var hash = require('gulp-hash');
|
|
5
5
|
var tap = require('gulp-tap');
|
|
6
6
|
var path = require('path');
|
|
7
|
-
|
|
8
7
|
const fileNames = {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
};
|
|
18
|
-
|
|
8
|
+
modAlyticsFileName: '',
|
|
9
|
+
modUtilsFileName: '',
|
|
10
|
+
abandonmentJsFileName: '',
|
|
11
|
+
footerComponentJsFileName: '',
|
|
12
|
+
modFooterStylesFileName: '',
|
|
13
|
+
qsFooterStylesFileName: '',
|
|
14
|
+
modFormFileName: '',
|
|
15
|
+
qsFormFileName: ''};
|
|
19
16
|
var isQuotePageOrUseRelativePath = false;
|
|
20
17
|
var resourceURL = '';
|
|
21
|
-
|
|
22
18
|
function replaceModalyticsSrc(gulp, gulpPlugins, siteSettings, siteData) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
.pipe(gulp.dest(siteSettings.srcFolder + '/shared-components/head'));
|
|
19
|
+
const resourcePath = isQuotePageOrUseRelativePath ? '{{#if this.src}}{{this.src}}{{/if}}resources/scripts/mod-alytics/' : '/resources/scripts/mod-alytics/';
|
|
20
|
+
return gulp.src(siteSettings.srcFolder + '/shared-components/head/head.html')
|
|
21
|
+
.pipe(replace(/".*(modalytics).*"/, resourcePath + fileNames.modAlyticsFileName))
|
|
22
|
+
.pipe(gulp.dest(siteSettings.srcFolder + '/shared-components/head'));
|
|
28
23
|
}
|
|
29
|
-
|
|
30
24
|
function replaceFootAssetScripts(gulp, gulpPlugins, siteSettings, siteData) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
25
|
+
console.log('replacing foot assets...')
|
|
26
|
+
const resourcePath = isQuotePageOrUseRelativePath ? '{{#if this.nodeModulesPath}}{{this.nodeModulesPath}}{{/if}}resources/scripts' : '/resources/scripts';
|
|
27
|
+
return gulp.src(siteSettings.srcFolder + '/shared-components/foot-assets/foot-assets.html')
|
|
28
|
+
.pipe(replace(/"(?:(?!"|js")[\s\S])+(modutils|mod-utils.*?)js"/, resourcePath + '/mod-utils/' + fileNames.modUtilsFileName))
|
|
29
|
+
.pipe(replace(/"(?:(?!"|")[\s\S])+(footer\/footer-component.*?)js"/, resourcePath + '/footer/' + fileNames.footerComponentJsFileName))
|
|
30
|
+
.pipe(replace(/"(?:(?!"|")[\s\S])+(mod-form\/mod-form.*?)js"/, resourcePath + '/mod-form/' + fileNames.modFormFileName))
|
|
31
|
+
.pipe(replace(/"(?:(?!"|")[\s\S])+(qs-form.*?)js"/, resourcePath + '/mod-form/' + fileNames.qsFormFileName))
|
|
32
|
+
.pipe(gulp.dest(siteSettings.srcFolder + '/shared-components/foot-assets'));
|
|
39
33
|
}
|
|
40
|
-
|
|
41
34
|
function replaceAbandonmentJsSrc(gulp, gulpPlugins, siteSettings, siteData) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
.pipe(gulp.dest(siteSettings.srcFolder + '/templates/abandonment'));
|
|
35
|
+
const resourcePath = isQuotePageOrUseRelativePath ? 'resources/scripts/abandonment/' : '/resources/scripts/abandonment/';
|
|
36
|
+
return gulp.src(siteSettings.srcFolder + '/templates/abandonment/*.html')
|
|
37
|
+
.pipe(replace(/"(?:(?!"|")[\s\S])+(abandonment\/abandonment.*?)js"/, resourcePath + fileNames.abandonmentJsFileName))
|
|
38
|
+
.pipe(gulp.dest(siteSettings.srcFolder + '/templates/abandonment'));
|
|
47
39
|
}
|
|
48
|
-
|
|
49
40
|
function replaceFooterStylesReference(gulp, gulpPlugins, siteSettings, siteData) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
41
|
+
if (siteData.siteData && siteData.siteData.useRelativePathForResources === true) {
|
|
42
|
+
return gulp.src(siteSettings.srcFolder + '/resources/scripts/footer/' + fileNames.footerComponentJsFileName)
|
|
43
|
+
.pipe(replace(/concat\((?:(?!concat\(|\))[\s\S])+(components\/footer\/mod.*?)\)/, 'concat("resources/styles/components/footer/' + fileNames.modFooterStylesFileName + '")'))
|
|
44
|
+
.pipe(replace(/concat\((?:(?!concat\(|\))[\s\S])+(components\/footer\/qs.*?)\)/, 'concat("resources/styles/components/footer/' + fileNames.qsFooterStylesFileName + '")'))
|
|
45
|
+
.pipe(gulp.dest(siteSettings.srcFolder + '/resources/scripts/footer'))
|
|
46
|
+
} else if (!siteData.siteData || siteData.siteData && !siteData.siteData.isQuotePage) {
|
|
47
|
+
return gulp.src(siteSettings.srcFolder + '/resources/scripts/footer/' + fileNames.footerComponentJsFileName)
|
|
48
|
+
.pipe(replace(/concat\((?:(?!concat\(|\))[\s\S])+(components\/footer\/mod.*?)\)/, 'concat("/resources/styles/components/footer/' + fileNames.modFooterStylesFileName + '")'))
|
|
49
|
+
.pipe(replace(/concat\((?:(?!concat\(|\))[\s\S])+(components\/footer\/qs.*?)\)/, 'concat("/resources/styles/components/footer/' + fileNames.qsFooterStylesFileName + '")'))
|
|
50
|
+
.pipe(gulp.dest(siteSettings.srcFolder + '/resources/scripts/footer'))
|
|
51
|
+
}
|
|
61
52
|
}
|
|
62
|
-
|
|
63
53
|
function replaceFooterStylesReferenceInMap(gulp, gulpPlugins, siteSettings, siteData) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
54
|
+
if (siteData.siteData && siteData.siteData.useRelativePathForResources === true) {
|
|
55
|
+
return gulp.src(siteSettings.srcFolder + '/resources/scripts/footer/footer-component.min.js.map')
|
|
56
|
+
.pipe(replace(/\`(?:(?!\`|\`)[\s\S])+(components\/footer\/mod.*?)\`/, '`resources/styles/components/footer/' + fileNames.modFooterStylesFileName + '`'))
|
|
57
|
+
.pipe(replace(/\`(?:(?!\`|\`)[\s\S])+(components\/footer\/mod.*?)\`/, '`resources/styles/components/footer/' + fileNames.qsFooterStylesFileName + '`'))
|
|
58
|
+
.pipe(gulp.dest(siteSettings.srcFolder + '/resources/scripts/footer'));
|
|
59
|
+
} else if (!siteData.siteData || siteData.siteData && !siteData.siteData.isQuotePage) {
|
|
60
|
+
return gulp.src(siteSettings.srcFolder + '/resources/scripts/footer/footer-component.min.js.map')
|
|
61
|
+
.pipe(replace(/\`(?:(?!\`|\`)[\s\S])+(components\/footer\/mod.*?)\`/, '`/resources/styles/components/footer/' + fileNames.modFooterStylesFileName + '`'))
|
|
62
|
+
.pipe(replace(/\`(?:(?!\`|\`)[\s\S])+(components\/footer\/mod.*?)\`/, '`/resources/styles/components/footer/' + fileNames.qsFooterStylesFileName + '`'))
|
|
63
|
+
.pipe(gulp.dest(siteSettings.srcFolder + '/resources/scripts/footer'));
|
|
64
|
+
}
|
|
75
65
|
}
|
|
76
|
-
|
|
77
66
|
function getFileFromURL(url) {
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function getResource(url, config = {}) {
|
|
82
|
-
if (Object.keys(config).length === 0) {
|
|
83
|
-
return false;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const file = getFileFromURL(url);
|
|
87
|
-
|
|
88
|
-
return new Promise(resolve => {
|
|
89
|
-
request(`${resourceURL}/${url}`)
|
|
90
|
-
.on('response', resp => {
|
|
91
|
-
if (resp.statusCode !== 200) {
|
|
92
|
-
throw new Error(`${resp.statusCode} Error while fetching ${file}`);
|
|
93
|
-
}
|
|
94
|
-
})
|
|
95
|
-
.pipe(source(`${file}`))
|
|
96
|
-
.pipe(hash({
|
|
97
|
-
hashLength: 20,
|
|
98
|
-
template: file.replace(/^([^.]*)\.(.*)$/, '$1-<%= hash %>.$2')
|
|
99
|
-
}))
|
|
100
|
-
.pipe(tap(function(file, t){
|
|
101
|
-
fileNames[config.fileName] = path.basename(file.path);
|
|
102
|
-
}))
|
|
103
|
-
.pipe(config.gulp.dest(`${config.siteSettings.srcFolder}/resources/${config.dest}`))
|
|
104
|
-
.on('finish', resolve);
|
|
105
|
-
})
|
|
106
|
-
|
|
67
|
+
return url.split('/').pop();
|
|
107
68
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
69
|
+
function getResource(url, config = {}, fn, fnArray) {
|
|
70
|
+
if (Object.keys(config).length === 0) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
const file = getFileFromURL(url);
|
|
74
|
+
return new Promise(resolve => {
|
|
75
|
+
request(`${resourceURL}/${url}`)
|
|
76
|
+
.on('response', resp => {
|
|
77
|
+
if (resp.statusCode !== 200) {
|
|
78
|
+
throw new Error(`${resp.statusCode} Error while fetching ${file}`);
|
|
79
|
+
}
|
|
80
|
+
})
|
|
81
|
+
.pipe(source(`${file}`))
|
|
82
|
+
.pipe(hash({
|
|
83
|
+
hashLength: 20,
|
|
84
|
+
template: file.replace(/^([^.]*)\.(.*)$/, '$1-<%= hash %>.$2')
|
|
85
|
+
}))
|
|
86
|
+
.pipe(tap(function(file, t){
|
|
87
|
+
fileNames[config.fileName] = path.basename(file.path);
|
|
88
|
+
}))
|
|
89
|
+
.pipe(config.gulp.dest(`${config.siteSettings.srcFolder}/resources/${config.dest}`))
|
|
90
|
+
.on('finish', resolve);
|
|
91
|
+
})
|
|
92
|
+
.then(() => {
|
|
93
|
+
if (!config.mapUrl) { return false };
|
|
94
|
+
return new Promise((resolve) => {
|
|
95
|
+
request(`${resourceURL}/${url}`)
|
|
96
|
+
.on('response', (resp) => {
|
|
97
|
+
if (resp.statusCode !== 200) {
|
|
98
|
+
throw new Error(`${resp.statusCode} Error while fetching ${file}`);
|
|
99
|
+
} else {
|
|
100
|
+
if (typeof fn === 'function') {
|
|
101
|
+
fn.call(null, config.gulp, config.gulpSettings, config.siteSettings, config.siteData);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
})
|
|
105
|
+
.pipe(source(`${file}`))
|
|
106
|
+
.pipe(config.gulp.dest(`${config.siteSettings.srcFolder}/resources/${config.dest}`))
|
|
107
|
+
.on('finish', resolve);
|
|
108
|
+
});
|
|
109
|
+
})
|
|
110
|
+
.then(() => {
|
|
111
|
+
if (fnArray && fnArray.length) {
|
|
112
|
+
fnArray.map(function(fn) {
|
|
113
|
+
if (typeof fn === 'function') {
|
|
114
|
+
fn.call(null, config.gulp, config.gulpSettings, config.siteSettings, config.siteData)
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
});
|
|
132
119
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
const TASKS = {
|
|
140
|
-
copyModalytics: {
|
|
141
|
-
url: `mod-alytics/modalytics.min.js`,
|
|
120
|
+
const TASKS = {
|
|
121
|
+
copyModalytics: {
|
|
122
|
+
url: `mod-alytics/modalytics.min.js`,
|
|
123
|
+
config: {
|
|
124
|
+
fileName: 'modAlyticsFileName',
|
|
125
|
+
dest: 'scripts/mod-alytics',
|
|
142
126
|
mapUrl: `mod-alytics/modalytics.min.js.map`,
|
|
143
|
-
config: {
|
|
144
|
-
fileName: 'modAlyticsFileName',
|
|
145
|
-
dest: 'scripts/mod-alytics'
|
|
146
|
-
},
|
|
147
|
-
srcReplaceFn: replaceModalyticsSrc,
|
|
148
|
-
additionalSrcReplaceFns: []
|
|
149
127
|
},
|
|
150
|
-
|
|
151
|
-
|
|
128
|
+
srcReplaceFn: replaceModalyticsSrc,
|
|
129
|
+
additionalSrcReplaceFns: []
|
|
130
|
+
},
|
|
131
|
+
copyModutils: {
|
|
132
|
+
url: `mod-utils/modutils.min.js`,
|
|
133
|
+
config: {
|
|
134
|
+
fileName: 'modUtilsFileName',
|
|
135
|
+
dest: 'scripts/mod-utils',
|
|
152
136
|
mapUrl: `mod-utils/modutils.min.js.map`,
|
|
153
|
-
config: {
|
|
154
|
-
fileName: 'modUtilsFileName',
|
|
155
|
-
dest: 'scripts/mod-utils'
|
|
156
|
-
},
|
|
157
|
-
srcReplaceFn: null,
|
|
158
|
-
additionalSrcReplaceFns: []
|
|
159
137
|
},
|
|
160
|
-
|
|
161
|
-
|
|
138
|
+
srcReplaceFn: null,
|
|
139
|
+
additionalSrcReplaceFns: []
|
|
140
|
+
},
|
|
141
|
+
copyAbandonmentJs: {
|
|
142
|
+
url: `shared-resources/scripts/abandonment/abandonment.min.js`,
|
|
143
|
+
config: {
|
|
144
|
+
fileName: 'abandonmentJsFileName',
|
|
145
|
+
dest: 'scripts/abandonment',
|
|
162
146
|
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
147
|
},
|
|
170
|
-
|
|
171
|
-
|
|
148
|
+
srcReplaceFn: replaceAbandonmentJsSrc,
|
|
149
|
+
additionalSrcReplaceFns: []
|
|
150
|
+
},
|
|
151
|
+
copyFooterComponentJs: {
|
|
152
|
+
url: `shared-resources/scripts/footer/footer-component.min.js`,
|
|
153
|
+
config: {
|
|
154
|
+
fileName: 'footerComponentJsFileName',
|
|
155
|
+
dest: 'scripts/footer',
|
|
172
156
|
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
157
|
},
|
|
180
|
-
|
|
181
|
-
|
|
158
|
+
srcReplaceFn: null,
|
|
159
|
+
additionalSrcReplaceFns: []
|
|
160
|
+
},
|
|
161
|
+
copyModForm: {
|
|
162
|
+
url: `mod-form/mod-form.min.js`,
|
|
163
|
+
config: {
|
|
164
|
+
fileName: 'modFormFileName',
|
|
165
|
+
dest: 'scripts/mod-form',
|
|
182
166
|
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
167
|
},
|
|
190
|
-
|
|
191
|
-
|
|
168
|
+
srcReplaceFn: null,
|
|
169
|
+
additionalSrcReplaceFns: []
|
|
170
|
+
},
|
|
171
|
+
copyQsForm: {
|
|
172
|
+
url: `mod-form/qs-form.min.js`,
|
|
173
|
+
config: {
|
|
174
|
+
fileName: 'qsFormFileName',
|
|
175
|
+
dest: 'scripts/mod-form',
|
|
192
176
|
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
177
|
},
|
|
200
|
-
|
|
201
|
-
|
|
178
|
+
srcReplaceFn: replaceFootAssetScripts,
|
|
179
|
+
additionalSrcReplaceFns: []
|
|
180
|
+
},
|
|
181
|
+
copyModFooterComponentStyles: {
|
|
182
|
+
url: `shared-resources/styles/components/footer/mod-footer.min.css`,
|
|
183
|
+
config: {
|
|
184
|
+
fileName: 'modFooterStylesFileName',
|
|
185
|
+
dest: 'styles/components/footer',
|
|
202
186
|
mapUrl: null,
|
|
203
|
-
config: {
|
|
204
|
-
fileName: 'modFooterStylesFileName',
|
|
205
|
-
dest: 'styles/components/footer'
|
|
206
|
-
},
|
|
207
|
-
srcReplaceFn: null,
|
|
208
|
-
additionalSrcReplaceFns: [replaceFooterStylesReference, replaceFooterStylesReferenceInMap]
|
|
209
187
|
},
|
|
210
|
-
|
|
211
|
-
|
|
188
|
+
srcReplaceFn: null,
|
|
189
|
+
additionalSrcReplaceFns: [replaceFooterStylesReference, replaceFooterStylesReferenceInMap]
|
|
190
|
+
},
|
|
191
|
+
copyQsFooterComponentStyles: {
|
|
192
|
+
url: `shared-resources/styles/components/footer/qs-footer.min.css`,
|
|
193
|
+
config: {
|
|
194
|
+
fileName: 'qsFooterStylesFileName',
|
|
195
|
+
dest: 'styles/components/footer',
|
|
212
196
|
mapUrl: null,
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
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
|
-
}());
|
|
250
|
-
};
|
|
197
|
+
},
|
|
198
|
+
srcReplaceFn: null,
|
|
199
|
+
additionalSrcReplaceFns: [replaceFooterStylesReference, replaceFooterStylesReferenceInMap]
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
module.exports = function(gulp, gulpPlugins, siteSettings, siteData) {
|
|
203
|
+
const isQuotePage = siteData.siteData && siteData.siteData.isQuotePage || siteData.siteData && siteData.isQuotePage;
|
|
204
|
+
const useRelativePathForResources = siteData.siteData && siteData.siteData.useRelativePathForResources || siteData.siteData && siteData.useRelativePathForResources;
|
|
205
|
+
isQuotePageOrUseRelativePath = isQuotePage === true || useRelativePathForResources === true;
|
|
206
|
+
resourceURL = `https://${siteSettings.nodeEnv}/quote/resources`;
|
|
207
|
+
return function() {
|
|
208
|
+
const { nodeEnv } = siteSettings;
|
|
209
|
+
if (!nodeEnv) {
|
|
210
|
+
throw new Error('Missing environment variables. Did you start with gulp instead of npm run...?');
|
|
211
|
+
}
|
|
212
|
+
return (function() {
|
|
213
|
+
const tasks = Object.values(TASKS)
|
|
214
|
+
if (tasks.length) {
|
|
215
|
+
var getAllResources = tasks.map(function(task) {
|
|
216
|
+
Object.assign(task.config, { gulp, gulpPlugins, siteSettings, siteData });
|
|
217
|
+
return getResource(task.url, task.config, task.srcReplaceFn, task.additionalSrcReplaceFns)
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
return Promise.all(getAllResources);
|
|
222
|
+
}());
|
|
223
|
+
};
|
|
251
224
|
};
|