mod-build 4.0.105-beta.2 → 4.0.106-beta.1

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,11 +1,19 @@
1
1
  # Changelog
2
+
3
+ ## 4.0.106
4
+
5
+ - Added `grab-global-images task` to download our hosted images in the site folder instead of dynamically fetching them in client side.
6
+
2
7
  ## 4.0.105
3
- - Adding dns modal path in grab-cdn.
8
+
9
+ - Updating `grab-code-review-rules.js` to pivot away from Rovo & switch to Cursor Bugbot.
4
10
 
5
11
  ## 4.0.104
12
+
6
13
  - Migrating vite to master.
7
14
 
8
15
  ## 4.0.103
16
+
9
17
  - Removing unused files.
10
18
 
11
19
  ## 4.0.102
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mod-build",
3
- "version": "4.0.105-beta.2",
3
+ "version": "4.0.106-beta.1",
4
4
  "description": "Share components for S3 sites.",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -4,7 +4,8 @@ export const defaultSettings = {
4
4
  distFolder: 'dist',
5
5
  publicFolder: 'public',
6
6
  fontsSubfolder: 'fonts',
7
- imagesSubfolder: 'images',
7
+ assetsSubfolder: 'assets',
8
+ imagesSubfolder: 'images',
8
9
  stylesSubfolder: 'styles',
9
10
  scriptsSubfolder: 'scripts',
10
11
  scriptsCompiledFolder: 'scripts/compiled',
package/tasks/grab-cdn.js CHANGED
@@ -83,8 +83,7 @@ export default async function(config) {
83
83
  '/quote/resources/shared-resources/templates/modals/terms/': [`${srcFolder}/resources/templates/modals/terms/`, 'index.html'],
84
84
  '/quote/resources/shared-resources/templates/modals/contact-us/': [`${srcFolder}/resources/templates/modals/contact-us/`, 'index.html'],
85
85
  '/quote/resources/shared-resources/templates/modals/faq/': [`${srcFolder}/resources/templates/modals/faq/`, 'index.html'],
86
- '/quote/resources/shared-resources/templates/modals/e-sign-consent/': [`${srcFolder}/resources/templates/modals/e-sign-consent/`, 'index.html'],
87
- '/quote/resources/shared-resources/templates/modals/dns/': [`${srcFolder}/resources/templates/modals/dns/`, 'index.html']
86
+ '/quote/resources/shared-resources/templates/modals/e-sign-consent/': [`${srcFolder}/resources/templates/modals/e-sign-consent/`, 'index.html']
88
87
  });
89
88
 
