mod-build 4.0.98-beta.4 → 4.0.98

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
@@ -2,7 +2,7 @@
2
2
 
3
3
  ## 4.0.98
4
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`
5
+ - 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
6
6
 
7
7
  ## 4.0.97
8
8
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mod-build",
3
- "version": "4.0.98-beta.4",
3
+ "version": "4.0.98",
4
4
  "description": "Share components for S3 sites.",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -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, weightMap = { regular: '400', bold: '700' }) => {
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) => {
38
38
  }
39
39
 
40
40
  const downloadUrls = {};
41
- const targetWeights = ['400', '700'];
41
+ const targetWeights = Object.values(weightMap);
42
42
 
43
43
  fontData.variants.forEach(variant => {
44
44
  if (variant.fontStyle === 'normal' && targetWeights.includes(variant.fontWeight)) {
45
- const variantName = variant.fontWeight === '400' ? 'regular' : 'bold';
45
+ const variantName = Object.keys(weightMap).find(name => weightMap[name] === variant.fontWeight);
46
46
  downloadUrls[variantName] = downloadUrls[variantName] || {};
47
47
  if (variant.ttf) {
48
48
  downloadUrls[variantName].ttf = variant.ttf;
@@ -92,7 +92,23 @@ const downloadFontFile = async (fontName, variant, extension, downloadUrl) => {
92
92
  }
93
93
  };
94
94
 
95
- const downloadFont = async (fontName) => {
95
+ const downloadFont = async (fontEntry) => {
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
+
96
112
  const fontDir = getFontPath(fontName);
97
113
 
98
114
  if (directoryHasItems(fontDir)) {
@@ -102,14 +118,14 @@ const downloadFont = async (fontName) => {
102
118
 
103
119
  console.log(`Downloading font: ${fontName}`);
104
120
 
105
- const downloadUrls = await getFontDownloadUrls(fontName);
121
+ const downloadUrls = await getFontDownloadUrls(fontName, weightMap);
106
122
 
107
123
  if (!downloadUrls || Object.keys(downloadUrls).length === 0) {
108
124
  throw new Error(`Could not find download URLs for ${fontName}`);
109
125
  }
110
126
 
111
127
  await Promise.all(
112
- fontVariants.flatMap(variant =>
128
+ variants.flatMap(variant =>
113
129
  fontExtensions.map(ext => {
114
130
  const url = downloadUrls[variant]?.[ext];
115
131
  if (!url) {
@@ -122,8 +138,10 @@ const downloadFont = async (fontName) => {
122
138
  );
123
139
  };
124
140
 
141
+ const getFontName = (fontEntry) => typeof fontEntry === 'string' ? fontEntry : Object.keys(fontEntry)[0];
142
+
125
143
  const updateGitignore = async (fontNames) => {
126
- const fontEntries = fontNames.map(fontName => `${getFontPath(fontName)}/`);
144
+ const fontEntries = fontNames.map(fontEntry => `${getFontPath(getFontName(fontEntry))}/`);
127
145
  await addFilesToGitignore(fontEntries, 'Downloaded fonts');
128
146
  };
129
147
 
package/tasks/serve.js CHANGED
@@ -4,7 +4,6 @@ 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';
8
7
  import grabB2BData from './grab-b2b-data.js';
9
8
  import getDefaultTradeQuestions from './get-default-trade-questions.js';
10
9
  import grabFormHelpers from './grab-form-helpers.js';
@@ -19,7 +18,6 @@ export async function startModBuild(config) {
19
18
  await grabGlobalFonts(config);
20
19
  await grabB2BData(config);
21
20
  await grabCdn(config);
22
- await grabBbbLogo();
23
21
  await getDefaultTradeQuestions(config);
24
22
  await Promise.all([
25
23
  grabSharedComponents(config),
@@ -1,108 +0,0 @@
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
- }