node-karin 1.9.7 → 1.9.9

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.
@@ -7,13 +7,11 @@ import { fork } from 'node:child_process';
7
7
  // src/start/index.ts
8
8
  var isStart = false;
9
9
  var child;
10
- var lastStartTime = 0;
11
- var isClosing = false;
12
- var minRestartInterval = 5e3;
13
10
  var _filename = fileURLToPath(import.meta.url);
14
11
  var _dirname = path.dirname(_filename);
15
12
  var getMainPath = () => {
16
- const filePath = path.join(_dirname, import.meta.url.includes(".mjs") ? "app.mjs" : "app.ts");
13
+ const isESM = import.meta.url.includes(".mjs");
14
+ const filePath = path.join(_dirname, isESM ? "app.mjs" : "app.ts");
17
15
  if (fs.existsSync(filePath)) {
18
16
  return filePath;
19
17
  }
@@ -25,31 +23,23 @@ var start = () => {
25
23
  return child;
26
24
  }
27
25
  isStart = true;
28
- lastStartTime = Date.now();
29
26
  child = fork(getMainPath());
30
27
  child.on("message", (message) => {
31
- const { port, type, token } = JSON.parse(message) || {};
32
- if (type === "restart") {
33
- restart(port, token);
34
- return;
35
- }
36
- if (type === "stop") {
37
- process.exit(0);
38
- }
39
- });
40
- child.on("exit", (code) => {
41
- isStart = false;
42
- if (!isClosing && Date.now() - lastStartTime > minRestartInterval) {
43
- process.exit(code);
28
+ try {
29
+ const { port, type, token } = JSON.parse(message) || {};
30
+ if (type === "restart") {
31
+ restart(port, token);
32
+ return;
33
+ }
34
+ if (type === "stop") exit();
35
+ } catch (error) {
36
+ console.error("\u5904\u7406\u5B50\u8FDB\u7A0B\u6D88\u606F\u65F6\u51FA\u9519:", error);
44
37
  }
45
38
  });
46
- child.on("error", (err) => {
47
- console.error("\u5B50\u8FDB\u7A0B\u53D1\u751F\u9519\u8BEF:", err);
48
- });
39
+ child.once("exit", exit);
49
40
  return child;
50
41
  };
51
42
  var restart = async (port, token, isFetch = true) => {
52
- isClosing = true;
53
43
  if (isFetch) {
54
44
  await sendExit(port, token);
55
45
  }
@@ -101,7 +91,15 @@ var sendExit = async (port, token) => {
101
91
  } catch {
102
92
  }
103
93
  };
104
- process.on("exit", () => {
105
- child.kill("SIGTERM");
106
- });
94
+ var exit = () => {
95
+ try {
96
+ child.kill("SIGTERM");
97
+ process.kill(child.pid);
98
+ } catch {
99
+ child?.kill();
100
+ } finally {
101
+ process.exit(0);
102
+ }
103
+ };
104
+ process.on("exit", exit);
107
105
  start();
@@ -1,5 +1,6 @@
1
1
  import EventEmitter from 'events';
2
2
  import chalk__default from 'chalk';
3
+ import { Logger as Logger$1 } from 'log4js';
3
4
 
4
5
  /**
5
6
  * @description 所有日志等级
@@ -13,7 +14,7 @@ type LogMethodsOnly = Pick<Logger, LogMethodNames>;
13
14
  /**
14
15
  * @description 日志接口
15
16
  */
16
- interface Logger {
17
+ interface Logger extends Logger$1 {
17
18
  /** @description chalk模块 */
18
19
  chalk: typeof chalk__default;
19
20
  /** @description 将文本设置为红色 */
@@ -43,12 +44,6 @@ interface Logger {
43
44
  * @param args - 日志内容
44
45
  */
45
46
  bot: (level: LogMethodNames, id: string, ...args: any[]) => void;
46
- /**
47
- * @description 构建自定义前缀函数
48
- * @param prefix - 前缀
49
- * @returns 返回一个函数
50
- */
51
- prefix: (prefix: string) => (level: LogMethodNames, ...args: any[]) => void;
52
47
  /** @description 打印追踪日志 */
53
48
  trace(...args: any[]): void;
54
49
  /** @description 打印调试日志 */
@@ -67,17 +62,6 @@ interface Logger {
67
62
  off(): void;
68
63
  /** @description 打印日志 跟`info`日志相同 */
69
64
  log(...args: any[]): void;
70
- /** @description 获取、设置日志等级 */
71
- level: LoggerLevel;
72
- /** @description 获取当前配置 */
73
- readonly config: LoggerConfig;
74
- /**
75
- * @description 设置新的配置
76
- * @param config - 日志配置
77
- */
78
- configure(config: Partial<LoggerConfig>): void;
79
- /** @description 关闭并清理资源 */
80
- close(): void;
81
65
  }
82
66
  /**
83
67
  * @description 文件日志配置
@@ -110,8 +94,6 @@ interface FileLogConfig {
110
94
  * @description 日志配置
111
95
  */
112
96
  interface LoggerConfig {
113
- /** @description 日志前缀 @default '' */
114
- prefix: string;
115
97
  /** @description 日志级别 @default 'info' */
116
98
  level: LoggerLevel;
117
99
  /** @description `logger.fnc`自定义颜色 @default '#FFFF00' */
@@ -123,29 +105,5 @@ interface LoggerConfig {
123
105
  * @description 默认配置
124
106
  */
125
107
  declare const DEFAULT_LOGGER_CONFIG: LoggerConfig;
126
- /**
127
- * @description 日志级别优先级
128
- */
129
- declare const LoggerLevelPriority: Record<LoggerLevel, number>;
130
- /**
131
- * @description 日志输出接口
132
- */
133
- interface LogWriter {
134
- /**
135
- * @description 输出日志
136
- * @param level - 日志级别
137
- * @param message - 日志消息
138
- */
139
- write(level: LoggerLevel, message: string): void;
140
- /**
141
- * @description 更新配置
142
- * @param newConfig - 新的配置
143
- */
144
- updateConfig?(newConfig: Partial<FileLogConfig>): void;
145
- /**
146
- * @description 关闭输出
147
- */
148
- close?(): void;
149
- }
150
108
 
151
- export { DEFAULT_LOGGER_CONFIG as D, type FileLogConfig as F, type Logger as L, type LogMethodNames as a, type LoggerLevel as b, type LogMethodsOnly as c, type LoggerConfig as d, LoggerLevelPriority as e, type LogWriter as f };
109
+ export { DEFAULT_LOGGER_CONFIG as D, type FileLogConfig as F, type Logger as L, type LogMethodNames as a, type LoggerLevel as b, type LogMethodsOnly as c, type LoggerConfig as d };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-karin",
3
- "version": "1.9.7",
3
+ "version": "1.9.9",
4
4
  "description": "Lightweight, efficient, concise, and stable robot framework.",
5
5
  "keywords": [
6
6
  "node",
@@ -170,6 +170,7 @@
170
170
  "chokidar": "4.0.3",
171
171
  "express": "npm:@karinjs/express@1.0.3",
172
172
  "lodash": "npm:@karinjs/lodash@1.1.1",
173
+ "log4js": "^6.9.1",
173
174
  "moment": "npm:@karinjs/moment@1.1.5",
174
175
  "node-schedule": "npm:@karinjs/node-schedule@1.0.0",
175
176
  "redis": "npm:@karinjs/redis@1.1.3",