90
89
  if (cssThemes && cssThemes.length > 0) {
@@ -6,14 +6,15 @@ async function grabRules() {
6
6
  const url = `https://${defaultSettings.nodeEnv}/quote/resources/mod-site/code-review-rules/review-agent.md`;
7
7
  const response = await fetch(url);
8
8
 
9
- if (response.status !== 200) {
9
+ if (!response.ok) {
10
10
  throw new Error(`${response.status}: Error while fetching review-agent.md`);
11
11
  }
12
12
 
13
13
  const text = await response.text();
14
14
 
15
- await fs.mkdir('.rovodev', { recursive: true });
16
- await fs.writeFile('.rovodev/.review-agent.md', text, 'utf8');
15
+ await fs.mkdir('.cursor', { recursive: true });
16
+ await fs.writeFile('.cursor/BUGBOT.md', text, 'utf8');
17
+ await fs.rm('.rovodev', { recursive: true, force: true });
17
18
  } catch (error) {
18
19
  console.error('Error occurred:', error.message);
19
20
  }
@@ -14,6 +14,7 @@ const finished = promisify(stream.finished);
14
14
 
15
15
  const fetchWithRetry = createRetryFetch();
16
16
 
17
+
17
18
  const getFontPath = (...parts) => path.join(
18
19
  defaultSettings.publicFolder,
19
20
  defaultSettings.fontsSubfolder,
@@ -0,0 +1,142 @@
1
+ import { defaultSettings } from "../src/data/config";
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+ import addFilesToGitignore from './add-files-to-gitignore.js';
5
+
6
+ function getPictureObjectsWithUseCDN(node, found = []) {
7
+ if (!node || typeof node !== 'object') {
8
+ return found;
9
+ }
10
+
11
+ if (node.useCDN && (node.img || node.svg)) {
12
+ found.push(node);
13
+ }
14
+
15
+ if (Array.isArray(node)) {
16
+ node.forEach((item) => getPictureObjectsWithUseCDN(item, found));
17
+ } else {
18
+ Object.values(node).forEach((value) => getPictureObjectsWithUseCDN(value, found));
19
+ }
20
+
21
+ return found;
22
+ }
23
+
24
+ async function fetchGlobalImageAndUpdateSrc(picture) {
25
+ const { img, svg, source } = picture;
26
+ let imagesToDownload = [];
27
+ if (img) {
28
+ if (img.attributes && img.attributes.src) {
29
+ // remove leading slash from src
30
+ let src = img.attributes.src;
31
+ if (src.startsWith('/')) {
32
+ src = src.slice(1);
33
+ }
34
+ imagesToDownload.push(src);
35
+ }
36
+ }
37
+
38
+ if (svg) {
39
+ if (svg.use && svg.use.attributes && svg.use.attributes.href) {
40
+ let href = svg.use.attributes.href;
41
+ if (href.startsWith('/')) {
42
+ href = href.slice(1);
43
+ }
44
+ href = href.split('#')[0];
45
+ if (href) {
46
+ imagesToDownload.push(href);
47
+ }
48
+ }
49
+ }
50
+
51
+ if (source && Array.isArray(source)) {
52
+ source.forEach((item) => {
53
+ if (item.attributes && item.attributes.srcset) {
54
+ let srcset = item.attributes.srcset;
55
+ if (srcset.startsWith('/')) {
56
+ srcset = srcset.slice(1);
57
+ }
58
+ imagesToDownload.push(srcset);
59
+ }
60
+ });
61
+ }
62
+
63
+ if (imagesToDownload.length === 0) {
64
+ return;
65
+ }
66
+
67
+ // download the images
68
+ let imageDirs = await Promise.all(imagesToDownload.map((url) => downloadImage(url)));
69
+ // add the image dirs to gitignore
70
+ await addFilesToGitignore([...imageDirs.filter(Boolean)], 'Global images');
71
+
72
+ // now in all src, srcset and href values add '/assets' in front of them
73
+ if (img) {
74
+ if (img.attributes && img.attributes.src) {
75
+ img.attributes.src = `/${defaultSettings.assetsSubfolder}${img.attributes.src}`;
76
+ }
77
+ }
78
+
79
+ if (svg) {
80
+ if (svg.use && svg.use.attributes && svg.use.attributes.href) {
81
+ svg.use.attributes.href = `/${defaultSettings.assetsSubfolder}${svg.use.attributes.href}`;
82
+ }
83
+ }
84
+
85
+ if (source && Array.isArray(source)) {
86
+ source.forEach((item) => {
87
+ if (item.attributes && item.attributes.srcset) {
88
+ item.attributes.srcset = `/${defaultSettings.assetsSubfolder}${item.attributes.srcset}`;
89
+ }
90
+ });
91
+ }
92
+
93
+ // remove picture.useCDN
94
+ delete picture.useCDN;
95
+
96
+ }
97
+
98
+ async function downloadImage(url) {
99
+ // first check if the image already exists in public/assets folder
100
+ const imagePath = path.join(defaultSettings.publicFolder, defaultSettings.assetsSubfolder, url);
101
+ if (fs.existsSync(imagePath)) {
102
+ return null;
103
+ }
104
+ // download the image and put in imagePath
105
+ try {
106
+ const fileUrl = `https://${defaultSettings.nodeEnv}/quote/resources/assets/${url}`
107
+ const response = await fetch(fileUrl);
108
+ if (!response.ok) {
109
+ console.error(`Error downloading image ${url}: ${response.statusText}`);
110
+ throw new Error(`Error downloading image ${url}: ${response.statusText}`);
111
+ }
112
+ const buffer = Buffer.from(await response.arrayBuffer());
113
+ fs.mkdirSync(path.dirname(imagePath), { recursive: true });
114
+ fs.writeFileSync(imagePath, buffer);
115
+ console.log(`Downloaded image ${url} and added to gitignore`);
116
+ return path.dirname(imagePath);
117
+ } catch (error) {
118
+ console.error(`Error downloading image ${url}: ${error}`);
119
+ throw new Error(`Error downloading image ${url}: ${error}`);
120
+ }
121
+ }
122
+
123
+ export default async function(config) {
124
+ console.log('Starting grab-global-images...');
125
+ // check if assets/images exists in public folder
126
+ const imagesPath = path.join(defaultSettings.publicFolder, defaultSettings.assetsSubfolder, defaultSettings.imagesSubfolder);
127
+ if (!fs.existsSync(imagesPath)) {
128
+ fs.mkdirSync(imagesPath, { recursive: true });
129
+ }
130
+
131
+ const pictureObjects = getPictureObjectsWithUseCDN(config);
132
+
133
+ if (pictureObjects.length === 0) {
134
+ console.log('No global images to download');
135
+ return;
136
+ }
137
+
138
+ await Promise.all(pictureObjects.map((picture) => fetchGlobalImageAndUpdateSrc(picture)));
139
+
140
+
141
+ console.log('Finished grab-global-images...');
142
+ }
package/tasks/serve.js CHANGED
@@ -11,6 +11,7 @@ import grabFormHelpers from './grab-form-helpers.js';
11
11
  import grabJSDoc from './grab-jsdoc.js';
12
12
  import templates from './templates.js';
13
13
  import { createStylelintFile, updateConfig } from '../src/scripts/plugins.js';
14
+ import grabGlobalImages from './grab-global-images.js';
14
15
 
15
16
  export async function startModBuild(config) {
16
17
  addEditorConfig();
@@ -21,6 +22,7 @@ export async function startModBuild(config) {
21
22
  await grabCdn(config);
22
23
  await grabBbbLogo();
23
24
  await getDefaultTradeQuestions(config);
25
+ await grabGlobalImages(config);
24
26
  await Promise.all([
25
27
  grabSharedComponents(config),
26
28
  grabFormHelpers(config),