1 |
|
2 | const path = require('path');
|
3 | const logger = require('./utils/logger');
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | global.getLogger = function (category = '') {
|
10 | const channel = category.replace(share.APP_PATH, '').replace('.js', '').trim();
|
11 | return logger.getLogger(channel.split(path.sep).filter(item => !!item).join('.'));
|
12 | };
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | global.getController = function (name) {
|
19 |
|
20 | const controllerPath = name || `${share.FRAMEWORK_PATH}lib${path.sep}base${path.sep}controller`;
|
21 | return require(controllerPath) || null;
|
22 | };
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 | global.getWebsocketHandler = function (name) {
|
29 |
|
30 | const websocketPath = name || `${share.FRAMEWORK_PATH}lib${path.sep}base${path.sep}websocket`;
|
31 | return require(websocketPath) || null;
|
32 | };
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 | global.getValidate = function (name) {
|
39 |
|
40 | const validatePath = name || `${share.FRAMEWORK_PATH}lib${path.sep}base${path.sep}validate`;
|
41 | return require(validatePath) || null;
|
42 | };
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 | global.getService = function (name) {
|
49 | if (name) {
|
50 | const modelPath = `${share.APP_PATH}app${path.sep}service${path.sep}${name}`;
|
51 | const Service = require(modelPath);
|
52 | return new Service(name);
|
53 | }
|
54 | return require(`${share.FRAMEWORK_PATH}lib${path.sep}base${path.sep}service`) || null;
|
55 | };
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 | global.getModel = function (name, anotherName) {
|
63 | if (name) {
|
64 | const modelPath = `${share.APP_PATH}app${path.sep}model${path.sep}${name}`;
|
65 | const Model = require(modelPath);
|
66 | return new Model(name, anotherName);
|
67 | }
|
68 | return require(`${share.FRAMEWORK_PATH}lib${path.sep}base${path.sep}model`) || null;
|
69 | };
|