-
Notifications
You must be signed in to change notification settings - Fork 1
/
Loader.js
62 lines (54 loc) · 1.9 KB
/
Loader.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
'use strict'
const fs = require('fs');
const path = require('path');
const basename = path.basename(module.filename);
class Loader {
static loadAll(app) {
Loader.loadModels();
Loader.loadRoutes(app);
// Loader.loadSeeders();
}
static loadRoutes(app) {
let baseDir = (__dirname + '/src/main/rotas');
fs
.readdirSync(path.join(baseDir))
.filter(function (file) {
return (file.indexOf('.') !== 0) && (file !== basename) && (file.slice(-3) === '.js');
})
.forEach(function (file) {
global.logger.info(`Carregando rotas: ${file}`)
let route = require((path.join(baseDir, file)));
new route(app);
});
}
static loadModels() {
let baseDir = (__dirname + '/src/main/modelos');
fs
.readdirSync(baseDir)
.filter(function (file) {
return (file.indexOf('.') !== 0) && (file !== basename) && (file.slice(-3) === '.js');
})
.forEach(function (file) {
global.logger.info(`Carregando modelos: ${file}`);
let model = require((path.join(baseDir, file)));
new model();
});
}
// static loadSeeders() {
// let baseDir = (__dirname + '/src/main/seeders');
// fs
// .readdirSync(baseDir)
// .filter(function (file) {
// return (file.indexOf('.') !== 0) && (file !== basename) && (file.slice(-3) === '.js');
// })
// .forEach(function (file) {
// if (file !== 'index.js') {
// return
// }
// global.logger.info(`Carregando seeders: ${file}`);
// let seeder = require((path.join(baseDir, file)));
// seeder();
// });
// }
}
module.exports = Loader;