UNPKG

931 BJavaScriptView Raw
1'use strict';
2
3const path = require('path');
4
5module.exports = function addCoreModulesToApp(app, options) {
6 // Load modules list from configuration dot-rc file.
7 const moduleConfig = app.config.registerConfig('modules', null, () => {
8 // Ignore the old config, write what is currently used.
9 return (
10 app.modules
11 // Do not save built-in modules.
12 .filter(mod => app.builtInModules.indexOf(mod) === -1)
13 // Output module paths.
14 .map(mod => mod.getInfo().path)
15 );
16 });
17
18 // Load the core module and hide it from listing.
19 const coreModule = app.enableBuiltInModule(
20 path.join(__dirname, 'modules', 'core'),
21 app,
22 options
23 );
24 coreModule.hidden = true;
25
26 // Load modules from configuration dot-rc file.
27 (Array.isArray(moduleConfig) ? moduleConfig : []).map(modulePath => {
28 try {
29 app.enableModule(modulePath);
30 } catch (err) {
31 app.error(path.basename(modulePath) + ' modulefail', err);
32 }
33 });
34};