mod-build 4.0.83-beta.3 → 4.0.83-beta.5

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,9 +1,13 @@
1
1
  # Changelog
2
2
 
3
- ## 4.0.83
3
+ ## 4.0.84
4
4
 
5
5
  - Updated `grab-global-fonts` task to grab fonts from `gwfh.mranftl.com/api/fonts` -- will default to `Roboto` unless defined in `siteconfig.js` = `fontsToDownload: ['font-name']`
6
6
 
7
+ ## 4.0.83
8
+
9
+ - Updated `grab-jsdoc` task to use correct resource path for mod-form
10
+
7
11
  ## 4.0.82
8
12
 
9
13
  - Added `grab-global-fonts` task to grab Roboto + Montserrat font files from mod-site
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mod-build",
3
- "version": "4.0.83-beta.3",
3
+ "version": "4.0.83-beta.5",
4
4
  "description": "Share components for S3 sites.",
5
5
  "type": "module",
6
6
  "scripts": {
package/tasks/clean.js CHANGED
@@ -13,20 +13,20 @@ const fontFoldersToDelete = fs.existsSync(fontBaseFolder)
13
13
 
14
14
  const foldersToDelete = [...baseFoldersToDelete, ...fontFoldersToDelete];
15
15
 
16
- foldersToDelete.forEach(async (folder) => {
16
+ await Promise.all(foldersToDelete.map(async (folder) => {
17
17
  try {
18
18
  await fs.promises.rm(folder, { recursive: true });
19
19
  console.log(`Folder ${folder} deleted successfully`);
20
20
  } catch (err) {
21
21
  // fail silently
22
22
  }
23
- });
23
+ }));
24
24
 
25
- filesToDelete.forEach(async (file) => {
25
+ await Promise.all(filesToDelete.map(async (file) => {
26
26
  try {
27
27
  await fs.promises.rm(file);
28
28
  console.log(`File ${file} deleted successfully`);
29
29
  } catch (err) {
30
30
  // fail silently
31
31
  }
32
- });
32
+ }));
@@ -11,16 +11,22 @@ import addFilesToGitignore from './add-files-to-gitignore.js';
11
11
  // Font variants and extensions to download for each font
12
12
  const fontVariants = ['regular', 'bold'];
13
13
  const fontExtensions = ['ttf', 'woff2'];
14
+ const finished = promisify(stream.finished);
14
15
 
15
16
  const axiosInstance = axios.create();
16
17
  responseInterceptor(axiosInstance);
17
18
 
19
+ const getFontPath = (...parts) => path.join(
20
+ defaultSettings.publicFolder,
21
+ defaultSettings.fontsSubfolder,
22
+ ...parts
23
+ );
24
+
18
25
  const directoryHasItems = (dirPath) => {
19
26
  if (!fs.existsSync(dirPath)) {
20
27
  return false;
21
28
  }
22
- const items = fs.readdirSync(dirPath);
23
- return items.length > 0;
29
+ return fs.readdirSync(dirPath).length > 0;
24
30
  };
25
31
 
26
32
  const getFontDownloadUrls = async (fontName) => {
@@ -29,22 +35,17 @@ const getFontDownloadUrls = async (fontName) => {
29
35
  const response = await axiosInstance.get(url);
30
36
  const fontData = response.data;
31
37
 
32
- if (!fontData || !fontData.variants) {
38
+ if (!fontData?.variants) {
33
39
  throw new Error('Invalid font data received');
34
40
  }
35
41
 
36
42
  const downloadUrls = {};
37
-
38
43
  const targetWeights = ['400', '700'];
39
44
 
40
45
  fontData.variants.forEach(variant => {
41
46
  if (variant.fontStyle === 'normal' && targetWeights.includes(variant.fontWeight)) {
42
47
  const variantName = variant.fontWeight === '400' ? 'regular' : 'bold';
43
-
44
- if (!downloadUrls[variantName]) {
45
- downloadUrls[variantName] = {};
46
- }
47
-
48
+ downloadUrls[variantName] = downloadUrls[variantName] || {};
48
49
  if (variant.ttf) {
49
50
  downloadUrls[variantName].ttf = variant.ttf;
50
51
  }
@@ -53,7 +54,7 @@ const getFontDownloadUrls = async (fontName) => {
53
54
  }
54
55
  }
55
56
  });
56
-
57
+
57
58
  return downloadUrls;
58
59
  } catch (error) {
59
60
  console.error(`Error fetching font data for ${fontName}:`, error.message);
@@ -61,61 +62,44 @@ const getFontDownloadUrls = async (fontName) => {
61
62
  }
62
63
  };
63
64
 
64
- const downloadFontFile = async (defaultSettings, fontName, variant, extension, downloadUrl) => {
65
- const finished = promisify(stream.finished);
66
-
67
- return new Promise((resolve, reject) => {
68
- const fileName = `${fontName}-${variant}.${extension}`;
69
- const filePath = path.join(
70
- defaultSettings.publicFolder,
71
- defaultSettings.fontsSubfolder,
72
- fontName,
73
- fileName
74
- );
75
- const folderPath = path.dirname(filePath);
76
-
77
- if (!fs.existsSync(folderPath)) {
78
- fs.mkdirSync(folderPath, { recursive: true });
79
- }
65
+ const downloadFontFile = async (fontName, variant, extension, downloadUrl) => {
66
+ const fileName = `${fontName}-${variant}.${extension}`;
67
+ const filePath = getFontPath(fontName, fileName);
68
+ const folderPath = path.dirname(filePath);
80
69
 
81
- if (fs.existsSync(filePath)) {
82
- console.log(`${filePath} already exists, skipping...`);
83
- resolve();
84
- return;
85
- }
70
+ if (!fs.existsSync(folderPath)) {
71
+ fs.mkdirSync(folderPath, { recursive: true });
72
+ }
86
73
 
87
- const writer = createWriteStream(filePath);
74
+ if (fs.existsSync(filePath)) {
75
+ console.log(`${filePath} already exists, skipping...`);
76
+ return;
77
+ }
88
78
 
89
- axiosInstance({
79
+ try {
80
+ const resp = await axiosInstance({
90
81
  url: downloadUrl,
91
82
  method: 'get',
92
83
  responseType: 'stream'
93
- })
94
- .then(resp => {
95
- if (resp.status !== 200) {
96
- throw new Error(`${resp.status}: Error while fetching ${downloadUrl}`);
97
- }
98
- console.log(`Downloading ${filePath}...`);
99
- resp.data.pipe(writer);
100
- return finished(writer);
101
- })
102
- .then(() => {
103
- console.log(`${filePath} downloaded successfully`);
104
- resolve();
105
- })
106
- .catch(error => {
107
- console.error(`Error downloading ${filePath} from ${downloadUrl}:`, error.message);
108
- reject(new Error(`Failed to download ${filePath}: ${error.message}`));
109
- });
110
- });
84
+ });
85
+
86
+ if (resp.status !== 200) {
87
+ throw new Error(`${resp.status}: Error while fetching ${downloadUrl}`);
88
+ }
89
+
90
+ console.log(`Downloading ${filePath}...`);
91
+ const writer = createWriteStream(filePath);
92
+ resp.data.pipe(writer);
93
+ await finished(writer);
94
+ console.log(`${filePath} downloaded successfully`);
95
+ } catch (error) {
96
+ console.error(`Error downloading ${filePath} from ${downloadUrl}:`, error.message);
97
+ throw new Error(`Failed to download ${filePath}: ${error.message}`);
98
+ }
111
99
  };
112
100
 
113
- const downloadFont = async (defaultSettings, fontName) => {
114
- const fontDir = path.join(
115
- defaultSettings.publicFolder,
116
- defaultSettings.fontsSubfolder,
117
- fontName
118
- );
101
+ const downloadFont = async (fontName) => {
102
+ const fontDir = getFontPath(fontName);
119
103
 
120
104
  if (directoryHasItems(fontDir)) {
121
105
  console.log(`Font directory ${fontDir} already has items, skipping ${fontName}...`);
@@ -130,45 +114,35 @@ const downloadFont = async (defaultSettings, fontName) => {
130
114
  throw new Error(`Could not find download URLs for ${fontName}`);
131
115
  }
132
116
 
133
- const downloadPromises = fontVariants.flatMap(variant => {
134
- return fontExtensions.map(ext => {
135
- const url = downloadUrls[variant]?.[ext];
136
- if (!url) {
137
- console.warn(`Warning: No ${ext} URL found for ${fontName} ${variant}, skipping...`);
138
- return Promise.resolve();
139
- }
140
- return downloadFontFile(defaultSettings, fontName, variant, ext, url);
141
- });
142
- });
143
-
144
- await Promise.all(downloadPromises);
117
+ await Promise.all(
118
+ fontVariants.flatMap(variant =>
119
+ fontExtensions.map(ext => {
120
+ const url = downloadUrls[variant]?.[ext];
121
+ if (!url) {
122
+ console.warn(`Warning: No ${ext} URL found for ${fontName} ${variant}, skipping...`);
123
+ return Promise.resolve();
124
+ }
125
+ return downloadFontFile(fontName, variant, ext, url);
126
+ })
127
+ )
128
+ );
145
129
  };
146
130
 
147
- const updateGitignore = async (defaultSettings, fontNames) => {
148
- const fontEntries = fontNames.map(fontName =>
149
- `${defaultSettings.publicFolder}/${defaultSettings.fontsSubfolder}/${fontName}/`
150
- );
151
-
152
- await addFilesToGitignore(fontEntries, 'Global fonts');
131
+ const updateGitignore = async (fontNames) => {
132
+ const fontEntries = fontNames.map(fontName => `${getFontPath(fontName)}/`);
133
+ await addFilesToGitignore(fontEntries, 'Downloaded fonts');
153
134
  };
154
135
 
155
136
  // If a site has a branded font that is outside of this API - we should add it to /public/fonts/branded/{fontName}/*
156
- export default function(config) {
137
+ export default async function(config) {
157
138
  // Download fonts from config.fontsToDownload or will default to ['roboto']
158
- const fontNames = config?.fontsToDownload && Array.isArray(config.fontsToDownload) && config.fontsToDownload.length > 0
159
- ? config.fontsToDownload
160
- : ['roboto'];
139
+ const fontNames = config?.fontsToDownload?.length > 0 ? config.fontsToDownload : ['roboto'];
161
140
 
162
- const fontsPath = path.join(defaultSettings.publicFolder, defaultSettings.fontsSubfolder);
141
+ const fontsPath = getFontPath();
163
142
  if (!fs.existsSync(fontsPath)) {
164
143
  fs.mkdirSync(fontsPath, { recursive: true });
165
144
  }
166
145
 
167
- const fontPromises = fontNames.map(fontName => {
168
- return downloadFont(defaultSettings, fontName);
169
- });
170
-
171
- return Promise.all(fontPromises).then(async () => {
172
- await updateGitignore(defaultSettings, fontNames);
173
- });
146
+ await Promise.all(fontNames.map(downloadFont));
147
+ await updateGitignore(fontNames);
174
148
  }
@@ -7,7 +7,7 @@ import path from 'node:path';
7
7
  import { responseInterceptor } from '../src/scripts/retry-axios.js';
8
8
  import addFilesToGitignore from './add-files-to-gitignore.js';
9
9
 
10
- const resourcePath = 'quote/resources/mod-form/form';
10
+ const resourcePath = 'quote/resources/mod-form';
11
11
  const axiosInstance = axios.create();
12
12
  const jsdocAxiosInstance = axios.create();
13
13
  responseInterceptor(axiosInstance);
package/tasks/serve.js CHANGED
@@ -13,7 +13,7 @@ import { createStylelintFile, updateConfig } from '../src/scripts/plugins.js';
13
13
  export async function startModBuild(config) {
14
14
  addEditorConfig();
15
15
  createStylelintFile();
16
- grabGlobalFonts(config);
16
+ await grabGlobalFonts(config);
17
17
  await grabB2BData(config);
18
18
  await grabCdn(config);
19
19
  await getDefaultTradeQuestions(config);