Created
December 31, 2021 17:26
-
-
Save ceelsoin/9556cc04d6b075ed7fd87f5dc7c3f89b to your computer and use it in GitHub Desktop.
Dynamic controller import inversify-express-utils
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require('path'); | |
const loadHandlers = () => { | |
return new Promise(async (resolve, reject) => { | |
const fs = require('fs'); | |
const dir = path.join(process.cwd(), process.env.NODE_ENV != 'production' ? 'src' : '','/Presentation/Handlers') | |
log(LogLevelEnum.INFO, `Loading controllers from ${dir}`) | |
await fs.readdir(dir, async (err, files) => { | |
let reducers = files.filter(a => a.includes('.')); | |
let references = []; | |
reducers.forEach(reducer => { | |
references.push(reducer); | |
}); | |
await references.map(async (ref) => { | |
console.log(path.join(dir, ref)) | |
await import(path.join(dir, ref)) | |
}) | |
console.log(Object.keys(require('module')._cache).filter(a => !a.includes('node_modules'))) | |
resolve(true) | |
}); | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment