@fastcar/core 0.2.63 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -2
- package/annotation.d.ts +3 -0
- package/index.d.ts +57 -50
- package/package.json +4 -4
- package/src/FastCarApplication.ts +184 -123
- package/src/annotation/Application.ts +3 -1
- package/src/annotation/bind/AddInjectionService.ts +17 -0
- package/src/annotation/bind/AddRequireModule.ts +1 -1
- package/src/annotation/bind/AliasInjection.ts +8 -15
- package/src/annotation/bind/Autowired.ts +1 -1
- package/src/annotation/bind/CallDependency.ts +7 -17
- package/src/annotation/bind/DemandInjection.ts +16 -0
- package/src/annotation/stereotype/Log.ts +13 -9
- package/src/annotation/stereotype/Value.ts +5 -0
- package/src/annotation.ts +2 -0
- package/src/constant/FastCarMetaData.ts +2 -0
- package/src/model/WinstonLogger.ts +1 -1
- package/src/type/ClassConstructor.ts +5 -0
- package/src/type/ComponentDesc.ts +13 -0
- package/src/type/FileHotterDesc.ts +6 -0
- package/src/utils/ClassLoader.ts +2 -1
- package/src/utils/ValidationUtil.ts +1 -1
- package/target/FastCarApplication.js +764 -708
- package/target/annotation/Application.js +46 -45
- package/target/annotation/ExceptionMonitor.js +16 -16
- package/target/annotation/bind/AddInjectionService.js +16 -0
- package/target/annotation/bind/AddRequireModule.js +21 -21
- package/target/annotation/bind/AliasInjection.js +19 -23
- package/target/annotation/bind/Autowired.js +13 -13
- package/target/annotation/bind/CallDependency.js +16 -23
- package/target/annotation/bind/DemandInjection.js +15 -0
- package/target/annotation/data/DBType.js +11 -11
- package/target/annotation/data/DS.js +54 -54
- package/target/annotation/data/DSIndex.js +9 -9
- package/target/annotation/data/Entity.js +10 -10
- package/target/annotation/data/Field.js +18 -18
- package/target/annotation/data/PrimaryKey.js +9 -9
- package/target/annotation/data/SqlSession.js +9 -9
- package/target/annotation/data/Table.js +35 -35
- package/target/annotation/data/Transactional.js +52 -52
- package/target/annotation/env/ApplicationSetting.js +25 -25
- package/target/annotation/env/BaseFilePath.js +14 -14
- package/target/annotation/env/BaseName.js +9 -9
- package/target/annotation/env/BasePath.js +14 -14
- package/target/annotation/env/ENV.js +10 -10
- package/target/annotation/env/ResourcePath.js +9 -9
- package/target/annotation/lifeCycle/AddLifeCycleItem.js +17 -18
- package/target/annotation/lifeCycle/ApplicationDestory.js +15 -15
- package/target/annotation/lifeCycle/ApplicationInit.js +15 -15
- package/target/annotation/lifeCycle/ApplicationRunner.js +7 -7
- package/target/annotation/lifeCycle/ApplicationStart.js +24 -24
- package/target/annotation/lifeCycle/ApplicationStop.js +20 -20
- package/target/annotation/property/Deprecate.js +19 -19
- package/target/annotation/property/NotImplemented.js +8 -8
- package/target/annotation/property/Override.js +7 -7
- package/target/annotation/property/Readonly.js +16 -16
- package/target/annotation/scan/ComponentInjection.js +21 -21
- package/target/annotation/scan/ComponentScan.js +9 -9
- package/target/annotation/scan/ComponentScanExclusion.js +25 -25
- package/target/annotation/scan/ComponentScanMust.js +25 -25
- package/target/annotation/scan/Hotter.js +8 -8
- package/target/annotation/stereotype/BeanName.js +11 -11
- package/target/annotation/stereotype/Component.js +8 -8
- package/target/annotation/stereotype/Configure.js +14 -14
- package/target/annotation/stereotype/Controller.js +9 -9
- package/target/annotation/stereotype/Injection.js +12 -12
- package/target/annotation/stereotype/Log.js +19 -17
- package/target/annotation/stereotype/Repository.js +9 -9
- package/target/annotation/stereotype/Service.js +9 -9
- package/target/annotation/stereotype/Value.js +5 -0
- package/target/annotation/valid/AddChildValid.js +56 -56
- package/target/annotation/valid/CustomType.js +11 -11
- package/target/annotation/valid/DefaultVal.js +10 -10
- package/target/annotation/valid/NotNull.js +8 -8
- package/target/annotation/valid/Rule.js +99 -100
- package/target/annotation/valid/Size.js +10 -10
- package/target/annotation/valid/Type.js +10 -10
- package/target/annotation/valid/ValidCustom.js +17 -17
- package/target/annotation/valid/ValidForm.js +133 -133
- package/target/annotation.js +110 -108
- package/target/config/ApplicationConfig.js +2 -2
- package/target/config/SysConfig.js +19 -19
- package/target/constant/AppStatusEnum.js +9 -9
- package/target/constant/BootPriority.js +11 -11
- package/target/constant/CommonConstant.js +18 -18
- package/target/constant/ComponentKind.js +11 -11
- package/target/constant/DataTypes.js +19 -19
- package/target/constant/FastCarMetaData.js +33 -31
- package/target/constant/LifeCycleModule.js +9 -9
- package/target/db.js +49 -49
- package/target/index.js +21 -21
- package/target/interface/ApplicationHook.js +2 -2
- package/target/interface/ApplicationInterface.js +2 -2
- package/target/interface/ApplicationRunnerService.js +2 -2
- package/target/interface/DataSourceManager.js +2 -2
- package/target/interface/Logger.js +5 -5
- package/target/model/BaseMapper.js +103 -98
- package/target/model/DataMap.js +87 -87
- package/target/model/FormRuleModel.js +2 -2
- package/target/model/ValidError.js +5 -5
- package/target/model/WinstonLogger.js +98 -96
- package/target/type/ClassConstructor.js +2 -0
- package/target/type/ComponentDesc.js +9 -2
- package/target/type/DesignMeta.js +15 -15
- package/target/type/FileHotterDesc.js +9 -2
- package/target/type/MapperType.js +2 -2
- package/target/type/ProcessType.js +2 -2
- package/target/type/SqlError.js +5 -5
- package/target/type/WinstonLoggerType.js +9 -9
- package/target/utils/ClassLoader.js +66 -65
- package/target/utils/ClassUtils.js +35 -35
- package/target/utils/CryptoUtil.js +86 -86
- package/target/utils/DataFormat.js +88 -88
- package/target/utils/DateUtil.js +71 -71
- package/target/utils/FileUtil.js +153 -153
- package/target/utils/FormatStr.js +14 -14
- package/target/utils/IPUtils.js +34 -34
- package/target/utils/Id.js +8 -9
- package/target/utils/Mix.js +62 -62
- package/target/utils/ReflectUtil.js +22 -22
- package/target/utils/TypeUtil.js +53 -53
- package/target/utils/ValidationUtil.js +123 -123
- package/target/utils.js +25 -25
- package/test/example/logs/fastcar-server.app.log +0 -0
- package/test/example/logs/fastcar-server.sys.log +10 -0
- package/test/example/logs/fastcar-server.sys1.log +8 -0
- package/test/example/logs/fastcar-server.sys2.log +11 -0
- package/test/example/logs/fastcar-server.sys3.log +0 -0
- package/test/example/logs/other-server.app.log +0 -0
- package/test/example/logs/other-server.sys.log +5 -0
- package/test/example/logs/sys.log +0 -0
- package/test/example/logs/sys1.log +0 -0
- package/test/example/resource/application.yml +2 -0
- package/test/example/resource/hello.yml +1 -1
- package/test/example/simple/app-test.ts +2 -1
- package/test/example/simple/app.ts +16 -16
- package/test/example/simple/service/CallService.ts +2 -0
- package/test/example/simple/service/HelloService.ts +2 -0
- package/test/unit/sys2.log +6 -0
- package/test/unit/sys3.log +6 -0
- package/test/unit/sys4.log +6 -0
- package/test/unit/sys5.log +6 -0
- package/test/unit/sys6.log +6 -0
|
@@ -1,96 +1,98 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const winston = require("winston");
|
|
4
|
-
const WinstonLoggerType_1 = require("../type/WinstonLoggerType");
|
|
5
|
-
const path = require("path");
|
|
6
|
-
const utils_1 = require("../utils");
|
|
7
|
-
const util = require("util");
|
|
8
|
-
const SPLAT = Symbol.for("splat");
|
|
9
|
-
class WinstonLogger {
|
|
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
|
-
let
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const winston = require("winston");
|
|
4
|
+
const WinstonLoggerType_1 = require("../type/WinstonLoggerType");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
const utils_1 = require("../utils");
|
|
7
|
+
const util = require("util");
|
|
8
|
+
const SPLAT = Symbol.for("splat");
|
|
9
|
+
class WinstonLogger {
|
|
10
|
+
config;
|
|
11
|
+
categoryMap;
|
|
12
|
+
constructor(config) {
|
|
13
|
+
this.config = config;
|
|
14
|
+
this.categoryMap = new Map();
|
|
15
|
+
}
|
|
16
|
+
//控制台着色
|
|
17
|
+
colorize(str, level) {
|
|
18
|
+
let colorStyle = Reflect.get(WinstonLoggerType_1.ColorLevelType, level);
|
|
19
|
+
if (!colorStyle) {
|
|
20
|
+
return str;
|
|
21
|
+
}
|
|
22
|
+
return `\x1B[${colorStyle[0]}m ${str} \x1B[${colorStyle[1]}m`;
|
|
23
|
+
}
|
|
24
|
+
//数据着色为白色
|
|
25
|
+
colorizeData(data) {
|
|
26
|
+
let msg = utils_1.ValidationUtil.isObject(data) ? JSON.stringify(data) : data;
|
|
27
|
+
return `\x1B[37m ${msg} \x1B[39m`;
|
|
28
|
+
}
|
|
29
|
+
setConfig(config) {
|
|
30
|
+
this.config = config;
|
|
31
|
+
}
|
|
32
|
+
hasLogger(category) {
|
|
33
|
+
return winston.loggers.has(category);
|
|
34
|
+
}
|
|
35
|
+
getLogger(category) {
|
|
36
|
+
return this.categoryMap.get(category);
|
|
37
|
+
}
|
|
38
|
+
addLogger(category) {
|
|
39
|
+
if (this.categoryMap.has(category)) {
|
|
40
|
+
winston.loggers.close(category);
|
|
41
|
+
}
|
|
42
|
+
let newLogger = winston.loggers.add(category, {
|
|
43
|
+
format: winston.format.combine(winston.format.label({ label: category }), winston.format.printf((info) => {
|
|
44
|
+
//debug模式等级时仅为控制台输出
|
|
45
|
+
let level = info.level.toUpperCase();
|
|
46
|
+
let timestamp = utils_1.DateUtil.toDateTimeMS();
|
|
47
|
+
let content = {
|
|
48
|
+
timestamp,
|
|
49
|
+
level,
|
|
50
|
+
label: info.label,
|
|
51
|
+
message: info.message,
|
|
52
|
+
};
|
|
53
|
+
if (Reflect.has(info, SPLAT)) {
|
|
54
|
+
let splat = Reflect.get(info, SPLAT);
|
|
55
|
+
Reflect.set(content, "splat", typeof splat == "string" ? splat : JSON.stringify(splat));
|
|
56
|
+
}
|
|
57
|
+
if (info.stack) {
|
|
58
|
+
Reflect.set(content, "stack", info.stack);
|
|
59
|
+
}
|
|
60
|
+
Reflect.set(info, "timestamp", content.timestamp);
|
|
61
|
+
//新增打印控制台
|
|
62
|
+
if (this.config.printConsole) {
|
|
63
|
+
let text = this.colorize(util.format("[%s] [%s] %s - ", timestamp, level, info.label), info.level);
|
|
64
|
+
text += this.colorizeData(content.message);
|
|
65
|
+
if (Reflect.has(info, SPLAT)) {
|
|
66
|
+
let splatMsg = Reflect.get(info, SPLAT);
|
|
67
|
+
splatMsg.forEach((item) => {
|
|
68
|
+
text += " " + this.colorizeData(item);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
if (info.stack) {
|
|
72
|
+
text += this.colorizeData(`\nstatck: ${info.stack}`);
|
|
73
|
+
}
|
|
74
|
+
let fn = console.info;
|
|
75
|
+
if (Reflect.has(console, info.level)) {
|
|
76
|
+
fn = Reflect.get(console, info.level);
|
|
77
|
+
}
|
|
78
|
+
Reflect.apply(fn, console, [text]);
|
|
79
|
+
}
|
|
80
|
+
return util.format("%j", content);
|
|
81
|
+
})),
|
|
82
|
+
transports: [
|
|
83
|
+
new winston.transports.File({
|
|
84
|
+
level: this.config.fileLevel,
|
|
85
|
+
filename: path.join(this.config.rootPath, `${category}.log`),
|
|
86
|
+
maxsize: this.config.maxsize,
|
|
87
|
+
maxFiles: this.config.maxFiles,
|
|
88
|
+
}),
|
|
89
|
+
],
|
|
90
|
+
});
|
|
91
|
+
this.categoryMap.set(category, newLogger);
|
|
92
|
+
return newLogger;
|
|
93
|
+
}
|
|
94
|
+
getLoggerList() {
|
|
95
|
+
return [...this.categoryMap.values()];
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
exports.default = WinstonLogger;
|
|
@@ -1,2 +1,9 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InjectionType = void 0;
|
|
4
|
+
//注入的类型
|
|
5
|
+
var InjectionType;
|
|
6
|
+
(function (InjectionType) {
|
|
7
|
+
InjectionType["PROPERTYKEY"] = "PROPERTYKEY";
|
|
8
|
+
InjectionType["ALIAS"] = "ALIAS";
|
|
9
|
+
})(InjectionType || (exports.InjectionType = InjectionType = {}));
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DesignMeta = void 0;
|
|
4
|
-
var DesignMeta;
|
|
5
|
-
(function (DesignMeta) {
|
|
6
|
-
DesignMeta["table"] = "db:table";
|
|
7
|
-
DesignMeta["field"] = "db:field";
|
|
8
|
-
DesignMeta["fieldMap"] = "db:fieldMap";
|
|
9
|
-
DesignMeta["dbType"] = "db:dbType";
|
|
10
|
-
DesignMeta["primaryKey"] = "db:primaryKey";
|
|
11
|
-
DesignMeta["entity"] = "db:entity";
|
|
12
|
-
DesignMeta["mapping"] = "db:mapping";
|
|
13
|
-
DesignMeta["dbFields"] = "db:fields";
|
|
14
|
-
DesignMeta["sqlSession"] = "SqlSession";
|
|
15
|
-
})(DesignMeta
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DesignMeta = void 0;
|
|
4
|
+
var DesignMeta;
|
|
5
|
+
(function (DesignMeta) {
|
|
6
|
+
DesignMeta["table"] = "db:table";
|
|
7
|
+
DesignMeta["field"] = "db:field";
|
|
8
|
+
DesignMeta["fieldMap"] = "db:fieldMap";
|
|
9
|
+
DesignMeta["dbType"] = "db:dbType";
|
|
10
|
+
DesignMeta["primaryKey"] = "db:primaryKey";
|
|
11
|
+
DesignMeta["entity"] = "db:entity";
|
|
12
|
+
DesignMeta["mapping"] = "db:mapping";
|
|
13
|
+
DesignMeta["dbFields"] = "db:fields";
|
|
14
|
+
DesignMeta["sqlSession"] = "SqlSession";
|
|
15
|
+
})(DesignMeta || (exports.DesignMeta = DesignMeta = {}));
|
|
@@ -1,2 +1,9 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HotReloadEnum = void 0;
|
|
4
|
+
var HotReloadEnum;
|
|
5
|
+
(function (HotReloadEnum) {
|
|
6
|
+
HotReloadEnum["reload"] = "reload";
|
|
7
|
+
HotReloadEnum["sysReload"] = "sysReload";
|
|
8
|
+
HotReloadEnum["configReload"] = "configReload";
|
|
9
|
+
})(HotReloadEnum || (exports.HotReloadEnum = HotReloadEnum = {}));
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
package/target/type/SqlError.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
class SqlError extends Error {
|
|
4
|
-
}
|
|
5
|
-
exports.default = SqlError;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class SqlError extends Error {
|
|
4
|
+
}
|
|
5
|
+
exports.default = SqlError;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ColorLevelType = void 0;
|
|
4
|
-
exports.ColorLevelType = {
|
|
5
|
-
info: [32, 39],
|
|
6
|
-
debug: [36, 39],
|
|
7
|
-
warn: [33, 39],
|
|
8
|
-
error: [91, 39], //red
|
|
9
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ColorLevelType = void 0;
|
|
4
|
+
exports.ColorLevelType = {
|
|
5
|
+
info: [32, 39], //green
|
|
6
|
+
debug: [36, 39], // cyan
|
|
7
|
+
warn: [33, 39], //yellow
|
|
8
|
+
error: [91, 39], //red
|
|
9
|
+
};
|
|
@@ -1,65 +1,66 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const TypeUtil_1 = require("./TypeUtil");
|
|
4
|
-
const FileUtil_1 = require("./FileUtil");
|
|
5
|
-
const fs = require("fs");
|
|
6
|
-
const path = require("path");
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
* @version 1.
|
|
11
|
-
*
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
let
|
|
29
|
-
let
|
|
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
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const TypeUtil_1 = require("./TypeUtil");
|
|
4
|
+
const FileUtil_1 = require("./FileUtil");
|
|
5
|
+
const fs = require("fs");
|
|
6
|
+
const path = require("path");
|
|
7
|
+
const FileHotterDesc_1 = require("../type/FileHotterDesc");
|
|
8
|
+
class ClassLoader {
|
|
9
|
+
/***
|
|
10
|
+
* @version 1.0 加载模块
|
|
11
|
+
* @version 1.1 新增是否强制重载模块
|
|
12
|
+
*
|
|
13
|
+
*/
|
|
14
|
+
static loadModule(filePath, force = false) {
|
|
15
|
+
//校验后缀名是否为js或者ts
|
|
16
|
+
if (!TypeUtil_1.default.isTSORJS(filePath)) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
//避免重复加载或者想要重新进行挂载
|
|
20
|
+
if (Reflect.has(require.cache, filePath)) {
|
|
21
|
+
if (force) {
|
|
22
|
+
Reflect.deleteProperty(require.cache, filePath);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
//可能不止一个方法
|
|
26
|
+
const modulesMap = new Map();
|
|
27
|
+
//进行方法加载
|
|
28
|
+
let moduleClass = require(filePath);
|
|
29
|
+
let keys = Object.keys(moduleClass);
|
|
30
|
+
let fileName = FileUtil_1.default.getFileName(filePath);
|
|
31
|
+
keys.forEach((key) => {
|
|
32
|
+
let instance = moduleClass[key];
|
|
33
|
+
if (TypeUtil_1.default.isFunction(instance)) {
|
|
34
|
+
modulesMap.set(instance.name, instance);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (TypeUtil_1.default.isObject(instance)) {
|
|
38
|
+
modulesMap.set(fileName, instance);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
return modulesMap;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* @version 1.0 监听某个文件或者文件夹
|
|
45
|
+
*/
|
|
46
|
+
static watchServices(fp, context, eventName = FileHotterDesc_1.HotReloadEnum.reload) {
|
|
47
|
+
if (typeof context.emit != "function") {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
const currStats = fs.statSync(fp);
|
|
51
|
+
let fileFlag = currStats.isFile();
|
|
52
|
+
//添加热更方法
|
|
53
|
+
fs.watch(fp, function (event, filename) {
|
|
54
|
+
if (event === "change") {
|
|
55
|
+
if (!fileFlag && filename) {
|
|
56
|
+
context.emit(eventName, path.join(fp, filename));
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
context.emit(eventName, fp);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.default = ClassLoader;
|
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
class ClassUtils {
|
|
4
|
-
//获取一个类所有的proto属性 采用递归的形式
|
|
5
|
-
static getProtoType(t) {
|
|
6
|
-
if (!t?.prototype) {
|
|
7
|
-
return [];
|
|
8
|
-
}
|
|
9
|
-
let keys = Reflect.ownKeys(t?.prototype).map((item) => {
|
|
10
|
-
return item;
|
|
11
|
-
});
|
|
12
|
-
let parentObj = Reflect.getPrototypeOf(t);
|
|
13
|
-
if (!parentObj || !Reflect.has(parentObj, "prototype")) {
|
|
14
|
-
return keys;
|
|
15
|
-
}
|
|
16
|
-
let parentKeys = ClassUtils.getProtoType(parentObj);
|
|
17
|
-
let s = new Set([...keys, ...parentKeys]);
|
|
18
|
-
return [...s];
|
|
19
|
-
}
|
|
20
|
-
static getProtoDesc(t, key) {
|
|
21
|
-
if (!t?.prototype) {
|
|
22
|
-
return null;
|
|
23
|
-
}
|
|
24
|
-
let desc = Object.getOwnPropertyDescriptor(t.prototype, key);
|
|
25
|
-
if (!!desc) {
|
|
26
|
-
return desc;
|
|
27
|
-
}
|
|
28
|
-
let parentObj = Reflect.getPrototypeOf(t);
|
|
29
|
-
if (!parentObj || !Reflect.has(parentObj, "prototype")) {
|
|
30
|
-
return null;
|
|
31
|
-
}
|
|
32
|
-
return ClassUtils.getProtoDesc(parentObj, key);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
exports.default = ClassUtils;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class ClassUtils {
|
|
4
|
+
//获取一个类所有的proto属性 采用递归的形式
|
|
5
|
+
static getProtoType(t) {
|
|
6
|
+
if (!t?.prototype) {
|
|
7
|
+
return [];
|
|
8
|
+
}
|
|
9
|
+
let keys = Reflect.ownKeys(t?.prototype).map((item) => {
|
|
10
|
+
return item;
|
|
11
|
+
});
|
|
12
|
+
let parentObj = Reflect.getPrototypeOf(t);
|
|
13
|
+
if (!parentObj || !Reflect.has(parentObj, "prototype")) {
|
|
14
|
+
return keys;
|
|
15
|
+
}
|
|
16
|
+
let parentKeys = ClassUtils.getProtoType(parentObj);
|
|
17
|
+
let s = new Set([...keys, ...parentKeys]);
|
|
18
|
+
return [...s];
|
|
19
|
+
}
|
|
20
|
+
static getProtoDesc(t, key) {
|
|
21
|
+
if (!t?.prototype) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
let desc = Object.getOwnPropertyDescriptor(t.prototype, key);
|
|
25
|
+
if (!!desc) {
|
|
26
|
+
return desc;
|
|
27
|
+
}
|
|
28
|
+
let parentObj = Reflect.getPrototypeOf(t);
|
|
29
|
+
if (!parentObj || !Reflect.has(parentObj, "prototype")) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
return ClassUtils.getProtoDesc(parentObj, key);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.default = ClassUtils;
|