-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathloader.ts
29 lines (26 loc) · 877 Bytes
/
loader.ts
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
import * as fs from 'fs/promises';
import * as path from 'path';
import { flatten } from 'lodash';
import { interfaces } from 'inversify';
import { TYPES } from '@vulcan/core/containers';
export const importExtensions = async (folder: string) => {
const extensions = await import(folder);
return extensions.default || [];
};
export const bindExtensions = async (bind: interfaces.Bind) => {
const builtInExtensionNames = (
await fs.readdir(path.join(__dirname, '..', 'built-in-extensions'))
).filter((name) => name !== 'index.ts');
const extensions = flatten(
await Promise.all(
builtInExtensionNames.map((name) =>
importExtensions(
path.join(__dirname, '..', 'built-in-extensions', name)
)
)
)
);
extensions.forEach((extension) => {
bind(TYPES.CompilerExtension).to(extension).inSingletonScope();
});
};