mod-build 3.7.32 → 3.7.33

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.7.33
4
+
5
+ - Added support for seasonal changes in all steps objects.
6
+
3
7
  ## 3.7.32
4
8
 
5
9
  - Update editorconfig path
@@ -27,52 +27,79 @@ module.exports = function(gulp, gulpPlugins, siteSettings, siteData) {
27
27
  const CENTRAL_AC = 'Central AC';
28
28
  const CENTRAL_HEATING = 'Central Heating';
29
29
  siteData.isWarmWeather = false; // will use this variable in site level to update the hero title/subtitle wherever required
30
- if (activeSeason.length !== 0) {
31
- if (activeSeason.includes(SEASON)) {
32
- siteData.isWarmWeather = true;
33
- const data = JSON.stringify(siteData, null, 4);
34
- const heating = '(Heating|heating|calentadores|Calentadores|calefactores|Calefactores)';
35
- const and = '(\\s&\\s|\\sand\\s|and|\\sy\\s)'; // eslint-disable-line no-useless-escape
36
- const ac = '(AC|Cooling|cooling|aires.*?acondicionados|Aires.*?Acondicionados)';
37
- const spaces = '.*?';
38
-
39
- const regex = new RegExp(`${heating}${spaces}${and}${spaces}${ac}`, 'gm');
40
- // Find and reverse the required words in the string using regex group capture
41
- const processedData = data.replaceAll(regex, '$3 $2 $1');
42
- // Convert data into JSON
43
- siteData = JSON.parse(processedData);
44
- // Find the HVACInterest step and reverse the options array
45
- if (siteData.steps && (siteData.steps.items && siteData.steps.items.length)) {
46
- siteData.steps.items.forEach(function(step) {
47
- const isHvacInterestStep = step && (step.stepName && step.stepName === HVAC_INTEREST) || (step.attributes && step.attributes.data && step.attributes.data['step-name'] === HVAC_INTEREST);
48
- if (isHvacInterestStep) {
49
- const stepFields = step.fields || step.stepContent.fields;
50
- if (stepFields && stepFields.length) {
51
- stepFields.forEach(function(field) {
52
- const firstOption = field.options[0];
53
- const lastOption = field.options[field.options.length - 1];
54
- const firstOptionIsCentralHeating = (firstOption.attributes && firstOption.attributes.value === CENTRAL_HEATING) || firstOption.value === CENTRAL_HEATING;
55
- const lastOptionIsCentralAC = (lastOption.attributes && lastOption.attributes.value === CENTRAL_AC) || lastOption.value === CENTRAL_AC;
56
- // if the first option is central heating & last option is central ac then only swap those options
57
- if (firstOptionIsCentralHeating && lastOptionIsCentralAC) {
58
- field.options[0] = lastOption;
59
- field.options[field.options.length - 1] = firstOption;
60
- }
61
30
 
62
- field.options.some(function(option) {
63
- if (option.checked) {
64
- option.checked = false;
65
- field.options[0].checked = true;
66
- }
67
- });
31
+ var processStepsOptions = async function(steps, HVAC_INTEREST, CENTRAL_AC, CENTRAL_HEATING) {
32
+ if (steps && steps.items && steps.items.length) {
33
+ for (const step of steps.items) {
34
+ const isHvacInterestStep = step && (step.stepName && step.stepName === HVAC_INTEREST) || (step.attributes && step.attributes.data && step.attributes.data['step-name'] === HVAC_INTEREST);
35
+ if (isHvacInterestStep) {
36
+ const stepFields = step.fields || step.stepContent.fields;
37
+ if (stepFields && stepFields.length) {
38
+ for (const field of stepFields) {
39
+ const firstOption = field.options[0];
40
+ const lastOption = field.options[field.options.length - 1];
41
+ const firstOptionIsCentralHeating = (firstOption.attributes && firstOption.attributes.value === CENTRAL_HEATING) || firstOption.value === CENTRAL_HEATING;
42
+ const lastOptionIsCentralAC = (lastOption.attributes && lastOption.attributes.value === CENTRAL_AC) || lastOption.value === CENTRAL_AC;
43
+ // if the first option is central heating & last option is central ac then only swap those options
44
+ if (firstOptionIsCentralHeating && lastOptionIsCentralAC) {
45
+ field.options[0] = lastOption;
46
+ field.options[field.options.length - 1] = firstOption;
47
+ }
48
+
49
+ field.options.some(function(option) {
50
+ if (option.checked) {
51
+ option.checked = false;
52
+ field.options[0].checked = true;
53
+ }
68
54
  });
69
55
  }
70
56
  }
71
- });
57
+ }
58
+ }
59
+ }
60
+ }
61
+
62
+ var applySeasonalChangesToAllSteps = async function(data, HVAC_INTEREST, CENTRAL_AC, CENTRAL_HEATING) {
63
+ if (!data || typeof data !== 'object') {
64
+ return;
65
+ }
66
+
67
+ if (data.steps && typeof data.steps === 'object') {
68
+ await processStepsOptions(data.steps, HVAC_INTEREST, CENTRAL_AC, CENTRAL_HEATING);
69
+ }
70
+
71
+ for (const key of Object.keys(data)) {
72
+ const value = data[key];
73
+ if (typeof value === 'object' && value !== null) {
74
+ await applySeasonalChangesToAllSteps(value, HVAC_INTEREST, CENTRAL_AC, CENTRAL_HEATING);
72
75
  }
73
76
  }
74
77
  }
75
78
 
79
+ var applySeasonalUpdates = async function() {
80
+ if (activeSeason.length !== 0) {
81
+ if (activeSeason.includes(SEASON)) {
82
+ siteData.isWarmWeather = true;
83
+ const data = JSON.stringify(siteData, null, 4);
84
+ const heating = '(Heating|heating|calentadores|Calentadores|calefactores|Calefactores)';
85
+ const and = '(\\s&\\s|\\sand\\s|and|\\sy\\s)'; // eslint-disable-line no-useless-escape
86
+ const ac = '(AC|Cooling|cooling|aires.*?acondicionados|Aires.*?Acondicionados)';
87
+ const spaces = '.*?';
88
+
89
+ const regex = new RegExp(`${heating}${spaces}${and}${spaces}${ac}`, 'gm');
90
+ // Find and reverse the required words in the string using regex group capture
91
+ const processedData = data.replaceAll(regex, '$3 $2 $1');
92
+ // Convert data into JSON
93
+ siteData = JSON.parse(processedData);
94
+ // Apply seasonal changes to all steps objects recursively
95
+ await applySeasonalChangesToAllSteps(siteData, HVAC_INTEREST, CENTRAL_AC, CENTRAL_HEATING);
96
+ }
97
+ }
98
+ }
99
+
100
+ // Apply seasonal updates
101
+ applySeasonalUpdates();
102
+
76
103
  var templatesData = Object.assign(commonData(), qsFooterData(siteData), quoteFooterData(siteData), siteData, { isLocal, nodeEnv, assetsPath, buildPath });
77
104
 
78
105
  // This is helper function to evaluate JS expressions
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mod-build",
3
- "version": "3.7.32",
3
+ "version": "3.7.33",
4
4
  "description": "Share components for S3 sites.",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",