node-karin 1.15.5 → 1.16.1
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/CHANGELOG.md +31 -0
- package/dist/adapter-BqlH3u3X.mjs +218 -0
- package/dist/app-DdMQbBEY.mjs +4109 -0
- package/dist/cache-CPcPeo6N.mjs +163 -0
- package/dist/chunk-NzVPYdc1.mjs +21 -0
- package/dist/cli/index.cjs +10900 -1
- package/dist/cli/index.d.ts +1 -1
- package/dist/cli/index.mjs +10770 -10224
- package/dist/file-ZGuqNDd-.mjs +15987 -0
- package/dist/file-dGy9of8-.mjs +268 -0
- package/dist/fsSync-Cf5MWILk.mjs +65 -0
- package/dist/index.d.ts +12235 -12738
- package/dist/index.mjs +2054 -25247
- package/dist/internal-DupfycKE.mjs +597 -0
- package/dist/kv-DZp4UIxg.mjs +192 -0
- package/dist/module/art-template.d.ts +2 -13
- package/dist/module/art-template.mjs +3 -1
- package/dist/module/axios.d.ts +3 -2
- package/dist/module/axios.mjs +5 -2
- package/dist/module/chalk.d.ts +3 -2
- package/dist/module/chalk.mjs +5 -2
- package/dist/module/chokidar.d.ts +3 -2
- package/dist/module/chokidar.mjs +5 -2
- package/dist/module/express.d.ts +2 -1
- package/dist/module/express.mjs +3 -1
- package/dist/module/lodash.d.ts +2 -1
- package/dist/module/lodash.mjs +3 -1
- package/dist/module/log4js.d.ts +3 -2
- package/dist/module/log4js.mjs +5 -2
- package/dist/module/moment.d.ts +2 -1
- package/dist/module/moment.mjs +3 -1
- package/dist/module/node-schedule.d.ts +3 -2
- package/dist/module/node-schedule.mjs +5 -2
- package/dist/module/redis.d.ts +3 -2
- package/dist/module/redis.mjs +5 -2
- package/dist/module/sqlite3.d.ts +3 -2
- package/dist/module/sqlite3.mjs +5 -2
- package/dist/module/ws.d.ts +3 -2
- package/dist/module/ws.mjs +5 -2
- package/dist/module/yaml.d.ts +3 -2
- package/dist/module/yaml.mjs +5 -2
- package/dist/queue-CnKedaZA.mjs +70 -0
- package/dist/redis-aLJ7wbJH.mjs +1556 -0
- package/dist/render-DPqueDZr.mjs +170 -0
- package/dist/root.d.ts +46 -46
- package/dist/root.mjs +136 -93
- package/dist/router-zPSN9-tY.mjs +124 -0
- package/dist/server-DT64D-m-.mjs +38 -0
- package/dist/snapka-BTlnZOyI.mjs +450 -0
- package/dist/sqlite-Dcj9jlW9.mjs +307 -0
- package/dist/start/app.d.ts +1 -1
- package/dist/start/app.mjs +14 -7
- package/dist/start/index.d.ts +1 -1
- package/dist/start/index.mjs +325 -656
- package/dist/template-Djk6y0uC.mjs +133 -0
- package/dist/terminalManager-Lxa8Sm06.mjs +783 -0
- package/dist/uptime-C121X_rq.mjs +210 -0
- package/dist/web/{CompressaPRO-GX.woff2.br → CompressaPRO-GX.woff2} +0 -0
- package/dist/web/assets/css/style-CBB8wM_W.css +14880 -0
- package/dist/web/assets/js/entry-Blf4Trpx.js +258540 -0
- package/dist/web/{googleapis.woff2.br → googleapis.woff2} +0 -0
- package/dist/web/index.html +2 -15
- package/dist/web/karin.png +0 -0
- package/dist/web/sha256.min.js +9 -0
- package/dist/ws-BLDoC2gV.mjs +80 -0
- package/dist/ws-CcoWd3Ar.mjs +106 -0
- package/package.json +7 -7
- package/dist/global.d.d.ts +0 -68
- package/dist/types-hAhbXJDZ.d.ts +0 -109
- package/dist/web/assets/css/components-ep7vm38G.css +0 -1
- package/dist/web/assets/css/index-Dadvd9mn.css.br +0 -0
- package/dist/web/assets/css/vendor-editor-CFbL2ovg.css.br +0 -0
- package/dist/web/assets/css/vendor-others-ZgkIHsf0.css +0 -1
- package/dist/web/assets/js/components-CU2xw4lY.js.br +0 -0
- package/dist/web/assets/js/entry-Dvb7eYLE.js.br +0 -0
- package/dist/web/assets/js/hooks-CRfhs4ON.js.br +0 -0
- package/dist/web/assets/js/page-404.tsx-DYMd_RI_.js +0 -1
- package/dist/web/assets/js/page-dashboard-CG60V_Z-.js.br +0 -0
- package/dist/web/assets/js/page-loading.tsx-wY8a9me3.js.br +0 -0
- package/dist/web/assets/js/page-login.tsx-B54ZOEZB.js.br +0 -0
- package/dist/web/assets/js/utils-C9nWTSuo.js +0 -2
- package/dist/web/assets/js/vendor-editor-BmqYP7lh.js.br +0 -0
- package/dist/web/assets/js/vendor-heroui-ClBCy2zk.js.br +0 -0
- package/dist/web/assets/js/vendor-others-6GiMrjd4.js.br +0 -0
- package/dist/web/assets/js/vendor-react-Dc9jdQiK.js.br +0 -0
- package/dist/web/assets/js/vendor-ui-utils-D0xkboLL.js.br +0 -0
- package/dist/web/assets/js/vendor-visual-saF8KLH_.js.br +0 -0
- package/dist/web/karin.png.br +0 -0
- package/dist/web/sha256.min.js.br +0 -0
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import { exec } from "child_process";
|
|
4
|
+
import { createServer } from "node:net";
|
|
5
|
+
|
|
6
|
+
//#region src/utils/system/error.ts
|
|
7
|
+
/**
|
|
8
|
+
* @description 拆解错误对象 用于`JSON`序列化
|
|
9
|
+
* @param error 错误对象
|
|
10
|
+
* @returns 拆解后的错误对象
|
|
11
|
+
*/
|
|
12
|
+
const stringifyError = (error) => {
|
|
13
|
+
const { name, message, stack } = error || {};
|
|
14
|
+
return {
|
|
15
|
+
name,
|
|
16
|
+
message,
|
|
17
|
+
stack
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* 将错误对象转为字符串
|
|
22
|
+
* @param error 错误对象
|
|
23
|
+
* @returns 错误字符串
|
|
24
|
+
*/
|
|
25
|
+
const errorToString = (error) => {
|
|
26
|
+
if (!error) return "";
|
|
27
|
+
return [
|
|
28
|
+
`name: ${error.name}`,
|
|
29
|
+
`message: ${error.message}`,
|
|
30
|
+
`stack: ${error.stack?.toString()}`
|
|
31
|
+
].join("\n");
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region src/utils/system/exec.ts
|
|
36
|
+
/**
|
|
37
|
+
* 执行 shell 命令
|
|
38
|
+
* @param cmd 命令
|
|
39
|
+
* @param options 选项
|
|
40
|
+
* @param options.log 是否打印日志 默认不打印
|
|
41
|
+
* @param options.booleanResult 是否只返回布尔值 表示命令是否成功执行 默认返回完整的结果
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* const { status, error, stdout, stderr } = await exec('ls -al')
|
|
45
|
+
* // -> { status: true, error: null, stdout: '...', stderr: '...' }
|
|
46
|
+
*
|
|
47
|
+
* const status = await exec('ls -al', { booleanResult: true })
|
|
48
|
+
* // -> true
|
|
49
|
+
*
|
|
50
|
+
* const { status, error, stdout, stderr } = await exec('ls -al', { log: true })
|
|
51
|
+
* // -> 打印执行命令和结果
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
const exec$1 = (cmd, options) => {
|
|
55
|
+
const logger = global?.logger || console;
|
|
56
|
+
return new Promise((resolve) => {
|
|
57
|
+
if (options?.log) logger.info([
|
|
58
|
+
"[exec] 执行命令:",
|
|
59
|
+
`pwd: ${options?.cwd || process.cwd()}`,
|
|
60
|
+
`cmd: ${cmd}`,
|
|
61
|
+
`options: ${JSON.stringify(options)}`
|
|
62
|
+
].join("\n"));
|
|
63
|
+
exec(cmd, options, (error, stdout, stderr) => {
|
|
64
|
+
if (options?.log) {
|
|
65
|
+
const info = stringifyError(error);
|
|
66
|
+
if (info.message) info.message = `\x1b[91m${info.message}\x1b[0m`;
|
|
67
|
+
logger.info([
|
|
68
|
+
"[exec] 执行结果:",
|
|
69
|
+
`stderr: ${stderr.toString()}`,
|
|
70
|
+
`stdout: ${stdout.toString()}`,
|
|
71
|
+
`error: ${JSON.stringify(info, null, 2)}`
|
|
72
|
+
].join("\n"));
|
|
73
|
+
}
|
|
74
|
+
if (options?.booleanResult) return resolve(!error);
|
|
75
|
+
stdout = stdout.toString();
|
|
76
|
+
stderr = stderr.toString();
|
|
77
|
+
if (options?.trim) {
|
|
78
|
+
stdout = stdout.trim();
|
|
79
|
+
stderr = stderr.trim();
|
|
80
|
+
}
|
|
81
|
+
resolve({
|
|
82
|
+
status: !error,
|
|
83
|
+
error,
|
|
84
|
+
stdout,
|
|
85
|
+
stderr
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
//#endregion
|
|
92
|
+
//#region src/utils/system/system.ts
|
|
93
|
+
/** 是否为windows */
|
|
94
|
+
const isWin = os.platform() === "win32";
|
|
95
|
+
/** 是否为linux */
|
|
96
|
+
const isLinux = os.platform() === "linux";
|
|
97
|
+
/** 是否为mac */
|
|
98
|
+
const isMac = os.platform() === "darwin";
|
|
99
|
+
/** 是否为docker */
|
|
100
|
+
const isDocker = fs.existsSync("/.dockerenv");
|
|
101
|
+
/** 是否为root用户 仅linux */
|
|
102
|
+
const isRoot = os.userInfo().uid === 0;
|
|
103
|
+
|
|
104
|
+
//#endregion
|
|
105
|
+
//#region src/utils/system/pid.ts
|
|
106
|
+
/**
|
|
107
|
+
* 传入端口号,返回对应的pid
|
|
108
|
+
* @param port - 端口号
|
|
109
|
+
*/
|
|
110
|
+
const getPid = async (port) => {
|
|
111
|
+
const { stdout } = await exec$1(isWin ? `netstat -ano | findstr :${port}` : `lsof -i:${port} | grep LISTEN | awk '{print $2}'`);
|
|
112
|
+
if (!stdout) return null;
|
|
113
|
+
if (isWin) {
|
|
114
|
+
const pid = stdout.toString().split(/\s+/).filter(Boolean).pop();
|
|
115
|
+
return isNaN(Number(pid)) ? null : Number(pid);
|
|
116
|
+
}
|
|
117
|
+
return isNaN(Number(stdout)) ? null : Number(stdout);
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
//#endregion
|
|
121
|
+
//#region src/utils/common/sleep.ts
|
|
122
|
+
/**
|
|
123
|
+
* 休眠函数
|
|
124
|
+
* @param ms 毫秒
|
|
125
|
+
* @example
|
|
126
|
+
* ```ts
|
|
127
|
+
* await sleep(1000)
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
131
|
+
|
|
132
|
+
//#endregion
|
|
133
|
+
//#region src/utils/system/port.ts
|
|
134
|
+
/**
|
|
135
|
+
* 检查端口是否可用
|
|
136
|
+
* @param port - 端口号
|
|
137
|
+
* @returns 端口可用返回true,否则返回false
|
|
138
|
+
*/
|
|
139
|
+
const checkPort = (port) => {
|
|
140
|
+
return new Promise((resolve) => {
|
|
141
|
+
const server = createServer();
|
|
142
|
+
server.once("error", () => {
|
|
143
|
+
server.close();
|
|
144
|
+
resolve(false);
|
|
145
|
+
});
|
|
146
|
+
server.once("listening", () => {
|
|
147
|
+
server.close();
|
|
148
|
+
resolve(true);
|
|
149
|
+
});
|
|
150
|
+
server.listen(port, "127.0.0.1");
|
|
151
|
+
});
|
|
152
|
+
};
|
|
153
|
+
/**
|
|
154
|
+
* 等待端口可用
|
|
155
|
+
* @param port - 端口号
|
|
156
|
+
* @param maxAttempts - 最大尝试次数
|
|
157
|
+
* @param interval - 检查间隔(ms)
|
|
158
|
+
* @returns 端口是否可用
|
|
159
|
+
*/
|
|
160
|
+
const waitPort = async (port, maxAttempts = 30, interval = 1e3) => {
|
|
161
|
+
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
162
|
+
if (await checkPort(port)) return true;
|
|
163
|
+
logger.debug(`端口 ${port} 被占用,等待释放... (${attempt + 1}/${maxAttempts})`);
|
|
164
|
+
await sleep(interval);
|
|
165
|
+
}
|
|
166
|
+
return false;
|
|
167
|
+
};
|
|
168
|
+
/**
|
|
169
|
+
* 结束指定PID或端口的程序
|
|
170
|
+
* @param identifier - PID号或端口号
|
|
171
|
+
* @param isPort - 是否为端口号
|
|
172
|
+
* @returns 是否成功结束程序
|
|
173
|
+
*/
|
|
174
|
+
const killApp = async (identifier, isPort = false) => {
|
|
175
|
+
const pid = isPort ? await getPid(Number(identifier)) : Number(identifier);
|
|
176
|
+
if (!pid) return false;
|
|
177
|
+
const { stderr } = await exec$1(isWin ? `taskkill /F /PID ${pid}` : `kill -9 ${pid}`);
|
|
178
|
+
if (stderr) return false;
|
|
179
|
+
return true;
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
//#endregion
|
|
183
|
+
//#region src/utils/common/uptime.ts
|
|
184
|
+
/**
|
|
185
|
+
* 获取运行时间
|
|
186
|
+
* @example
|
|
187
|
+
* ```ts
|
|
188
|
+
* uptime()
|
|
189
|
+
* // -> '1天2小时3分钟4秒'
|
|
190
|
+
* // -> '2小时3分钟4秒'
|
|
191
|
+
* // -> '3分钟4秒'
|
|
192
|
+
* // -> '4秒'
|
|
193
|
+
* ```
|
|
194
|
+
*/
|
|
195
|
+
const uptime = () => {
|
|
196
|
+
const time = process.uptime();
|
|
197
|
+
const day = Math.floor(time / 86400);
|
|
198
|
+
const hour = Math.floor(time % 86400 / 3600);
|
|
199
|
+
const min = Math.floor(time % 3600 / 60);
|
|
200
|
+
const sec = Math.floor(time % 60);
|
|
201
|
+
return [
|
|
202
|
+
day ? `${day}天` : "",
|
|
203
|
+
hour ? `${hour}小时` : "",
|
|
204
|
+
min ? `${min}分钟` : "",
|
|
205
|
+
!day && sec ? `${sec}秒` : ""
|
|
206
|
+
].filter(Boolean).join("");
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
//#endregion
|
|
210
|
+
export { sleep as a, isLinux as c, isWin as d, exec$1 as f, waitPort as i, isMac as l, stringifyError as m, checkPort as n, getPid as o, errorToString as p, killApp as r, isDocker as s, uptime as t, isRoot as u };
|
|
Binary file
|