UNPKG

936 BJavaScriptView Raw
1import path from 'path';
2import { fileURLToPath } from 'url';
3
4const __filename = fileURLToPath(import.meta.url);
5const __dirname = path.dirname(__filename);
6
7export default async function addCoreModulesToApp(app, options) {
8 // Load modules list from configuration dot-rc file.
9 const moduleConfig = app.config.registerConfig('modules', []);
10
11 // Load the core module and hide it from listing.
12 const coreModule = await app.enableBuiltInModule(
13 path.join(__dirname, 'modules', 'core'),
14 app,
15 options
16 );
17 coreModule.hidden = true;
18
19 // Load modules from configuration dot-rc file.
20 (Array.isArray(moduleConfig) ? moduleConfig : []).map((modulePath) => {
21 try {
22 // Resolve potentially relative module paths defined in the dot-rc file.
23 modulePath = path.resolve(app.config.getLocation(), modulePath);
24 app.enableModule(modulePath);
25 } catch (err) {
26 app.error(`${path.basename(modulePath)} modulefail`, err);
27 }
28 });
29}