-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodules.js
More file actions
40 lines (32 loc) · 948 Bytes
/
modules.js
File metadata and controls
40 lines (32 loc) · 948 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
36
37
38
39
40
import fs from 'fs'
import path from 'path'
import { fileURLToPath } from 'url'
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
// Path to modules.json
const registryPath = path.join(__dirname, 'modules.json')
// Load module list
const moduleNames = JSON.parse(fs.readFileSync(registryPath, 'utf8'))
// Resolve each module into a usable object
export function loadModules() {
const modules = {}
for (const name of moduleNames) {
const moduleDir = path.join(__dirname, 'modules', name)
const entry = path.join(moduleDir, 'index.js')
try {
// Dynamically import the module
const mod = fs.existsSync(entry)
? import(entry)
: null
modules[name] = {
name,
path: moduleDir,
entry,
loader: mod
}
} catch (err) {
console.error(`Failed to load module "${name}":`, err.message)
}
}
return modules
}