mod-build 3.7.35-beta.1 → 3.7.35

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,8 +1,8 @@
1
1
  # Changelog
2
2
 
3
- ## 3.7.34
3
+ ## 3.7.35
4
4
 
5
- - Added support for dynamic gtm based on traffic source
5
+ - Add 'grab-b2b-data' task to build/serve
6
6
 
7
7
  ## 3.7.34
8
8
 
@@ -5,15 +5,15 @@ module.exports = function(gulp, gulpPlugins, siteSettings, siteData) {
5
5
  var sequenceOpts;
6
6
 
7
7
  if (siteData.useTypescript) {
8
- sequenceOpts = ['clean', 'grab-cdn', 'grab-shared-components', 'grab-shared-scripts', 'get-default-trade-questions', 'grab-form-helpers', 'templates', 'styles', 'compile-prod', 'js-lint', 'html-min', 'css-min', 'js-min', 'img-min', 'extras', 'cache-bust', 'add-path-subdirectories', 'copy-resources-to-dist', 'build-stat'];
8
+ sequenceOpts = ['clean', 'grab-b2b-data', 'grab-cdn', 'grab-shared-components', 'grab-shared-scripts', 'get-default-trade-questions', 'grab-form-helpers', 'templates', 'styles', 'compile-prod', 'js-lint', 'html-min', 'css-min', 'js-min', 'img-min', 'extras', 'cache-bust', 'add-path-subdirectories', 'copy-resources-to-dist', 'build-stat'];
9
9
  } else if (siteData.isWhiteLabel) {
10
10
  if (siteData.isQSPage) {
11
- sequenceOpts = ['clean', 'grab-cdn', 'grab-shared-components', 'grab-shared-scripts', 'get-default-trade-questions', 'grab-form-helpers', 'templates', 'styles', 'copy-videos', 'grab-theme-json', 'combine-files', 'grab-images', 'copy-json', 'js-lint', 'html-min', 'css-min', 'js-min', 'img-min', 'extras', 'copy-files-to-build-path', 'cache-bust', 'add-path-subdirectories', 'grab-tooltips-json', 'copy-resources-to-dist', 'build-stat'];
11
+ sequenceOpts = ['clean', 'grab-b2b-data', 'grab-cdn', 'grab-shared-components', 'grab-shared-scripts', 'get-default-trade-questions', 'grab-form-helpers', 'templates', 'styles', 'copy-videos', 'grab-theme-json', 'combine-files', 'grab-images', 'copy-json', 'js-lint', 'html-min', 'css-min', 'js-min', 'img-min', 'extras', 'copy-files-to-build-path', 'cache-bust', 'add-path-subdirectories', 'grab-tooltips-json', 'copy-resources-to-dist', 'build-stat'];
12
12
  } else {
13
- sequenceOpts = ['clean', 'grab-cdn', 'grab-shared-components', 'grab-shared-scripts', 'get-default-trade-questions', 'grab-form-helpers', 'templates', 'styles', 'copy-videos', 'combine-files', 'grab-images', 'js-lint', 'html-min', 'grab-global-images', 'css-min', 'js-min', 'img-min', 'extras', 'cache-bust', 'add-path-subdirectories', 'grab-tooltips-json', 'copy-resources-to-dist', 'build-stat'];
13
+ sequenceOpts = ['clean', 'grab-b2b-data', 'grab-cdn', 'grab-shared-components', 'grab-shared-scripts', 'get-default-trade-questions', 'grab-form-helpers', 'templates', 'styles', 'copy-videos', 'combine-files', 'grab-images', 'js-lint', 'html-min', 'grab-global-images', 'css-min', 'js-min', 'img-min', 'extras', 'cache-bust', 'add-path-subdirectories', 'grab-tooltips-json', 'copy-resources-to-dist', 'build-stat'];
14
14
  }
15
15
  } else {
16
- sequenceOpts = ['clean', 'grab-cdn', 'grab-shared-components', 'grab-shared-scripts', 'get-default-trade-questions', 'grab-form-helpers', 'templates', 'styles', 'copy-videos', 'js-lint', 'html-min', 'css-min', 'js-min', 'img-min', 'extras', 'cache-bust', 'add-path-subdirectories', 'copy-resources-to-dist', 'build-stat'];
16
+ sequenceOpts = ['clean', 'grab-b2b-data', 'grab-cdn', 'grab-shared-components', 'grab-shared-scripts', 'get-default-trade-questions', 'grab-form-helpers', 'templates', 'styles', 'copy-videos', 'js-lint', 'html-min', 'css-min', 'js-min', 'img-min', 'extras', 'cache-bust', 'add-path-subdirectories', 'copy-resources-to-dist', 'build-stat'];
17
17
  }
18
18
 
19
19
  if (siteData.copyLocalFontFile) {
@@ -0,0 +1,87 @@
1
+ /* globals Promise */
2
+ var request = require('request');
3
+ var source = require('vinyl-source-stream');
4
+ var fs = require('fs');
5
+
6
+ // helper to allow us to define an "end" event to multiple streams
7
+ async function streamToDestination(gulp, siteSettings, siteData, inputPath, destPath, fileName, index) {
8
+ var url = `https://${siteSettings.nodeEnv}${inputPath}`;
9
+ return await new Promise(async function(resolve) { // eslint-disable-line no-undef
10
+ console.time(`${index + 1} B2B data finished after`);
11
+ console.log(`${index + 1} Starting B2B data:`, url);
12
+
13
+ // Collect JSON data for processing
14
+ let jsonData = '';
15
+
16
+ request(url)
17
+ .on('response', async function(resp) {
18
+ if (resp.statusCode !== 200) {
19
+ throw new Error(`Error fetching ${url}`);
20
+ }
21
+ console.timeEnd(`${index + 1} B2B data finished after`);
22
+ })
23
+ .on('data', function(chunk) {
24
+ jsonData += chunk.toString();
25
+ })
26
+ .pipe(source(fileName))
27
+ .pipe(gulp.dest(`${siteSettings.srcFolder}/${destPath}`))
28
+ .on('finish', function() {
29
+ // Parse the JSON data and add to siteData
30
+ try {
31
+ const parsedData = JSON.parse(jsonData);
32
+ const keyName = fileName.replace('.json', '');
33
+ // turn to camelCase so lead-form.json becomes leadForm
34
+ const camelCaseKeyName = keyName.replace(/-([a-z])/g, (g) => g[1].toUpperCase());
35
+ siteData[camelCaseKeyName] = parsedData;
36
+ console.log(`B2B data '${camelCaseKeyName}' added to siteData`);
37
+ } catch (error) {
38
+ console.error(`Error parsing JSON from ${url}:`, error.message);
39
+ }
40
+ resolve();
41
+ });
42
+ });
43
+ }
44
+
45
+ module.exports = function(gulp, _gulpPlugins, siteSettings, siteData) {
46
+ return async function() {
47
+ if (siteData.b2b === undefined || siteData.b2b === false) {
48
+ return;
49
+ }
50
+
51
+ const { nodeEnv } = siteSettings;
52
+
53
+ if (!nodeEnv) {
54
+ throw new Error('Missing environment variables. Did you start with gulp instead of npm run...?');
55
+ }
56
+
57
+ // B2B data files to fetch
58
+ // key: inputPath, value: [destPath, fileName]
59
+ const b2bDataFiles = {
60
+ '/pros/wp-content/themes/modernize/app/Data/b2b-lead-form.json': ['data/', 'lead-form.json'],
61
+ '/pros/wp-content/themes/modernize/app/Data/trades.json': ['data/', 'trades.json']
62
+ };
63
+
64
+ const totalRequests = Object.keys(b2bDataFiles).length;
65
+ return await new Promise(async function(resolve) {
66
+ const sequentialRequests = async function(key, index) {
67
+ if (index === totalRequests) {
68
+ console.log('All B2B data files have been fetched successfully.');
69
+ resolve();
70
+ return;
71
+ }
72
+
73
+ const destinationPath = b2bDataFiles[key][0];
74
+ const fileName = b2bDataFiles[key][1];
75
+
76
+ // Add cache buster to prevent cached responses
77
+ const cachebuster = Math.round(new Date().getTime() / 1000);
78
+ const inputPathWithCacheBuster = `${key}?cb=${cachebuster}`;
79
+
80
+ return await streamToDestination(gulp, siteSettings, siteData, inputPathWithCacheBuster, destinationPath, fileName, index)
81
+ .then(() => sequentialRequests(Object.keys(b2bDataFiles)[index + 1], index + 1));
82
+ };
83
+
84
+ sequentialRequests(Object.keys(b2bDataFiles)[0], 0);
85
+ });
86
+ };
87
+ };
@@ -4,11 +4,11 @@ module.exports.src = function(gulp, gulpPlugins, siteSettings, siteData) {
4
4
  var runSequence = require('run-sequence');
5
5
  var sequenceOpts;
6
6
  if (siteData.useTypescript) {
7
- sequenceOpts = ['clean', 'add-editorconfig', 'grab-cdn', 'grab-shared-components', 'grab-shared-scripts', 'get-default-trade-questions', 'grab-form-helpers', 'templates', 'styles', 'compile', 'grab-tooltips-json', 'combine-files', 'grab-images', 'js-lint'];
7
+ sequenceOpts = ['clean', 'add-editorconfig', 'grab-b2b-data', 'grab-cdn', 'grab-shared-components', 'grab-shared-scripts', 'get-default-trade-questions', 'grab-form-helpers', 'templates', 'styles', 'compile', 'grab-tooltips-json', 'combine-files', 'grab-images', 'js-lint'];
8
8
  } else if (siteData.isQSPage) {
9
- sequenceOpts = ['clean', 'add-editorconfig', 'grab-cdn', 'grab-shared-components', 'grab-shared-scripts', 'get-default-trade-questions', 'grab-form-helpers', 'templates', 'styles', 'grab-theme-json', 'grab-tooltips-json', 'combine-files', 'grab-images', 'js-lint'];
9
+ sequenceOpts = ['clean', 'add-editorconfig', 'grab-b2b-data', 'grab-cdn', 'grab-shared-components', 'grab-shared-scripts', 'get-default-trade-questions', 'grab-form-helpers', 'templates', 'styles', 'grab-theme-json', 'grab-tooltips-json', 'combine-files', 'grab-images', 'js-lint'];
10
10
  } else {
11
- sequenceOpts = ['clean', 'add-editorconfig', 'grab-cdn', 'grab-shared-components', 'grab-shared-scripts', 'get-default-trade-questions', 'grab-form-helpers', 'templates', 'styles', 'grab-tooltips-json', 'combine-files', 'grab-images', 'grab-global-images', 'js-lint'];
11
+ sequenceOpts = ['clean', 'add-editorconfig', 'grab-b2b-data', 'grab-cdn', 'grab-shared-components', 'grab-shared-scripts', 'get-default-trade-questions', 'grab-form-helpers', 'templates', 'styles', 'grab-tooltips-json', 'combine-files', 'grab-images', 'grab-global-images', 'js-lint'];
12
12
  }
13
13
  runSequence(...sequenceOpts, () => {
14
14
  // Run a BrowserSync server
@@ -28,6 +28,17 @@ module.exports = function() {
28
28
  }
29
29
  },
30
30
 
31
+ 'grab-b2b-data': {
32
+ subtasks: [],
33
+ func: function(opts) {
34
+ if ('undefined' === typeof opts.gulpTasksFolderPath) {
35
+ opts.gulpTasksFolderPath = '.';
36
+ }
37
+
38
+ return require(opts.gulpTasksFolderPath + '/grab-b2b-data')(opts.gulp, opts.gulpPlugins, opts.gulpSettings, opts.siteData);
39
+ }
40
+ },
41
+
31
42
  // Grab html files from CDN so they can be swapped into build
32
43
  'grab-cdn': {
33
44
  subtasks: [],
@@ -100,8 +100,6 @@ module.exports = function(gulp, gulpPlugins, siteSettings, siteData) {
100
100
  // Apply seasonal updates
101
101
  applySeasonalUpdates();
102
102
 
103
- var templatesData = Object.assign(commonData(), qsFooterData(siteData), quoteFooterData(siteData), siteData, { isLocal, nodeEnv, assetsPath, buildPath });
104
-
105
103
  // This is helper function to evaluate JS expressions
106
104
  // in Handlebars, e.g. for conditions
107
105
  var handlebarsX = function(expression, context) {
@@ -331,7 +329,7 @@ module.exports = function(gulp, gulpPlugins, siteSettings, siteData) {
331
329
  return steps;
332
330
  };
333
331
 
334
- var getDefaultFormFieldConfig = async function(folder) {
332
+ var getDefaultFormFieldConfig = async function(folder, templatesData) {
335
333
  console.time('Finished fetch-default-form-config after');
336
334
  console.log('Starting fetch-default-form-config: ');
337
335
  await new Promise((resolve) => {
@@ -354,7 +352,7 @@ module.exports = function(gulp, gulpPlugins, siteSettings, siteData) {
354
352
  console.timeEnd('Finished fetch-default-form-config after');
355
353
  };
356
354
 
357
- var fetchTcpaFromSitegenie = async function() {
355
+ var fetchTcpaFromSitegenie = async function(templatesData) {
358
356
  const website = templatesData.website_name;
359
357
  const c_level = templatesData.cLevel ? templatesData.cLevel : 'default';
360
358
  const affiliateKey = templatesData.affiliateKey ? templatesData.affiliateKey : 0;
@@ -391,7 +389,7 @@ module.exports = function(gulp, gulpPlugins, siteSettings, siteData) {
391
389
  console.timeEnd('Finished fetch-tcpa-from-sitegenie after');
392
390
  };
393
391
 
394
- var getConsentCaptureLanguage = async function() {
392
+ var getConsentCaptureLanguage = async function(templatesData) {
395
393
  const requestPromise = (url) => {
396
394
  return new Promise((resolve, reject) => {
397
395
  request(url, (error, xhr, response) => {
@@ -456,21 +454,31 @@ module.exports = function(gulp, gulpPlugins, siteSettings, siteData) {
456
454
  };
457
455
 
458
456
  return async function() {
457
+ var templatesData = Object.assign(commonData(), qsFooterData(siteData), quoteFooterData(siteData), siteData, { isLocal, nodeEnv, assetsPath, buildPath });
458
+
459
+ // Ensure B2B data is explicitly included in templatesData
460
+ if (siteData.leadForm) {
461
+ templatesData.leadForm = siteData.leadForm;
462
+ }
463
+ if (siteData.trades) {
464
+ templatesData.trades = siteData.trades;
465
+ }
466
+
459
467
  if (Object.keys(siteData).length > 0) {
460
468
  if (!templatesData.doNotUseDefaultFieldConfig && !templatesData.defaultConfigCompleted) {
461
469
  if (templatesData.siteData && templatesData.siteData.useAccessibleConfig) {
462
- await getDefaultFormFieldConfig('accessible-components');
470
+ await getDefaultFormFieldConfig('accessible-components', templatesData);
463
471
  } else {
464
- await getDefaultFormFieldConfig('shared-components');
472
+ await getDefaultFormFieldConfig('shared-components', templatesData);
465
473
  }
466
474
  }
467
475
 
468
476
  if (!templatesData.tcpaText && templatesData.primary_trade) {
469
- await fetchTcpaFromSitegenie();
477
+ await fetchTcpaFromSitegenie(templatesData);
470
478
  }
471
479
 
472
480
  if (!templatesData.consentCapture) {
473
- await getConsentCaptureLanguage();
481
+ await getConsentCaptureLanguage(templatesData);
474
482
  }
475
483
  }
476
484
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mod-build",
3
- "version": "3.7.35-beta.1",
3
+ "version": "3.7.35",
4
4
  "description": "Share components for S3 sites.",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",
@@ -1,27 +0,0 @@
1
- const trafficChannels = window.updateMediaSpecificGtm;
2
- // trafficChannels is an array of media channels to enable this feature, e.g. ['sem', 'avm'] - we are going to remove this param after testing
3
- const gtmContainers = {
4
- 'sem': 'GTM-5WM2R5WC',
5
- 'avm': 'GTM-TBJV3H',
6
- 'pub': 'GTM-TBJV3H'
7
- };
8
- const urlParams = new URLSearchParams(window.location.search);
9
- const queryParams = Object.fromEntries(urlParams.entries());
10
- const url = window.location.href.replace(window.location.hash, '');
11
- const hasSemIdentifiers = url.includes('gclid') || url.includes('msclkid') || url.includes('=SEM') || url.includes('=sem');
12
- // const hasQuadlink = 'quadlink' in queryParams; - keeping it for future use
13
- const hasCCIDorCLK = 'ccid' in queryParams || 'clk' in queryParams;
14
- const hasAVMParam = queryParams.channel && queryParams.channel.toLowerCase() === 'avm';
15
- let mediaChannel = 'pub';
16
-
17
- if (hasAVMParam) {
18
- mediaChannel = 'avm';
19
- }
20
-
21
- if (hasSemIdentifiers && !hasCCIDorCLK && !hasAVMParam) {
22
- mediaChannel = 'sem';
23
- }
24
-
25
- if (trafficChannels.includes(mediaChannel) && gtmContainers[mediaChannel]) {
26
- window.gtm_container_ID = gtmContainers[mediaChannel];
27
- }