mod-build 4.0.0-alpha.12 → 4.0.0-alpha.14

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-alpha.12",
3
+ "version": "4.0.0-alpha.14",
4
4
  "description": "Share components for S3 sites.",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -1,3 +1,5 @@
1
+ import fs from "node:fs";
2
+ import merge from "lodash.merge";
1
3
  import { seasons } from "../data/seasons.js";
2
4
  import gulpHandlebarsFileInclude from "gulp-handlebars-file-include";
3
5
 
@@ -165,4 +167,26 @@ export const handlebarsHelpers = [
165
167
  return gulpHandlebarsFileInclude(input);
166
168
  }
167
169
  }
168
- ]
170
+ ]
171
+
172
+ export const updateConfig = (config) => {
173
+ return {
174
+ name: 'update-config',
175
+ configResolved({ configFileDependencies }) {
176
+ configFileDependencies.forEach((file) => {
177
+ if (file.endsWith('siteconfig.js') || file.endsWith('template.js')) {
178
+ console.log('siteconfig or template changed');
179
+ try {
180
+ const tempConfig = config;
181
+ const configData = fs.readFileSync('src/.tmp/config.json', 'utf8');
182
+ const parsedConfig = JSON.parse(configData);
183
+ // overwrite the config file with new data
184
+ fs.writeFileSync('src/.tmp/config.json', JSON.stringify(merge(parsedConfig, tempConfig), null, 2));
185
+ } catch (error) {
186
+ console.error(`Error reading config file: ${error}`);
187
+ }
188
+ }
189
+ });
190
+ }
191
+ }
192
+ }
@@ -86,6 +86,9 @@ 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}`)) {
90
+ return;
91
+ }
89
92
  await streamToDestination(destinationPath, fileName);
90
93
  });
91
94
 
package/vite.config.js CHANGED
@@ -3,7 +3,7 @@ import vituum from 'vituum'
3
3
  import { defaultSettings } from './src/data/config.js'
4
4
  import { defineConfig } from 'vite'
5
5
  import { startModBuild } from './tasks/serve.js'
6
- import { handlebarsHelpers } from './src/scripts/utils.js'
6
+ import { handlebarsHelpers, updateConfig } from './src/scripts/utils.js'
7
7
  import gulpHandlebarsFileInclude from 'gulp-handlebars-file-include'
8
8
  import eslint from 'vite-plugin-eslint'
9
9
 
@@ -16,7 +16,7 @@ export default defineConfig((config) => ({
16
16
  startModBuild(config),
17
17
  vituum(),
18
18
  handlebars({
19
- data: ['src/**/*.json'],
19
+ data: ['src/.tmp/config.json'],
20
20
  formats: ['json', 'html', 'hbs'],
21
21
  globals: config,
22
22
  partials: {
@@ -24,6 +24,7 @@ export default defineConfig((config) => ({
24
24
  }
25
25
  }),
26
26
  gulpHandlebarsFileInclude({}, { handlebarsHelpers, maxRecursion: 500 }),
27
+ updateConfig(config),
27
28
  {
28
29
  ...eslint(),
29
30
  apply: 'build',