-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateJsAssets-v3.js
More file actions
35 lines (28 loc) · 1018 Bytes
/
createJsAssets-v3.js
File metadata and controls
35 lines (28 loc) · 1018 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const fs = require('fs');
const path = require('path');
const {globSync} = require('glob');
const dynamicEntryPoints = globSync(`./components/block-*/*-v{3,4}.js`).map(
(filePath) => {
const assetKey = path.basename(filePath, '.js');
return assetKey;
}
);
const assetArray = dynamicEntryPoints.map((entry) => {
return {assetKey: entry};
});
// Create the directory path for the target file
const jsModulePath = path.join('./public');
const jsAssetsFilePath = path.join(jsModulePath, 'jsAssets.mjs');
// Create directories if they don't exist
fs.mkdirSync(jsModulePath, {recursive: true});
// Write the initial content to the target file
fs.writeFileSync(jsAssetsFilePath, '// This file is auto-generated.\n');
// Create directories if they don't exist
const dirPath = path.dirname(jsAssetsFilePath);
fs.mkdirSync(dirPath, {recursive: true});
const data = `
const dynamicAssets = ${JSON.stringify(assetArray)};
const api = {dynamicAssets};
export default api;
`;
fs.writeFileSync(jsAssetsFilePath, data);