mod-build 4.0.0-beta.4 → 4.0.0-beta.4c

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mod-build",
3
- "version": "4.0.0-beta.4",
3
+ "version": "4.0.0-beta.4c",
4
4
  "description": "Share components for S3 sites.",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -2,6 +2,7 @@ export const defaultSettings = {
2
2
  tmpFolder: '.tmp',
3
3
  srcFolder: 'src',
4
4
  distFolder: 'dist',
5
+ publicFolder: 'public',
5
6
  fontsSubfolder: 'fonts',
6
7
  imagesSubfolder: 'images',
7
8
  stylesSubfolder: 'styles',
@@ -17,7 +17,7 @@ const streamToDestination = (destPath, fileName) => {
17
17
  const url = `https://${defaultSettings.nodeEnv}/${resourcePath}/${fileName}`;
18
18
 
19
19
  return new Promise(resolve => {
20
- const folderPath = `${defaultSettings.srcFolder}/${destPath}`;
20
+ const folderPath = `${defaultSettings.publicFolder}/${destPath}`;
21
21
 
22
22
  if (!fs.existsSync(folderPath)) {
23
23
  fs.mkdirSync(folderPath, { recursive: true });
@@ -86,7 +86,7 @@ export default async function() {
86
86
  const destinationPath = '/resources/scripts/helpers/';
87
87
  const filesPromiseMap = helpers.map(async helper => {
88
88
  const fileName = helper;
89
- if (fs.existsSync(`${defaultSettings.srcFolder}/${destinationPath}/${fileName}`)) {
89
+ if (fs.existsSync(`${defaultSettings.publicFolder}/${destinationPath}/${fileName}`)) {
90
90
  return;
91
91
  }
92
92
  await streamToDestination(destinationPath, fileName);
@@ -160,12 +160,12 @@ function getResource(task, fileNames, resourcePath = 'quote/resources') {
160
160
  return new Promise(resolve => {
161
161
  const file = getFileFromURL(url);
162
162
 
163
- if (!fs.existsSync(`${task.config.defaultSettings.srcFolder}/resources/${config.dest}`)) {
164
- fs.mkdirSync(`${task.config.defaultSettings.srcFolder}/resources/${config.dest}`, { recursive: true });
163
+ if (!fs.existsSync(`${task.config.defaultSettings.publicFolder}/resources/${config.dest}`)) {
164
+ fs.mkdirSync(`${task.config.defaultSettings.publicFolder}/resources/${config.dest}`, { recursive: true });
165
165
  }
166
166
 
167
167
  // if file exists, do not create it again
168
- if (fs.existsSync(`${task.config.defaultSettings.srcFolder}/resources/${config.dest}/${file}`)) {
168
+ if (fs.existsSync(`${task.config.defaultSettings.publicFolder}/resources/${config.dest}/${file}`)) {
169
169
  resolve();
170
170
  } else {
171
171
  const options = {
@@ -178,14 +178,14 @@ function getResource(task, fileNames, resourcePath = 'quote/resources') {
178
178
  throw new Error(`${resp.status}: Error while fetching ${url}`);
179
179
  }
180
180
 
181
- const writer = createWriteStream(`${task.config.defaultSettings.srcFolder}/resources/${config.dest}/${file}`);
181
+ const writer = createWriteStream(`${task.config.defaultSettings.publicFolder}/resources/${config.dest}/${file}`);
182
182
  resp.data.pipe(writer);
183
- console.log(`${task.config.defaultSettings.srcFolder}/resources/${config.dest}/${file} created...`);
183
+ console.log(`${task.config.defaultSettings.publicFolder}/resources/${config.dest}/${file} created...`);
184
184
  return finished(writer);
185
185
  })
186
186
  .then(() => {
187
187
  return new Promise((resolve) => {
188
- gulp.src(`${task.config.defaultSettings.srcFolder}/resources/${config.dest}/${file}`)
188
+ gulp.src(`${task.config.defaultSettings.publicFolder}/resources/${config.dest}/${file}`)
189
189
  .pipe(hash({
190
190
  hashLength: 20,
191
191
  algorithm: 'md5',
@@ -196,12 +196,9 @@ function getResource(task, fileNames, resourcePath = 'quote/resources') {
196
196
  file = JSON.parse(file).history[1];
197
197
  file = file.split('/').pop();
198
198
  fileNames[task.config.fileName] = file;
199
-
200
- console.log(file);
201
199
  }))
202
- .pipe(gulp.dest(`${task.config.defaultSettings.srcFolder}/resources/${config.dest}`))
200
+ .pipe(gulp.dest(`${task.config.defaultSettings.publicFolder}/resources/${config.dest}`))
203
201
  .on('finish', function(){
204
- console.log('DONE HASHING');
205
202
  resolve();
206
203
  })
207
204
  });
@@ -228,11 +225,8 @@ function getResource(task, fileNames, resourcePath = 'quote/resources') {
228
225
 
229
226
  export default async function(config) {
230
227
  const { isLocal } = defaultSettings;
231
- const isQuotePage = config.siteData?.isQuotePage || config.isQuotePage;
232
228
  const useAccessibleComponents = config.useAccessibleConfig;
233
- const useRelativePathForResources = config.siteData?.useRelativePathForResources || config.useRelativePathForResources;
234
229
  componentFolderPath = useAccessibleComponents === true ? 'accessible-components' : 'shared-components';
235
- isQuotePageOrUseRelativePath = isQuotePage === true || useRelativePathForResources === true;
236
230
  const isPathSubdirectory = config.siteData?.pathSubdirectory || config.pathSubdirectory;
237
231
  pathSubdirectory = !isLocal && isPathSubdirectory ? isPathSubdirectory : '';
238
232
 
package/vite.config.js CHANGED
@@ -6,6 +6,8 @@ import { defineConfig } from 'vite'
6
6
  import { startModBuild } from './tasks/serve.js'
7
7
  import { updateConfig } from './src/scripts/utils.js'
8
8
  import { viteStaticCopy } from 'vite-plugin-static-copy'
9
+ import { glob } from 'glob'
10
+ import fs from "node:fs";
9
11
 
10
12
  export default defineConfig((config) => ({
11
13
  build: {
@@ -66,14 +68,22 @@ export default defineConfig((config) => ({
66
68
  },
67
69
  {
68
70
  name: 'replace-src-paths',
69
- transformIndexHtml: (html) => {
70
- if (config.pathSubdirectory && config.pathSubdirectory.length > 0) {
71
- return html
72
- .replace(/(src|data-load)="\/?src\//g, `$1="${config.pathSubdirectory}`)
73
- .replace(/(src|data-load|href)="\/?assets\//g, `$1="${config.pathSubdirectory}assets/`)
74
- .replace(/(src|data-load|href)="\/?resources\//g, `$1="${config.pathSubdirectory}resources/`)
75
- } else {
76
- return html.replace(/(src|data-load)="\/?src\//g, '$1="/');
71
+ writeBundle: async () => {
72
+ const files = glob.sync(defaultSettings.distFolder + '/**/index.html');
73
+ for (const file of files) {
74
+ let html = await fs.promises.readFile(file, 'utf-8');
75
+ let updatedHtml = '';
76
+
77
+ if (config.pathSubdirectory && config.pathSubdirectory.length > 0) {
78
+ updatedHtml = html
79
+ .replace(/(src|data-load)="\/?src\//g, `$1="${config.pathSubdirectory}`)
80
+ .replace(/(src|data-load|href)="\/?assets\//g, `$1="${config.pathSubdirectory}assets/`)
81
+ .replace(/(src|data-load|href)="\/?resources\//g, `$1="${config.pathSubdirectory}resources/`)
82
+ } else {
83
+ updatedHtml = html.replace(/(src|data-load)="\/?src\//g, '$1="/');
84
+ }
85
+
86
+ await fs.promises.writeFile(file, updatedHtml);
77
87
  }
78
88
  },
79
89
  apply: 'build',