mod-build 4.0.1 → 4.0.2
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 +1 -1
- package/src/scripts/plugins.js +49 -26
package/package.json
CHANGED
package/src/scripts/plugins.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
|
-
import mergeWith from "lodash.mergewith";
|
|
3
2
|
import merge from "lodash.merge";
|
|
4
3
|
import gulpHandlebarsFileInclude from "gulp-handlebars-file-include";
|
|
5
4
|
import { defaultSettings } from "../data/config.js";
|
|
@@ -33,21 +32,10 @@ export const STATIC_COPY_TARGETS = [
|
|
|
33
32
|
},
|
|
34
33
|
];
|
|
35
34
|
|
|
36
|
-
|
|
37
|
-
let tempConfigExists;
|
|
38
|
-
|
|
39
|
-
const customizer = (objValue, srcValue) => {
|
|
40
|
-
// If the key exists in parsedConfig but not in mergedConfig, drop it from the merged result
|
|
41
|
-
if (srcValue === undefined) {
|
|
42
|
-
return undefined;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// Otherwise, use the default merging behavior
|
|
46
|
-
return merge(objValue, srcValue); // or you can return merge(objValue, srcValue) to merge nested objects
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
const checkForTempConfig = (config) => {
|
|
35
|
+
export const updateConfig = async (config) => {
|
|
50
36
|
const { isLocal, nodeEnv, buildPath } = defaultSettings;
|
|
37
|
+
// eslint-disable-next-line no-unused-vars
|
|
38
|
+
let tempConfigExists;
|
|
51
39
|
|
|
52
40
|
let mergedConfig = {
|
|
53
41
|
...config,
|
|
@@ -55,23 +43,23 @@ const checkForTempConfig = (config) => {
|
|
|
55
43
|
...{ isLocal, nodeEnv, buildPath }
|
|
56
44
|
};
|
|
57
45
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
46
|
+
const checkForTempConfig = () => {
|
|
47
|
+
return new Promise((resolve) => {
|
|
48
|
+
tempConfigExists = fs.existsSync(`src/.tmp/config.json`);
|
|
49
|
+
|
|
61
50
|
const configData = fs.readFileSync('src/.tmp/config.json', 'utf8');
|
|
62
51
|
const parsedConfig = JSON.parse(configData);
|
|
63
|
-
mergedConfig =
|
|
64
|
-
}
|
|
65
|
-
resolve(mergedConfig);
|
|
66
|
-
});
|
|
67
|
-
};
|
|
52
|
+
mergedConfig = merge(parsedConfig, mergedConfig);
|
|
68
53
|
|
|
69
|
-
|
|
70
|
-
|
|
54
|
+
resolve();
|
|
55
|
+
});
|
|
56
|
+
};
|
|
71
57
|
|
|
72
58
|
return {
|
|
73
59
|
name: 'update-config',
|
|
74
60
|
async configResolved({ configFileDependencies }) {
|
|
61
|
+
await checkForTempConfig();
|
|
62
|
+
|
|
75
63
|
configFileDependencies.forEach((file) => {
|
|
76
64
|
if (file.endsWith('siteconfig.js') || file.endsWith('template.js')) {
|
|
77
65
|
console.log('siteconfig or template changed');
|
|
@@ -94,11 +82,46 @@ export const updateConfig = async (config) => {
|
|
|
94
82
|
}
|
|
95
83
|
|
|
96
84
|
export const updateHandlebarsOnWatch = async (config) => {
|
|
97
|
-
const
|
|
85
|
+
const { isLocal, nodeEnv, buildPath } = defaultSettings;
|
|
86
|
+
// eslint-disable-next-line no-unused-vars
|
|
87
|
+
let tempConfigExists;
|
|
88
|
+
|
|
89
|
+
let mergedConfig = {
|
|
90
|
+
...config,
|
|
91
|
+
...footer(config),
|
|
92
|
+
...{ isLocal, nodeEnv, buildPath }
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const checkForTempConfig = () => {
|
|
96
|
+
return new Promise((resolve) => {
|
|
97
|
+
tempConfigExists = fs.existsSync(`src/.tmp/config.json`);
|
|
98
|
+
|
|
99
|
+
const configData = fs.readFileSync('src/.tmp/config.json', 'utf8');
|
|
100
|
+
const parsedConfig = JSON.parse(configData);
|
|
101
|
+
mergedConfig = merge(parsedConfig, mergedConfig);
|
|
102
|
+
|
|
103
|
+
resolve();
|
|
104
|
+
});
|
|
105
|
+
};
|
|
98
106
|
|
|
99
107
|
return {
|
|
100
108
|
name: 'update-handlebars-reload',
|
|
101
109
|
enforce: 'pre',
|
|
110
|
+
async configResolved({ configFileDependencies }) {
|
|
111
|
+
await checkForTempConfig();
|
|
112
|
+
|
|
113
|
+
configFileDependencies.forEach((file) => {
|
|
114
|
+
if (file.endsWith('siteconfig.js') || file.endsWith('template.js')) {
|
|
115
|
+
console.log('siteconfig or template changed');
|
|
116
|
+
try {
|
|
117
|
+
// overwrite the config file with new data
|
|
118
|
+
fs.writeFileSync('src/.tmp/config.json', JSON.stringify(mergedConfig, null, 2));
|
|
119
|
+
} catch (error) {
|
|
120
|
+
console.error(`Error reading config file: ${error}`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
},
|
|
102
125
|
async handleHotUpdate({ server, file }) {
|
|
103
126
|
if (file.endsWith('.hbs') || file.endsWith('.html')) {
|
|
104
127
|
server.ws.send({
|