@x-9lab/xlab 1.0.4-alpha.1 → 1.0.6
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/@types/components/return-code/index.d.ts +4 -115
- package/@types/dot-file.d.ts +3 -0
- package/@types/global.d.ts +26 -1
- package/README.md +5 -0
- package/dist/bin/watch.js +1 -1
- package/dist/dot-file.js +41 -0
- package/dist/global.js +1 -0
- package/dist/server.js +2 -0
- package/package.json +2 -2
|
@@ -1,44 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 状态详细信息
|
|
3
3
|
*/
|
|
4
|
-
declare const CODE_DETAIL:
|
|
5
|
-
FAIL: {
|
|
6
|
-
errorcode: number;
|
|
7
|
-
msg: string;
|
|
8
|
-
};
|
|
9
|
-
SUCCESS: {
|
|
10
|
-
errorcode: number;
|
|
11
|
-
msg: string;
|
|
12
|
-
};
|
|
13
|
-
BUSY: {
|
|
14
|
-
errorcode: number;
|
|
15
|
-
msg: string;
|
|
16
|
-
};
|
|
17
|
-
WRONG_PARAMETER: {
|
|
18
|
-
errorcode: number;
|
|
19
|
-
msg: string;
|
|
20
|
-
};
|
|
21
|
-
NOT_FOUND: {
|
|
22
|
-
errorcode: number;
|
|
23
|
-
msg: string;
|
|
24
|
-
};
|
|
25
|
-
PERMISSION_DENIED: {
|
|
26
|
-
errorcode: number;
|
|
27
|
-
msg: string;
|
|
28
|
-
};
|
|
29
|
-
SERVER_BUSY: {
|
|
30
|
-
errorcode: number;
|
|
31
|
-
msg: string;
|
|
32
|
-
};
|
|
33
|
-
SERVER_TIMEOUT: {
|
|
34
|
-
errorcode: number;
|
|
35
|
-
msg: string;
|
|
36
|
-
};
|
|
37
|
-
UNCHECK_ERROR: {
|
|
38
|
-
errorcode: number;
|
|
39
|
-
msg: string;
|
|
40
|
-
};
|
|
41
|
-
};
|
|
4
|
+
declare const CODE_DETAIL: XLab.ICodeDetail;
|
|
42
5
|
/**
|
|
43
6
|
* 根据状态码获取错误定义信息
|
|
44
7
|
* @param code 状态码
|
|
@@ -72,88 +35,14 @@ export { getReturnCode };
|
|
|
72
35
|
* 获取错误代码
|
|
73
36
|
* @return 错误代码
|
|
74
37
|
*/
|
|
75
|
-
declare function getCodeDetail():
|
|
76
|
-
FAIL: {
|
|
77
|
-
errorcode: number;
|
|
78
|
-
msg: string;
|
|
79
|
-
};
|
|
80
|
-
SUCCESS: {
|
|
81
|
-
errorcode: number;
|
|
82
|
-
msg: string;
|
|
83
|
-
};
|
|
84
|
-
BUSY: {
|
|
85
|
-
errorcode: number;
|
|
86
|
-
msg: string;
|
|
87
|
-
};
|
|
88
|
-
WRONG_PARAMETER: {
|
|
89
|
-
errorcode: number;
|
|
90
|
-
msg: string;
|
|
91
|
-
};
|
|
92
|
-
NOT_FOUND: {
|
|
93
|
-
errorcode: number;
|
|
94
|
-
msg: string;
|
|
95
|
-
};
|
|
96
|
-
PERMISSION_DENIED: {
|
|
97
|
-
errorcode: number;
|
|
98
|
-
msg: string;
|
|
99
|
-
};
|
|
100
|
-
SERVER_BUSY: {
|
|
101
|
-
errorcode: number;
|
|
102
|
-
msg: string;
|
|
103
|
-
};
|
|
104
|
-
SERVER_TIMEOUT: {
|
|
105
|
-
errorcode: number;
|
|
106
|
-
msg: string;
|
|
107
|
-
};
|
|
108
|
-
UNCHECK_ERROR: {
|
|
109
|
-
errorcode: number;
|
|
110
|
-
msg: string;
|
|
111
|
-
};
|
|
112
|
-
};
|
|
38
|
+
declare function getCodeDetail(): XLab.ICodeDetail;
|
|
113
39
|
export { getCodeDetail };
|
|
114
40
|
/**
|
|
115
41
|
* 设置新的错误代码
|
|
116
42
|
* @param data 新的错误代码数据
|
|
117
43
|
*/
|
|
118
|
-
declare function set(data: XLab.
|
|
44
|
+
declare function set(data: Record<string, XLab.ICodeItem>): void;
|
|
119
45
|
export { set };
|
|
120
46
|
/**错误类型对象 */
|
|
121
|
-
declare const ErrorTypes:
|
|
122
|
-
FAIL: {
|
|
123
|
-
errorcode: number;
|
|
124
|
-
msg: string;
|
|
125
|
-
};
|
|
126
|
-
SUCCESS: {
|
|
127
|
-
errorcode: number;
|
|
128
|
-
msg: string;
|
|
129
|
-
};
|
|
130
|
-
BUSY: {
|
|
131
|
-
errorcode: number;
|
|
132
|
-
msg: string;
|
|
133
|
-
};
|
|
134
|
-
WRONG_PARAMETER: {
|
|
135
|
-
errorcode: number;
|
|
136
|
-
msg: string;
|
|
137
|
-
};
|
|
138
|
-
NOT_FOUND: {
|
|
139
|
-
errorcode: number;
|
|
140
|
-
msg: string;
|
|
141
|
-
};
|
|
142
|
-
PERMISSION_DENIED: {
|
|
143
|
-
errorcode: number;
|
|
144
|
-
msg: string;
|
|
145
|
-
};
|
|
146
|
-
SERVER_BUSY: {
|
|
147
|
-
errorcode: number;
|
|
148
|
-
msg: string;
|
|
149
|
-
};
|
|
150
|
-
SERVER_TIMEOUT: {
|
|
151
|
-
errorcode: number;
|
|
152
|
-
msg: string;
|
|
153
|
-
};
|
|
154
|
-
UNCHECK_ERROR: {
|
|
155
|
-
errorcode: number;
|
|
156
|
-
msg: string;
|
|
157
|
-
};
|
|
158
|
-
};
|
|
47
|
+
declare const ErrorTypes: XLab.ICodeDetail;
|
|
159
48
|
export { ErrorTypes };
|
package/@types/global.d.ts
CHANGED
|
@@ -47,6 +47,8 @@ declare global {
|
|
|
47
47
|
* @param conf 配置项
|
|
48
48
|
*/
|
|
49
49
|
function setSysConfig(conf: XLab.IConfig): void;
|
|
50
|
+
/**全局注入挂在对象 */
|
|
51
|
+
var XLAB: Record<string, XLab.JsonValue>;
|
|
50
52
|
namespace XLab {
|
|
51
53
|
/**JSON 基本数据类型 */
|
|
52
54
|
type JsonValue = boolean | string | number | null | undefined | JsonArray | JsonObject;
|
|
@@ -163,7 +165,30 @@ declare global {
|
|
|
163
165
|
msg: string;
|
|
164
166
|
}
|
|
165
167
|
/**业务错误定义 */
|
|
166
|
-
|
|
168
|
+
interface ICodeDetail {
|
|
169
|
+
/**
|
|
170
|
+
操作失败
|
|
171
|
+
|
|
172
|
+
作为任何未定义失败的默认返回
|
|
173
|
+
*/
|
|
174
|
+
FAIL: ICodeItem;
|
|
175
|
+
/**操作成功 */
|
|
176
|
+
SUCCESS: ICodeItem;
|
|
177
|
+
/**业务繁忙 */
|
|
178
|
+
BUSY: ICodeItem;
|
|
179
|
+
/**参数错误 */
|
|
180
|
+
WRONG_PARAMETER: ICodeItem;
|
|
181
|
+
/**数据不存在 */
|
|
182
|
+
NOT_FOUND: ICodeItem;
|
|
183
|
+
/**没有权限 */
|
|
184
|
+
PERMISSION_DENIED: ICodeItem;
|
|
185
|
+
/**服务繁忙 */
|
|
186
|
+
SERVER_BUSY: ICodeItem;
|
|
187
|
+
/**服务超时 */
|
|
188
|
+
SERVER_TIMEOUT: ICodeItem;
|
|
189
|
+
/**未知错误 */
|
|
190
|
+
UNCHECK_ERROR: ICodeItem;
|
|
191
|
+
}
|
|
167
192
|
/**模块配置 */
|
|
168
193
|
interface XConfig {
|
|
169
194
|
/**watch 模式配置 */
|
package/README.md
CHANGED
|
@@ -18,6 +18,11 @@ X-9lab 通用服务端
|
|
|
18
18
|
模块会自动检测执行根目录中是否存在 `xlab.config.js` 文件。如存在该文件则会使用该文件为模块的启动配置文件。支持的配置项:
|
|
19
19
|
1. `watch` 是否开启 watch 模式
|
|
20
20
|
1. `business` 业务目录名称。注意当前只支持根目录下的文件夹
|
|
21
|
+
- 配置文件 `.xlab`
|
|
22
|
+
该文件用于定义系统中的全局变量,模块会自动检测执行根目录中是否存在 `.xlab` 文件。该类型文件一般用于定义一些不方便在代码中声明的敏感数据,因此 `.xlab` 及附属的环境文件 **不应该** 被提交到仓库中。
|
|
23
|
+
- 使用 `<key>=<value>` 的方式定义数据
|
|
24
|
+
- 文件中的数据会被加载到 `global.XLAB` 对象中
|
|
25
|
+
- `.xlab` 为生产环境定义,`.xlab.development` 为开发环境定义,`.xlab.sandbox` 为沙箱环境定义
|
|
21
26
|
- `watch` 模式
|
|
22
27
|
`xlab` 支持自动重启业务,开发中使用该功能可以减少大量手动重启业务的操作。
|
|
23
28
|
启用方式:
|
package/dist/bin/watch.js
CHANGED
package/dist/dot-file.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "processDotFile", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: ()=>processDotFile
|
|
8
|
+
});
|
|
9
|
+
const _path = /*#__PURE__*/ _interopRequireDefault(require("path"));
|
|
10
|
+
const _fs = /*#__PURE__*/ _interopRequireDefault(require("fs"));
|
|
11
|
+
const _utils = require("@x-drive/utils");
|
|
12
|
+
function _interopRequireDefault(obj) {
|
|
13
|
+
return obj && obj.__esModule ? obj : {
|
|
14
|
+
default: obj
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/**行分割正则 */ const LINE_SPLIT_REGEXP = /[\s]?=[\s]?/;
|
|
18
|
+
/**处理根目录下可能存在的配置文件 */ function processDotFile(env, logger) {
|
|
19
|
+
env = env.toLowerCase();
|
|
20
|
+
if (env === "production") {
|
|
21
|
+
env = "";
|
|
22
|
+
} else {
|
|
23
|
+
env = `.${env}`;
|
|
24
|
+
}
|
|
25
|
+
const dotFile = _path.default.resolve(process.cwd(), `.xlab${env}`);
|
|
26
|
+
try {
|
|
27
|
+
const fileStr = _fs.default.readFileSync(dotFile, "utf8");
|
|
28
|
+
const lines = fileStr.split("\n");
|
|
29
|
+
for(let i = 0; i < lines.length; i++){
|
|
30
|
+
const line = lines[i];
|
|
31
|
+
const linePart = line.split(LINE_SPLIT_REGEXP);
|
|
32
|
+
if ((0, _utils.isArray)(linePart) && linePart.length === 2) {
|
|
33
|
+
global.XLAB[linePart[0]] = JSON.parse(linePart[1]);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
} catch (e) {
|
|
37
|
+
if (e.code !== "ENOENT") {
|
|
38
|
+
logger.error(e);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
package/dist/global.js
CHANGED
package/dist/server.js
CHANGED
|
@@ -17,6 +17,7 @@ require("./global");
|
|
|
17
17
|
const _log = require("./components/log");
|
|
18
18
|
const _cron = require("./components/cron");
|
|
19
19
|
const _defaultXConfig = /*#__PURE__*/ _interopRequireDefault(require("./default-x-config"));
|
|
20
|
+
const _dotFile = require("./dot-file");
|
|
20
21
|
const _koaStatic = /*#__PURE__*/ _interopRequireDefault(require("koa-static"));
|
|
21
22
|
const _koaRouter = /*#__PURE__*/ _interopRequireDefault(require("koa-router"));
|
|
22
23
|
const _path = /*#__PURE__*/ _interopRequireDefault(require("path"));
|
|
@@ -72,6 +73,7 @@ function _interopRequireWildcard(obj, nodeInterop) {
|
|
|
72
73
|
return newObj;
|
|
73
74
|
}
|
|
74
75
|
const logger = _log.globalLog.getLogger("system");
|
|
76
|
+
(0, _dotFile.processDotFile)(_config.default.env, logger);
|
|
75
77
|
// 只在 master 上输出的日志
|
|
76
78
|
global.masterLog = _config.log;
|
|
77
79
|
// 服务实例
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@x-9lab/xlab",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "9lab 服务端模块",
|
|
5
|
-
"versionDesc": "
|
|
5
|
+
"versionDesc": "支持根目录下的点配置文件",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"dev": "swc src -D ./src/bin --config-file .swcrc -d dist -w",
|
|
8
8
|
"compile": "swc src -D ./src/bin --config-file .swcrc -d dist",
|