mod-build 4.0.98 → 4.0.99

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
+ ## 4.0.99
4
+
5
+ - Added `grab-bbb-logo` task to fetch the updated BBB logo and replace existing `bbb.svg` and/or `<symbol id="bbb">` in the sprite. Also updates current `BBB Accredited Business` alt text in `.html` / `template.js`
6
+
3
7
  ## 4.0.98
4
8
 
5
9
  - Allow `fontsToDownload` entries to specify custom weights via `fontVariants` (e.g. `{ montserrat: { fontVariants: [{ medium: '500' }, { bold: '700' }] } }`); plain font names still default to regular + bold
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mod-build",
3
- "version": "4.0.98",
3
+ "version": "4.0.99",
4
4
  "description": "Share components for S3 sites.",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -0,0 +1,108 @@
1
+ import { defaultSettings } from '../src/data/config.js';
2
+ import { createRetryFetch } from '../src/scripts/retry-fetch.js';
3
+ import fs from 'node:fs';
4
+ import path from 'node:path';
5
+
6
+ const bbbResourcePath = '/quote/resources/assets/images/logos/misc/bbb.svg';
7
+ const bbbAltText = 'BBB Accredited Business';
8
+ const bbbAltTextUpdated = 'Better Business Bureau Accredited Business';
9
+ const bbbSymbolRegex = /<symbol\b[^>]*\bid\s*=\s*["']bbb["'][^>]*>[\s\S]*?<\/symbol>/i;
10
+ const skipDirs = new Set(['node_modules', 'dist', '.git', '.tmp']);
11
+
12
+ const fetchWithRetry = createRetryFetch();
13
+
14
+ function walkFiles(dir, matcher, results = []) {
15
+ if (!fs.existsSync(dir)) {
16
+ return results;
17
+ }
18
+
19
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
20
+ const fullPath = path.join(dir, entry.name);
21
+
22
+ if (entry.isDirectory()) {
23
+ if (!skipDirs.has(entry.name)) {
24
+ walkFiles(fullPath, matcher, results);
25
+ }
26
+ continue;
27
+ }
28
+
29
+ if (entry.isFile() && matcher(fullPath, entry.name)) {
30
+ results.push(fullPath);
31
+ }
32
+ }
33
+
34
+ return results;
35
+ }
36
+
37
+ async function fetchBbbSvgMarkup() {
38
+ const url = `https://${defaultSettings.nodeEnv}${bbbResourcePath}`;
39
+ const response = await fetchWithRetry(url);
40
+
41
+ if (response.status !== 200) {
42
+ throw new Error(`${response.status}: Error while fetching ${url}`);
43
+ }
44
+
45
+ return (await response.text()).trim();
46
+ }
47
+
48
+ function buildBbbSymbol(svgMarkup) {
49
+ const symbol = svgMarkup.replace(/^[\s\S]*?<svg\b/i, '<symbol').replace(/<\/svg>\s*$/i, '</symbol>');
50
+
51
+ if (/^<symbol\b[^>]*\bid\s*=/i.test(symbol)) {
52
+ return symbol;
53
+ }
54
+
55
+ return symbol.replace(/^<symbol\b/i, '<symbol id="bbb"');
56
+ }
57
+
58
+ async function updateBbbLogo(svgMarkup) {
59
+ const existingLogos = walkFiles(process.cwd(), (_fullPath, fileName) => fileName === 'bbb.svg');
60
+
61
+ for (const logoPath of existingLogos) {
62
+ fs.writeFileSync(logoPath, `${svgMarkup}\n`, 'utf8');
63
+ console.log(`Updated BBB logo: ${logoPath}`);
64
+ }
65
+ }
66
+
67
+ async function updateAccreditedBusinessText() {
68
+ const files = walkFiles(process.cwd(), (_fullPath, fileName) => (
69
+ fileName.endsWith('.html') || fileName === 'template.js'
70
+ ));
71
+
72
+ for (const filePath of files) {
73
+ const contents = fs.readFileSync(filePath, 'utf8');
74
+
75
+ if (!contents.includes(bbbAltText)) {
76
+ continue;
77
+ }
78
+
79
+ const updated = contents.replaceAll(bbbAltText, bbbAltTextUpdated);
80
+ fs.writeFileSync(filePath, updated, 'utf8');
81
+ console.log(`Updated BBB accredited text in: ${filePath}`);
82
+ }
83
+ }
84
+
85
+ async function updateBbbInSprite(svgMarkup) {
86
+ const spriteFiles = walkFiles(process.cwd(), (_fullPath, fileName) => fileName === 'sprite.svg');
87
+ const updatedSymbol = buildBbbSymbol(svgMarkup);
88
+
89
+ for (const spritePath of spriteFiles) {
90
+ const contents = fs.readFileSync(spritePath, 'utf8');
91
+
92
+ if (!bbbSymbolRegex.test(contents)) {
93
+ continue;
94
+ }
95
+
96
+ const updatedContents = contents.replace(bbbSymbolRegex, updatedSymbol);
97
+ fs.writeFileSync(spritePath, updatedContents, 'utf8');
98
+ console.log(`Updated BBB symbol in sprite: ${spritePath}`);
99
+ }
100
+ }
101
+
102
+ export default async function() {
103
+ const svgMarkup = await fetchBbbSvgMarkup();
104
+
105
+ await updateBbbLogo(svgMarkup);
106
+ await updateAccreditedBusinessText();
107
+ await updateBbbInSprite(svgMarkup);
108
+ }
package/tasks/serve.js CHANGED
@@ -4,6 +4,7 @@ import grabGlobalFonts from './grab-global-fonts.js';
4
4
  import grabSharedComponents from './grab-shared-components.js';
5
5
  import grabSharedScripts from './grab-shared-scripts.js';
6
6
  import grabCdn from './grab-cdn.js';
7
+ import grabBbbLogo from './grab-bbb-logo.js';
7
8
  import grabB2BData from './grab-b2b-data.js';
8
9
  import getDefaultTradeQuestions from './get-default-trade-questions.js';
9
10
  import grabFormHelpers from './grab-form-helpers.js';
@@ -18,6 +19,7 @@ export async function startModBuild(config) {
18
19
  await grabGlobalFonts(config);
19
20
  await grabB2BData(config);
20
21
  await grabCdn(config);
22
+ await grabBbbLogo();
21
23
  await getDefaultTradeQuestions(config);
22
24
  await Promise.all([
23
25
  grabSharedComponents(config),