mod-build 4.0.0-beta.5 → 4.0.1-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 +16 -0
- package/package.json +1 -1
- package/src/scripts/default/index.js +9 -0
- package/src/scripts/default/update-link-paths.js +7 -13
- package/src/scripts/default/use-dynamic-gtm.js +4 -5
- package/src/scripts/plugins.js +109 -0
- package/src/scripts/utils.js +12 -51
- package/tasks/templates.js +2 -2
- package/vite.config.js +3 -51
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
## 4.0.1
|
|
2
|
+
|
|
3
|
+
- Clean up some plugins into separate files
|
|
4
|
+
- Add footAssetsConfig to additionalAssets
|
|
5
|
+
|
|
6
|
+
## 4.0.0-beta.5
|
|
7
|
+
|
|
8
|
+
- Updated the `transformIndexHtml` hook to use the `writeBundle` hook in the ViteConfig.
|
|
9
|
+
- This change ensures that all assets are transformed before adding the `pathSubdirectory` to the assets and local resources.
|
|
10
|
+
|
|
11
|
+
- Updated the `grab-shared-scripts` task to run more sequentially.
|
|
12
|
+
- All files are now downloaded and hashed before going through the functions to replace local paths.
|
|
13
|
+
|
|
14
|
+
- Changed global resources to download to the site's `/public` folder instead of inside `/src`.
|
|
15
|
+
- This prevents Vite from bundling them during the build process as they are static JS files.
|
|
16
|
+
|
|
1
17
|
## 4.0.0-beta.3
|
|
2
18
|
|
|
3
19
|
- Add static default tcpa.json to list of shared resources to grab
|
package/package.json
CHANGED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { loadAdditionalAssets } from "./additional-assets.js";
|
|
2
|
+
import { useDynamicGtm } from './use-dynamic-gtm.js';
|
|
3
|
+
import { updateFooterLinkPaths } from "./update-link-paths.js";
|
|
4
|
+
|
|
5
|
+
export const globals = (config) => {
|
|
6
|
+
useDynamicGtm(config);
|
|
7
|
+
loadAdditionalAssets(config);
|
|
8
|
+
updateFooterLinkPaths();
|
|
9
|
+
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { observeMutations } from "../utils.js";
|
|
2
|
+
|
|
1
3
|
const updateFooterModalPaths = () => {
|
|
2
4
|
const footerModalLinks = document.querySelectorAll('.footer__links a');
|
|
3
5
|
footerModalLinks.forEach((link) => {
|
|
@@ -13,19 +15,11 @@ const updateFooterModalPaths = () => {
|
|
|
13
15
|
});
|
|
14
16
|
};
|
|
15
17
|
|
|
16
|
-
export const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
if (footerLinks) {
|
|
22
|
-
observer.disconnect();
|
|
23
|
-
updateFooterModalPaths();
|
|
24
|
-
break;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
18
|
+
export const updateFooterLinkPaths = () => {
|
|
19
|
+
observeMutations(document.body, () => {
|
|
20
|
+
const updatedFooterLinks = document.querySelector('.footer__links');
|
|
21
|
+
if (updatedFooterLinks) {
|
|
22
|
+
updateFooterModalPaths();
|
|
27
23
|
}
|
|
28
24
|
});
|
|
29
|
-
|
|
30
|
-
observer.observe(document.body, { childList: true, subtree: true });
|
|
31
25
|
};
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
|
|
2
2
|
export const useDynamicGtm = (config) => {
|
|
3
3
|
const { page } = config;
|
|
4
|
-
|
|
5
4
|
if (page.headConfig.useDynamicGtm || typeof window.isQSPage === 'undefined') {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
import('@/scripts/has-qs-params.js').then((qs) => {
|
|
6
|
+
qs.default();
|
|
7
|
+
window.gtm_container_ID = window.isQSPage ? config.qs_gtm_container_ID : config.gtm_container_ID;
|
|
8
|
+
});
|
|
10
9
|
}
|
|
11
10
|
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import { defaultSettings } from "../data/config.js";
|
|
3
|
+
import footer from '../data/footer.js';
|
|
4
|
+
import { handlebarsHelpers } from "./utils.js";
|
|
5
|
+
import gulpHandlebarsFileInclude from "gulp-handlebars-file-include";
|
|
6
|
+
import merge from "lodash.merge";
|
|
7
|
+
import { glob } from 'glob'
|
|
8
|
+
|
|
9
|
+
export const STATIC_COPY_TARGETS = [
|
|
10
|
+
{
|
|
11
|
+
src: './src/resources/templates',
|
|
12
|
+
dest: './resources/'
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
src: './src/fonts',
|
|
16
|
+
dest: './'
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
src: './src/videos',
|
|
20
|
+
dest: './'
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
src: './src/accessible-components/carousel/carousel.min.js',
|
|
24
|
+
dest: './accessible-components/carousel'
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
src: './src/accessible-components/expand-collapse/expand-collapse.min.js',
|
|
28
|
+
dest: './accessible-components/expand-collapse'
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
src: './src/accessible-components/progress-bar/progress-bar.min.js',
|
|
32
|
+
dest: './accessible-components/progress-bar'
|
|
33
|
+
},
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
export const updateConfig = async (config) => {
|
|
37
|
+
const { isLocal, nodeEnv, buildPath } = defaultSettings;
|
|
38
|
+
// eslint-disable-next-line no-unused-vars
|
|
39
|
+
let tempConfigExists;
|
|
40
|
+
|
|
41
|
+
let mergedConfig = {
|
|
42
|
+
...config,
|
|
43
|
+
...footer(config),
|
|
44
|
+
...{ isLocal, nodeEnv, buildPath }
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const checkForTempConfig = () => {
|
|
48
|
+
return new Promise((resolve) => {
|
|
49
|
+
tempConfigExists = fs.existsSync(`src/.tmp/config.json`);
|
|
50
|
+
|
|
51
|
+
const configData = fs.readFileSync('src/.tmp/config.json', 'utf8');
|
|
52
|
+
const parsedConfig = JSON.parse(configData);
|
|
53
|
+
mergedConfig = merge(parsedConfig, mergedConfig);
|
|
54
|
+
|
|
55
|
+
resolve();
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
name: 'update-config',
|
|
61
|
+
async configResolved({ configFileDependencies }) {
|
|
62
|
+
await checkForTempConfig();
|
|
63
|
+
|
|
64
|
+
configFileDependencies.forEach((file) => {
|
|
65
|
+
if (file.endsWith('siteconfig.js') || file.endsWith('template.js')) {
|
|
66
|
+
console.log('siteconfig or template changed');
|
|
67
|
+
try {
|
|
68
|
+
// overwrite the config file with new data
|
|
69
|
+
fs.writeFileSync('src/.tmp/config.json', JSON.stringify(mergedConfig, null, 2));
|
|
70
|
+
} catch (error) {
|
|
71
|
+
console.error(`Error reading config file: ${error}`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
},
|
|
76
|
+
configureServer() {
|
|
77
|
+
gulpHandlebarsFileInclude(mergedConfig, { handlebarsHelpers, maxRecursion: 500 });
|
|
78
|
+
},
|
|
79
|
+
buildStart() {
|
|
80
|
+
gulpHandlebarsFileInclude(mergedConfig, { handlebarsHelpers, maxRecursion: 500 });
|
|
81
|
+
fs.writeFileSync('src/.tmp/config.json', JSON.stringify(mergedConfig, null, 2));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export const replaceSrcPaths = (config) => {
|
|
87
|
+
return {
|
|
88
|
+
name: 'replace-src-paths',
|
|
89
|
+
writeBundle: async () => {
|
|
90
|
+
const files = glob.sync(defaultSettings.distFolder + '/**/index.html');
|
|
91
|
+
for (const file of files) {
|
|
92
|
+
let html = await fs.promises.readFile(file, 'utf-8');
|
|
93
|
+
let updatedHtml = '';
|
|
94
|
+
|
|
95
|
+
if (config.pathSubdirectory && config.pathSubdirectory.length > 0) {
|
|
96
|
+
updatedHtml = html
|
|
97
|
+
.replace(/(src|data-load)="\/?src\//g, `$1="${config.pathSubdirectory}`)
|
|
98
|
+
.replace(/(src|srcset|data-load|href)="\/?assets\//g, `$1="${config.pathSubdirectory}assets/`)
|
|
99
|
+
.replace(/(src|data-load|href)="\/?resources\//g, `$1="${config.pathSubdirectory}resources/`)
|
|
100
|
+
} else {
|
|
101
|
+
updatedHtml = html.replace(/(src|data-load)="\/?src\//g, '$1="/');
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
await fs.promises.writeFile(file, updatedHtml);
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
apply: 'build',
|
|
108
|
+
}
|
|
109
|
+
}
|
package/src/scripts/utils.js
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
1
|
import { seasons } from "../data/seasons.js";
|
|
3
|
-
import { defaultSettings } from "../data/config.js";
|
|
4
|
-
import footer from '../data/footer.js';
|
|
5
2
|
import gulpHandlebarsFileInclude from "gulp-handlebars-file-include";
|
|
6
|
-
import merge from "lodash.merge";
|
|
7
3
|
|
|
8
4
|
export function getFileFromURL(url) {
|
|
9
5
|
return url.split('/').pop();
|
|
@@ -171,51 +167,16 @@ export const handlebarsHelpers = [
|
|
|
171
167
|
}
|
|
172
168
|
]
|
|
173
169
|
|
|
174
|
-
export const
|
|
175
|
-
const
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
};
|
|
183
|
-
|
|
184
|
-
const checkForTempConfig = () => {
|
|
185
|
-
return new Promise((resolve) => {
|
|
186
|
-
tempConfigExists = fs.existsSync(`src/.tmp/config.json`);
|
|
187
|
-
|
|
188
|
-
const configData = fs.readFileSync('src/.tmp/config.json', 'utf8');
|
|
189
|
-
const parsedConfig = JSON.parse(configData);
|
|
190
|
-
mergedConfig = merge(parsedConfig, mergedConfig);
|
|
191
|
-
|
|
192
|
-
resolve();
|
|
193
|
-
});
|
|
194
|
-
};
|
|
195
|
-
|
|
196
|
-
return {
|
|
197
|
-
name: 'update-config',
|
|
198
|
-
async configResolved({ configFileDependencies }) {
|
|
199
|
-
await checkForTempConfig();
|
|
200
|
-
|
|
201
|
-
configFileDependencies.forEach((file) => {
|
|
202
|
-
if (file.endsWith('siteconfig.js') || file.endsWith('template.js')) {
|
|
203
|
-
console.log('siteconfig or template changed');
|
|
204
|
-
try {
|
|
205
|
-
// overwrite the config file with new data
|
|
206
|
-
fs.writeFileSync('src/.tmp/config.json', JSON.stringify(mergedConfig, null, 2));
|
|
207
|
-
} catch (error) {
|
|
208
|
-
console.error(`Error reading config file: ${error}`);
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
});
|
|
212
|
-
},
|
|
213
|
-
configureServer() {
|
|
214
|
-
gulpHandlebarsFileInclude(mergedConfig, { handlebarsHelpers, maxRecursion: 500 });
|
|
215
|
-
},
|
|
216
|
-
buildStart() {
|
|
217
|
-
gulpHandlebarsFileInclude(mergedConfig, { handlebarsHelpers, maxRecursion: 500 });
|
|
218
|
-
fs.writeFileSync('src/.tmp/config.json', JSON.stringify(mergedConfig, null, 2));
|
|
170
|
+
export const observeMutations = (target, callback) => {
|
|
171
|
+
const observer = new MutationObserver((mutationsList) => {
|
|
172
|
+
for (const mutation of mutationsList) {
|
|
173
|
+
if (mutation.type === 'childList') {
|
|
174
|
+
callback();
|
|
175
|
+
observer.disconnect();
|
|
176
|
+
break;
|
|
177
|
+
}
|
|
219
178
|
}
|
|
220
|
-
}
|
|
221
|
-
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
observer.observe(target, { childList: true, subtree: true });
|
|
182
|
+
};
|
package/tasks/templates.js
CHANGED
|
@@ -81,7 +81,7 @@ const fetchTcpaFromSitegenie = async (config, tempConfig) => {
|
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
console.log('Starting fetch-tcpa-from-sitegenie: ', url);
|
|
84
|
-
return new Promise((resolve
|
|
84
|
+
return new Promise((resolve) => {
|
|
85
85
|
axios(options)
|
|
86
86
|
.then(async resp => {
|
|
87
87
|
if (resp.status !== 200) {
|
|
@@ -104,7 +104,7 @@ const fetchTcpaFromSitegenie = async (config, tempConfig) => {
|
|
|
104
104
|
console.log('Response error...using default TCPA language');
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
-
defaultTcpa = JSON.parse(fs.readFileSync('src/resources/data/tcpa.json', 'utf8'));
|
|
107
|
+
let defaultTcpa = JSON.parse(fs.readFileSync('src/resources/data/tcpa.json', 'utf8'));
|
|
108
108
|
tempConfig.tcpaText = defaultTcpa.tcpaText;
|
|
109
109
|
resolve(error);
|
|
110
110
|
});
|
package/vite.config.js
CHANGED
|
@@ -4,10 +4,8 @@ import eslint from 'vite-plugin-eslint'
|
|
|
4
4
|
import { defaultSettings } from './src/data/config.js'
|
|
5
5
|
import { defineConfig } from 'vite'
|
|
6
6
|
import { startModBuild } from './tasks/serve.js'
|
|
7
|
-
import { updateConfig } from './src/scripts/
|
|
7
|
+
import { updateConfig, replaceSrcPaths, STATIC_COPY_TARGETS } from './src/scripts/plugins.js'
|
|
8
8
|
import { viteStaticCopy } from 'vite-plugin-static-copy'
|
|
9
|
-
import { glob } from 'glob'
|
|
10
|
-
import fs from "node:fs";
|
|
11
9
|
|
|
12
10
|
export default defineConfig((config) => ({
|
|
13
11
|
build: {
|
|
@@ -27,32 +25,7 @@ export default defineConfig((config) => ({
|
|
|
27
25
|
}),
|
|
28
26
|
updateConfig(config),
|
|
29
27
|
viteStaticCopy({
|
|
30
|
-
targets:
|
|
31
|
-
{
|
|
32
|
-
src: './src/resources',
|
|
33
|
-
dest: './'
|
|
34
|
-
},
|
|
35
|
-
{
|
|
36
|
-
src: './src/fonts',
|
|
37
|
-
dest: './'
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
src: './src/videos',
|
|
41
|
-
dest: './'
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
src: './src/accessible-components/carousel/carousel.min.js',
|
|
45
|
-
dest: './accessible-components/carousel'
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
src: './src/accessible-components/expand-collapse/expand-collapse.min.js',
|
|
49
|
-
dest: './accessible-components/expand-collapse'
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
src: './src/accessible-components/progress-bar/progress-bar.min.js',
|
|
53
|
-
dest: './accessible-components/progress-bar'
|
|
54
|
-
},
|
|
55
|
-
],
|
|
28
|
+
targets: STATIC_COPY_TARGETS,
|
|
56
29
|
}),
|
|
57
30
|
{
|
|
58
31
|
...eslint(),
|
|
@@ -66,28 +39,7 @@ export default defineConfig((config) => ({
|
|
|
66
39
|
apply: 'serve',
|
|
67
40
|
enforce: 'post'
|
|
68
41
|
},
|
|
69
|
-
|
|
70
|
-
name: 'replace-src-paths',
|
|
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);
|
|
87
|
-
}
|
|
88
|
-
},
|
|
89
|
-
apply: 'build',
|
|
90
|
-
}
|
|
42
|
+
replaceSrcPaths(config),
|
|
91
43
|
],
|
|
92
44
|
define: {
|
|
93
45
|
'process.env': process.env
|