-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite-module-loader.js
39 lines (30 loc) · 1.15 KB
/
vite-module-loader.js
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
36
37
38
39
import fs from 'fs/promises';
import path from 'path';
async function collectModuleAssetsPaths(paths, modulesPath) {
modulesPath = path.join(__dirname, modulesPath);
const moduleStatusesPath = path.join(__dirname, 'modules_statuses.json');
try {
const moduleStatusesContent = await fs.readFile(moduleStatusesPath, 'utf-8');
const moduleStatuses = JSON.parse(moduleStatusesContent);
const moduleDirectories = await fs.readdir(modulesPath);
for (const moduleDir of moduleDirectories) {
if (moduleDir === '.DS_Store') {
continue;
}
if (moduleStatuses[moduleDir] === true) {
const viteConfigPath = path.join(modulesPath, moduleDir, 'vite.config.js');
const stat = await fs.stat(viteConfigPath);
if (stat.isFile()) {
const moduleConfig = await import(viteConfigPath);
if (moduleConfig.paths && Array.isArray(moduleConfig.paths)) {
paths.push(...moduleConfig.paths);
}
}
}
}
} catch (error) {
console.error(`Error reading module statuses or module configurations: ${error}`);
}
return paths;
}
export default collectModuleAssetsPaths;