2021-12-12 14:51:29 +00:00
|
|
|
const { readdirSync } = require('fs');
|
|
|
|
const { join } = require('path');
|
|
|
|
const NodeModule = require('module');
|
|
|
|
|
|
|
|
const paths = require('../paths');
|
2021-12-12 14:41:15 +00:00
|
|
|
|
|
|
|
|
2021-12-12 22:45:58 +00:00
|
|
|
module.exports = (moduleName) => { // If undefined, load all
|
2021-12-12 14:51:29 +00:00
|
|
|
const modulesDir = join(paths.getExeDir(), 'modules');
|
2021-12-12 22:45:58 +00:00
|
|
|
const moduleDirs = readdirSync(modulesDir);
|
2021-12-12 14:51:29 +00:00
|
|
|
|
2021-12-12 22:45:58 +00:00
|
|
|
if (moduleName) {
|
|
|
|
const moduleCoreDir = moduleDirs.find((x) => x.startsWith(moduleName + '-')); // Find desktop core dir by name
|
|
|
|
|
|
|
|
return NodeModule.globalPaths.push(join(modulesDir, moduleCoreDir)); // Add to globalPaths for requiring
|
|
|
|
}
|
|
|
|
|
|
|
|
// Undefined moduleName, load all
|
|
|
|
for (const dir of moduleDirs) {
|
|
|
|
NodeModule.globalPaths.push(join(modulesDir, dir));
|
|
|
|
}
|
2021-12-12 14:41:15 +00:00
|
|
|
};
|