mod-build 4.0.98-beta.1 → 4.0.98-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 +1 -1
- package/package.json +1 -1
- package/tasks/grab-bbb-logo.js +112 -0
- package/tasks/grab-global-fonts.js +7 -25
- package/tasks/serve.js +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
## 4.0.98
|
|
4
4
|
|
|
5
|
-
-
|
|
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
6
|
|
|
7
7
|
## 4.0.97
|
|
8
8
|
|
package/package.json
CHANGED
|
@@ -0,0 +1,112 @@
|
|
|
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 getSvgInnerContent(svgMarkup) {
|
|
49
|
+
return svgMarkup.replace(/^[\s\S]*?<svg\b[^>]*>/i, '').replace(/<\/svg>\s*$/i, '').trim();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async function updateBbbLogo(svgMarkup) {
|
|
53
|
+
const existingLogos = walkFiles(process.cwd(), (_fullPath, fileName) => fileName === 'bbb.svg');
|
|
54
|
+
|
|
55
|
+
for (const logoPath of existingLogos) {
|
|
56
|
+
fs.writeFileSync(logoPath, `${svgMarkup}\n`, 'utf8');
|
|
57
|
+
console.log(`Updated BBB logo: ${logoPath}`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async function updateAccreditedBusinessText() {
|
|
62
|
+
const files = walkFiles(process.cwd(), (_fullPath, fileName) => (
|
|
63
|
+
fileName.endsWith('.html') || fileName === 'template.js'
|
|
64
|
+
));
|
|
65
|
+
|
|
66
|
+
for (const filePath of files) {
|
|
67
|
+
const contents = fs.readFileSync(filePath, 'utf8');
|
|
68
|
+
|
|
69
|
+
if (!contents.includes(bbbAltText)) {
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const updated = contents.replaceAll(bbbAltText, bbbAltTextUpdated);
|
|
74
|
+
fs.writeFileSync(filePath, updated, 'utf8');
|
|
75
|
+
console.log(`Updated BBB accredited text in: ${filePath}`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async function updateBbbInSprite(svgMarkup) {
|
|
80
|
+
const spriteFiles = walkFiles(process.cwd(), (_fullPath, fileName) => fileName === 'sprite.svg');
|
|
81
|
+
const symbolInnerContent = getSvgInnerContent(svgMarkup);
|
|
82
|
+
|
|
83
|
+
for (const spritePath of spriteFiles) {
|
|
84
|
+
const contents = fs.readFileSync(spritePath, 'utf8');
|
|
85
|
+
const symbolMatch = contents.match(bbbSymbolRegex);
|
|
86
|
+
|
|
87
|
+
if (!symbolMatch) {
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const existingSymbol = symbolMatch[0];
|
|
92
|
+
const openTagMatch = existingSymbol.match(/^<symbol\b[^>]*>/i);
|
|
93
|
+
|
|
94
|
+
if (!openTagMatch) {
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const updatedSymbol = `${openTagMatch[0]}${symbolInnerContent}</symbol>`;
|
|
99
|
+
const updatedContents = contents.replace(existingSymbol, updatedSymbol);
|
|
100
|
+
|
|
101
|
+
fs.writeFileSync(spritePath, updatedContents, 'utf8');
|
|
102
|
+
console.log(`Updated BBB symbol in sprite: ${spritePath}`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export default async function() {
|
|
107
|
+
const svgMarkup = await fetchBbbSvgMarkup();
|
|
108
|
+
|
|
109
|
+
await updateBbbLogo(svgMarkup);
|
|
110
|
+
await updateAccreditedBusinessText();
|
|
111
|
+
await updateBbbInSprite(svgMarkup);
|
|
112
|
+
}
|
|
@@ -27,7 +27,7 @@ const directoryHasItems = (dirPath) => {
|
|
|
27
27
|
return fs.readdirSync(dirPath).length > 0;
|
|
28
28
|
};
|
|
29
29
|
|
|
30
|
-
const getFontDownloadUrls = async (fontName
|
|
30
|
+
const getFontDownloadUrls = async (fontName) => {
|
|
31
31
|
try {
|
|
32
32
|
const url = `https://gwfh.mranftl.com/api/fonts/${fontName}?subsets=latin`;
|
|
33
33
|
const response = await fetchWithRetry(url);
|
|
@@ -38,11 +38,11 @@ const getFontDownloadUrls = async (fontName, weightMap = { regular: '400', bold:
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
const downloadUrls = {};
|
|
41
|
-
const targetWeights =
|
|
41
|
+
const targetWeights = ['400', '700'];
|
|
42
42
|
|
|
43
43
|
fontData.variants.forEach(variant => {
|
|
44
44
|
if (variant.fontStyle === 'normal' && targetWeights.includes(variant.fontWeight)) {
|
|
45
|
-
const variantName =
|
|
45
|
+
const variantName = variant.fontWeight === '400' ? 'regular' : 'bold';
|
|
46
46
|
downloadUrls[variantName] = downloadUrls[variantName] || {};
|
|
47
47
|
if (variant.ttf) {
|
|
48
48
|
downloadUrls[variantName].ttf = variant.ttf;
|
|
@@ -92,23 +92,7 @@ const downloadFontFile = async (fontName, variant, extension, downloadUrl) => {
|
|
|
92
92
|
}
|
|
93
93
|
};
|
|
94
94
|
|
|
95
|
-
const downloadFont = async (
|
|
96
|
-
// Plain name uses defaults; object shape supports custom weights:
|
|
97
|
-
// { montserrat: { fontVariants: [{ medium: '500' }, { bold: '700' }] } }
|
|
98
|
-
let fontName = fontEntry;
|
|
99
|
-
let weightMap = { regular: '400', bold: '700' };
|
|
100
|
-
let variants = fontVariants;
|
|
101
|
-
|
|
102
|
-
if (typeof fontEntry === 'object') {
|
|
103
|
-
fontName = Object.keys(fontEntry)[0];
|
|
104
|
-
const customVariants = fontEntry[fontName]?.fontVariants;
|
|
105
|
-
|
|
106
|
-
if (Array.isArray(customVariants) && customVariants.length > 0) {
|
|
107
|
-
weightMap = Object.assign({}, ...customVariants);
|
|
108
|
-
variants = Object.keys(weightMap);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
95
|
+
const downloadFont = async (fontName) => {
|
|
112
96
|
const fontDir = getFontPath(fontName);
|
|
113
97
|
|
|
114
98
|
if (directoryHasItems(fontDir)) {
|
|
@@ -118,14 +102,14 @@ const downloadFont = async (fontEntry) => {
|
|
|
118
102
|
|
|
119
103
|
console.log(`Downloading font: ${fontName}`);
|
|
120
104
|
|
|
121
|
-
const downloadUrls = await getFontDownloadUrls(fontName
|
|
105
|
+
const downloadUrls = await getFontDownloadUrls(fontName);
|
|
122
106
|
|
|
123
107
|
if (!downloadUrls || Object.keys(downloadUrls).length === 0) {
|
|
124
108
|
throw new Error(`Could not find download URLs for ${fontName}`);
|
|
125
109
|
}
|
|
126
110
|
|
|
127
111
|
await Promise.all(
|
|
128
|
-
|
|
112
|
+
fontVariants.flatMap(variant =>
|
|
129
113
|
fontExtensions.map(ext => {
|
|
130
114
|
const url = downloadUrls[variant]?.[ext];
|
|
131
115
|
if (!url) {
|
|
@@ -138,10 +122,8 @@ const downloadFont = async (fontEntry) => {
|
|
|
138
122
|
);
|
|
139
123
|
};
|
|
140
124
|
|
|
141
|
-
const getFontName = (fontEntry) => typeof fontEntry === 'string' ? fontEntry : Object.keys(fontEntry)[0];
|
|
142
|
-
|
|
143
125
|
const updateGitignore = async (fontNames) => {
|
|
144
|
-
const fontEntries = fontNames.map(
|
|
126
|
+
const fontEntries = fontNames.map(fontName => `${getFontPath(fontName)}/`);
|
|
145
127
|
await addFilesToGitignore(fontEntries, 'Downloaded fonts');
|
|
146
128
|
};
|
|
147
129
|
|
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),
|