spee.ch/build/utils/importSubModules.js
2018-03-21 17:35:51 -07:00

22 lines
608 B
JavaScript

const { lstatSync, readdirSync } = require('fs');
const { join } = require('path');
const getSubDirectoryNames = (root) => {
console.log('getting sub directories for:', root);
return readdirSync(root)
.filter(name => {
console.log('module found:', name);
let fullPath = join(root, name);
return lstatSync(fullPath).isDirectory();
});
};
module.exports = (root) => {
let allModules = {};
getSubDirectoryNames(root)
.forEach((name) => {
console.log('importing module:', name);
allModules[name] = require(`./${name}`).default;
});
return allModules;
};