-
Notifications
You must be signed in to change notification settings - Fork 1
/
injector.js
32 lines (26 loc) · 892 Bytes
/
injector.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Copyright (c) 2020 Anastasiia Birillo
const APP_DIR = require('path').dirname(require.main.filename);
const objectType = {
MODELS: {
configPath: `${APP_DIR}/configs/injection-configs/models`,
filePath: `${APP_DIR}/models`
},
ROUTERS: {
configPath: `${APP_DIR}/configs/injection-configs/routers`,
filePath: `${APP_DIR}/routers`
}
};
const injectModels = () => {
const modelsConfig = require(objectType.MODELS.configPath);
for (const model of modelsConfig)
require(`${objectType.MODELS.filePath}/${model.path}`);
};
const injectRouters = (app, injector, agent) => {
const routersConfig = require(objectType.ROUTERS.configPath);
for (const router of routersConfig)
require(`${objectType.ROUTERS.filePath}/${router.path}`)(app, injector, agent);
};
module.exports = {
injectModels,
injectRouters
};