-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodules.json
More file actions
35 lines (28 loc) · 820 Bytes
/
modules.json
File metadata and controls
35 lines (28 loc) · 820 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
import fs from 'fs'
import path from 'path'
import { fileURLToPath } from 'url'
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const registryPath = path.join(__dirname, 'modules.json')
const moduleNames = JSON.parse(fs.readFileSync(registryPath, 'utf8'))
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 {
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
}