-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
45 lines (33 loc) · 1.16 KB
/
index.ts
File metadata and controls
45 lines (33 loc) · 1.16 KB
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
41
42
43
44
45
import fs from 'node:fs'
import PLUGIN_ID from '#gc.id';
import { Path, Logger, Config, ensurePathExists } from '#gc';
const apps = await (async () => {
await ensurePathExists();
Logger.info(`[${PLUGIN_ID}] Loading apps...`);
let ret = [];
const files = fs
.readdirSync(Path.App)
.filter(file => file.endsWith('.js'));
Config.load();
files.forEach((file) => {
Logger.info(`[${PLUGIN_ID}] App: ${file} <- ${Path.App}/${file}`);
ret.push(import(`file://${Path.App}/${file}`));
});
ret = await Promise.allSettled(ret);
let apps = {};
for (let i in files) {
let name = files[i].replace('.js', '');
if (ret[i].status !== 'fulfilled') {
Logger.error(`[${PLUGIN_ID}] Failed to load app ${name}`);
console.error(ret[i].reason?.stack || ret[i].reason);
continue;
}
if (ret[i].value) {
apps[name] = ret[i].value.default || Object.values(ret[i].value)[0];
} else {
Logger.warn(`[${PLUGIN_ID}] app [${name}] loaded but no export found.`);
}
}
return apps;
}) ();
export { apps };