node-karin 0.12.2-5.pr.206.027f2f2 → 0.12.2-5.pr.206.02ba956

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.
@@ -4,9 +4,7 @@
4
4
  ],
5
5
  "admin": [],
6
6
  "user": {
7
- "enable_list": [
8
- 1
9
- ],
7
+ "enable_list": [],
10
8
  "disable_list": []
11
9
  },
12
10
  "friend": {
@@ -0,0 +1,526 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ var fs2 = require('fs');
5
+ var url = require('url');
6
+ var path2 = require('path');
7
+ var child_process = require('child_process');
8
+ var dotenv = require('dotenv');
9
+ var commander = require('commander');
10
+
11
+ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
12
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
13
+
14
+ var fs2__default = /*#__PURE__*/_interopDefault(fs2);
15
+ var path2__default = /*#__PURE__*/_interopDefault(path2);
16
+ var dotenv__default = /*#__PURE__*/_interopDefault(dotenv);
17
+
18
+ var execSync = (cmd, options = {}) => {
19
+ try {
20
+ const result = child_process.execSync(cmd, options);
21
+ return { status: true, error: null, stdout: result.toString(), stderr: "" };
22
+ } catch (error) {
23
+ return { status: false, error, stdout: "", stderr: "" };
24
+ }
25
+ };
26
+ var exec = (cmd, options = {}) => {
27
+ return new Promise((resolve) => {
28
+ child_process.exec(cmd, options, (error, stdout, stderr) => {
29
+ const status = !error;
30
+ resolve({ status, error, stdout, stderr });
31
+ });
32
+ });
33
+ };
34
+ var pm2Dir = path2__default.default.join(process.cwd(), "./@karinjs/config/pm2.json");
35
+ var start = () => {
36
+ if (!fs2__default.default.existsSync(pm2Dir)) {
37
+ console.log(`[pm2] \u914D\u7F6E\u6587\u4EF6\u4E0D\u5B58\u5728 \u8BF7\u68C0\u67E5 ${pm2Dir} \u662F\u5426\u5B58\u5728`);
38
+ console.log("[pm2] \u5982\u679C\u662F\u65B0\u9879\u76EE\uFF0C\u8BF7\u5148\u524D\u53F0\u542F\u52A8\u751F\u6210\u914D\u7F6E\u6587\u4EF6: pnpm app");
39
+ process.exit(1);
40
+ }
41
+ console.log("[pm2] \u542F\u52A8\u4E2D...");
42
+ const { error } = execSync(`pm2 start ${pm2Dir}`, { cwd: process.cwd() });
43
+ if (error) {
44
+ console.log("[pm2] \u542F\u52A8\u5931\u8D25");
45
+ console.log(error);
46
+ process.exit(1);
47
+ }
48
+ console.log("[pm2] \u542F\u52A8\u6210\u529F");
49
+ console.log("[pm2] \u91CD\u542F\u670D\u52A1: pnpm rs");
50
+ console.log("[pm2] \u67E5\u770B\u65E5\u5FD7: pnpm log");
51
+ console.log("[pm2] \u505C\u6B62\u670D\u52A1: pnpm stop");
52
+ console.log("[pm2] \u67E5\u770B\u76D1\u63A7: pm2 monit");
53
+ console.log("[pm2] \u67E5\u770B\u5217\u8868: pm2 list");
54
+ process.exit(0);
55
+ };
56
+ var log = () => {
57
+ if (!fs2__default.default.existsSync(pm2Dir)) {
58
+ console.log(`[pm2] \u914D\u7F6E\u6587\u4EF6\u4E0D\u5B58\u5728 \u8BF7\u68C0\u67E5 ${pm2Dir} \u662F\u5426\u5B58\u5728`);
59
+ console.log("[pm2] \u5982\u679C\u662F\u65B0\u9879\u76EE\uFF0C\u8BF7\u5148\u524D\u53F0\u542F\u52A8\u751F\u6210\u914D\u7F6E\u6587\u4EF6: pnpm app");
60
+ process.exit(1);
61
+ }
62
+ const data = JSON.parse(fs2__default.default.readFileSync(pm2Dir, "utf-8"));
63
+ try {
64
+ const prefix = process.platform === "win32" ? "pm2.cmd" : "pm2";
65
+ child_process.spawn(prefix, ["logs", data.name, "--lines", data.lines || 1e3], { stdio: "inherit", shell: true });
66
+ } catch (error) {
67
+ console.error("[pm2] \u53D1\u751F\u672A\u77E5\u9519\u8BEF: \u8BF7\u68C0\u67E5pm2\u662F\u5426\u5B89\u88C5 \u3010npm install -g pm2\u3011");
68
+ console.error(error);
69
+ process.exit(1);
70
+ }
71
+ };
72
+ var stop = () => {
73
+ if (!fs2__default.default.existsSync(pm2Dir)) {
74
+ console.log(`[pm2] \u914D\u7F6E\u6587\u4EF6\u4E0D\u5B58\u5728 \u8BF7\u68C0\u67E5 ${pm2Dir} \u662F\u5426\u5B58\u5728`);
75
+ console.log("[pm2] \u5982\u679C\u662F\u65B0\u9879\u76EE\uFF0C\u8BF7\u5148\u524D\u53F0\u542F\u52A8\u751F\u6210\u914D\u7F6E\u6587\u4EF6: pnpm app");
76
+ process.exit(1);
77
+ }
78
+ const data = JSON.parse(fs2__default.default.readFileSync(pm2Dir, "utf-8"));
79
+ execSync(`pm2 stop ${data.name}`, { cwd: process.cwd() });
80
+ console.log("[pm2] \u505C\u6B62\u6210\u529F");
81
+ process.exit(0);
82
+ };
83
+ var restart = () => {
84
+ if (!fs2__default.default.existsSync(pm2Dir)) {
85
+ console.log(`[pm2] \u914D\u7F6E\u6587\u4EF6\u4E0D\u5B58\u5728 \u8BF7\u68C0\u67E5 ${pm2Dir} \u662F\u5426\u5B58\u5728`);
86
+ console.log("[pm2] \u5982\u679C\u662F\u65B0\u9879\u76EE\uFF0C\u8BF7\u5148\u524D\u53F0\u542F\u52A8\u751F\u6210\u914D\u7F6E\u6587\u4EF6: pnpm app");
87
+ process.exit(1);
88
+ }
89
+ };
90
+ var pm2 = {
91
+ start,
92
+ log,
93
+ stop,
94
+ restart
95
+ };
96
+ var dir = process.env.INIT_CWD || process.cwd();
97
+ var pkgDir = url.fileURLToPath(new url.URL("../..", (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))));
98
+ var createDir = () => {
99
+ const list = [
100
+ path2__default.default.join(dir, "logs"),
101
+ path2__default.default.join(dir, "plugins", "karin-plugin-example"),
102
+ path2__default.default.join(dir, "@karinjs", "config"),
103
+ path2__default.default.join(dir, "@karinjs", "data"),
104
+ path2__default.default.join(dir, "@karinjs", "temp", "console"),
105
+ path2__default.default.join(dir, "@karinjs", "temp", "html"),
106
+ path2__default.default.join(dir, "@karinjs", "resource")
107
+ ];
108
+ list.forEach((item) => {
109
+ if (!fs2__default.default.existsSync(item)) fs2__default.default.mkdirSync(item, { recursive: true });
110
+ });
111
+ };
112
+ var createPnpmFile = (dir2) => {
113
+ const pnpmfile = path2__default.default.join(dir2, ".pnpmfile.cjs");
114
+ if (fs2__default.default.existsSync(pnpmfile)) return;
115
+ const content = [
116
+ "// \u6E05\u7A7A\u5BF9\u7B49\u4F9D\u8D56\u4E2D\u7684node-karin",
117
+ "function readPackage (pkg, context) {",
118
+ " if (pkg?.['peerDependencies']?.['node-karin'] && pkg['peerDependencies']['node-karin'] !== 'file:./lib') {",
119
+ " delete pkg['peerDependencies']['node-karin']",
120
+ " }",
121
+ " return pkg",
122
+ "}",
123
+ "module.exports = {",
124
+ " hooks: {",
125
+ " readPackage",
126
+ " },",
127
+ "}"
128
+ ].join("\n");
129
+ fs2__default.default.writeFileSync(pnpmfile, content);
130
+ };
131
+ var shouldSkipNpmrc = () => {
132
+ const { stdout } = execSync("npm config get registry");
133
+ if (stdout.includes("registry.npmjs.org")) return true;
134
+ const { stdout: proxy } = execSync("npm config get proxy");
135
+ return !!proxy;
136
+ };
137
+ var createOrUpdateNpmrc = (dir2) => {
138
+ const list = [
139
+ "node_sqlite3_binary_host_mirror=https://registry.npmmirror.com/-/binary/sqlite3",
140
+ "better_sqlite3_binary_host_mirror=https://registry.npmmirror.com/-/binary/better-sqlite3",
141
+ "sass_binary_site=https://registry.npmmirror.com/-/binary/node-sass",
142
+ "sharp_binary_host=https://registry.npmmirror.com/-/binary/sharp",
143
+ "sharp_libvips_binary_host=https://registry.npmmirror.com/-/binary/sharp-libvips",
144
+ "canvas_binary_host_mirror=https://registry.npmmirror.com/-/binary/canvas",
145
+ "# 19\u4EE5\u4E0B\u7248\u672C",
146
+ "puppeteer_download_host=https://registry.npmmirror.com/mirrors",
147
+ "# 20\u4EE5\u4E0A\u7248\u672C",
148
+ "PUPPETEER_DOWNLOAD_BASE_URL = https://registry.npmmirror.com/binaries/chrome-for-testing"
149
+ ];
150
+ const npmrc = path2__default.default.join(dir2, ".npmrc");
151
+ if (!fs2__default.default.existsSync(npmrc)) {
152
+ fs2__default.default.writeFileSync(npmrc, list.join("\n"));
153
+ return;
154
+ }
155
+ const data = fs2__default.default.readFileSync(npmrc, "utf-8");
156
+ const newEntries = list.filter((item) => {
157
+ const key = item.split("=")[0];
158
+ return !data.includes(key);
159
+ });
160
+ if (newEntries.length > 0) {
161
+ fs2__default.default.appendFileSync(npmrc, "\n" + newEntries.join("\n"));
162
+ }
163
+ };
164
+ var createOrUpdateEnv = (dir2) => {
165
+ const generateRandomKey = () => {
166
+ const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
167
+ return Array.from({ length: 6 }, () => chars.charAt(Math.floor(Math.random() * chars.length))).join("");
168
+ };
169
+ const envData = [
170
+ "# \u662F\u5426\u542F\u7528HTTP",
171
+ "HTTP_ENABLE=true",
172
+ "# HTTP\u76D1\u542C\u7AEF\u53E3",
173
+ "HTTP_PORT=7777",
174
+ "# HTTP\u76D1\u542C\u5730\u5740",
175
+ "HTTP_HOST=0.0.0.0",
176
+ "# HTTP\u9274\u6743\u79D8\u94A5 \u4EC5\u7528\u4E8Ekarin\u81EA\u8EABApi",
177
+ `HTTP_AUTH_KEY=${generateRandomKey()}`,
178
+ "# ws_server\u9274\u6743\u79D8\u94A5",
179
+ `WS_SERVER_AUTH_KEY=${generateRandomKey()}`,
180
+ "\n",
181
+ "# \u662F\u5426\u542F\u7528Redis \u5173\u95ED\u540E\u5C06\u4F7F\u7528\u5185\u90E8\u865A\u62DFRedis",
182
+ "REDIS_ENABLE=true",
183
+ "# \u91CD\u542F\u662F\u5426\u8C03\u7528pm2 \u5982\u679C\u4E0D\u8C03\u7528\u5219\u4F1A\u76F4\u63A5\u5173\u673A \u6B64\u914D\u7F6E\u9002\u5408\u6709\u8FDB\u7A0B\u5B88\u62A4\u7684\u7A0B\u5E8F",
184
+ "PM2_RESTART=true",
185
+ "\n",
186
+ "# \u65E5\u5FD7\u7B49\u7EA7",
187
+ "LOG_LEVEL=info",
188
+ "# \u65E5\u5FD7\u4FDD\u7559\u5929\u6570",
189
+ "LOG_DAYS_TO_KEEP=7",
190
+ "# \u65E5\u5FD7\u6587\u4EF6\u6700\u5927\u5927\u5C0F \u5982\u679C\u6B64\u9879\u5927\u4E8E0\u5219\u542F\u7528\u65E5\u5FD7\u5206\u5272",
191
+ "LOG_MAX_LOG_SIZE=0",
192
+ "# logger.fnc\u989C\u8272",
193
+ 'LOG_FNC_COLOR="#E1D919"',
194
+ "\n",
195
+ "# ffmpeg",
196
+ "FFMPEG_PATH=",
197
+ "# ffprobe",
198
+ "FFPROBE_PATH=",
199
+ "# ffplay",
200
+ "FFPLAY_PATH=",
201
+ "\n",
202
+ "# \u8FD9\u91CC\u8BF7\u52FF\u4FEE\u6539",
203
+ "RUNTIME=node"
204
+ ];
205
+ const env = path2__default.default.join(dir2, ".env");
206
+ if (!fs2__default.default.existsSync(env)) {
207
+ fs2__default.default.writeFileSync(env, envData.join("\n"));
208
+ return;
209
+ }
210
+ const value = fs2__default.default.readFileSync(env, "utf-8");
211
+ const newEntries = envData.filter((item) => {
212
+ if (item.includes("#")) return false;
213
+ const key = item.split("=")[0];
214
+ return !value.includes(key);
215
+ });
216
+ if (newEntries.length > 0) {
217
+ fs2__default.default.appendFileSync(env, "\n" + newEntries.join("\n"));
218
+ }
219
+ };
220
+ var createWorkspace = (dir2) => {
221
+ const workspace = path2__default.default.join(dir2, "pnpm-workspace.yaml");
222
+ if (fs2__default.default.existsSync(workspace)) return;
223
+ const content = "packages:\n - 'plugins/**'\n";
224
+ fs2__default.default.writeFileSync(workspace, content);
225
+ };
226
+ var createOtherFile = async () => {
227
+ createPnpmFile(dir);
228
+ createWorkspace(dir);
229
+ if (!shouldSkipNpmrc()) {
230
+ createOrUpdateNpmrc(dir);
231
+ }
232
+ createOrUpdateEnv(dir);
233
+ };
234
+ var createConfig = () => {
235
+ const defCfg = path2__default.default.join(pkgDir, "default", "config");
236
+ const files = fs2__default.default.readdirSync(defCfg);
237
+ files.forEach((file) => {
238
+ if (!file.endsWith(".json")) return;
239
+ const filePath = path2__default.default.join(defCfg, file);
240
+ const targetPath = path2__default.default.join(dir, "@karinjs", "config");
241
+ const targetFile = path2__default.default.join(targetPath, file);
242
+ if (!fs2__default.default.existsSync(targetFile)) {
243
+ fs2__default.default.copyFileSync(filePath, targetFile);
244
+ return;
245
+ }
246
+ const defData = fs2__default.default.readFileSync(filePath, "utf-8");
247
+ const targetData = fs2__default.default.readFileSync(targetFile, "utf-8");
248
+ const mergedData = { ...JSON.parse(defData), ...JSON.parse(targetData) };
249
+ fs2__default.default.writeFileSync(targetFile, JSON.stringify(mergedData, null, 2));
250
+ });
251
+ };
252
+ var modifyPackageJson = () => {
253
+ const pkg = fs2__default.default.readFileSync(path2__default.default.join(dir, "package.json"), "utf-8");
254
+ const data = JSON.parse(pkg);
255
+ data.type = "module";
256
+ data.scripts.karin = "karin";
257
+ const list = [
258
+ "app",
259
+ "start",
260
+ "pm2",
261
+ "stop",
262
+ "rs",
263
+ "log",
264
+ "up",
265
+ "init",
266
+ "dev",
267
+ "ts",
268
+ "watch"
269
+ ];
270
+ list.forEach((v) => {
271
+ data.scripts[v] = `karin ${v}`;
272
+ });
273
+ fs2__default.default.writeFileSync(path2__default.default.join(dir, "package.json"), JSON.stringify(data, null, 2));
274
+ return data;
275
+ };
276
+ var init = async () => {
277
+ createDir();
278
+ await createOtherFile();
279
+ createConfig();
280
+ modifyPackageJson();
281
+ process.exit(0);
282
+ };
283
+ var parseEnvFiles = (env) => {
284
+ if (!env) return [".env"];
285
+ return env.split(",").map((file) => file.trim());
286
+ };
287
+ var loadEnv = (env) => {
288
+ const dir2 = process.cwd();
289
+ const files = parseEnvFiles(env);
290
+ if (!files.includes(".env")) {
291
+ files.unshift(".env");
292
+ }
293
+ files.forEach((file) => {
294
+ if (!fs2__default.default.existsSync(`${dir2}/${file}`)) {
295
+ if (file === ".env") {
296
+ console.error(`\u672A\u627E\u5230${file}\u6587\u4EF6\uFF0C\u8BF7\u4F7F\u7528 pnpm init \u8FDB\u884C\u521D\u59CB\u5316\u9879\u76EE`);
297
+ } else {
298
+ console.error(`\u672A\u627E\u5230${file}\u6587\u4EF6\uFF0C\u8BF7\u5C06\u5176\u653E\u7F6E\u5728\u9879\u76EE\u6839\u76EE\u5F55`);
299
+ }
300
+ process.exit(1);
301
+ }
302
+ });
303
+ const paths = files.map((file) => `${dir2}/${file}`);
304
+ dotenv__default.default.config({ path: paths, override: true });
305
+ };
306
+ var start2 = async (env) => {
307
+ loadEnv(env);
308
+ const index = "../root.js";
309
+ const { karinMain } = await import(index);
310
+ const child = child_process.fork(karinMain);
311
+ child.on("message", (message) => {
312
+ if (message === "restart") {
313
+ child.kill();
314
+ child.removeAllListeners();
315
+ start2(env);
316
+ }
317
+ });
318
+ child.on("exit", (code) => process.exit(code));
319
+ };
320
+ var dev = async (env) => {
321
+ loadEnv(env);
322
+ const index = "../root.js";
323
+ process.env.NODE_ENV = "development";
324
+ const { karinMain } = await import(index);
325
+ await import(url.pathToFileURL(karinMain).toString());
326
+ };
327
+ var tsStart = async (env) => {
328
+ loadEnv(env);
329
+ process.env.NODE_ENV = "development";
330
+ const index = "../root.js";
331
+ const { karinMain } = await import(index);
332
+ const child = child_process.spawn("npx", ["tsx", karinMain], {
333
+ env: {
334
+ ...process.env,
335
+ RUNTIME: "tsx"
336
+ },
337
+ stdio: "inherit",
338
+ shell: true
339
+ });
340
+ child.on("exit", (code) => process.exit(code ?? 0));
341
+ };
342
+ var tsWatch = async (options) => {
343
+ loadEnv(options.env);
344
+ process.env.NODE_ENV = "development";
345
+ const index = "../root.js";
346
+ const { karinMain } = await import(index);
347
+ const args = ["tsx", "watch"];
348
+ if (options.include) {
349
+ options.include.split(",").forEach((pattern) => {
350
+ args.push("--include", pattern.trim());
351
+ });
352
+ }
353
+ if (options.exclude) {
354
+ options.exclude.split(",").forEach((pattern) => {
355
+ args.push("--exclude", pattern.trim());
356
+ });
357
+ }
358
+ if (!options.clearScreen) {
359
+ args.push("--clear-screen=false");
360
+ }
361
+ args.push(karinMain);
362
+ const child = child_process.spawn("npx", args, {
363
+ env: {
364
+ ...process.env,
365
+ RUNTIME: "tsx",
366
+ TSX_WATCH: "true"
367
+ },
368
+ stdio: "inherit",
369
+ shell: true
370
+ });
371
+ child.on("exit", (code) => process.exit(code ?? 0));
372
+ };
373
+ var checkGitInstalled = async () => {
374
+ try {
375
+ const { status } = await exec("git --version");
376
+ return status;
377
+ } catch {
378
+ return false;
379
+ }
380
+ };
381
+ var updateDependencies = async (packagePath) => {
382
+ try {
383
+ const packageJson = JSON.parse(fs2__default.default.readFileSync(packagePath, "utf-8"));
384
+ const dependencies = packageJson.dependencies || {};
385
+ const packagesToUpdate = [];
386
+ const checkVersionTasks = Object.entries(dependencies).map(async ([pkg, version]) => {
387
+ if (pkg.startsWith("@types/")) {
388
+ return;
389
+ }
390
+ try {
391
+ const { stdout: pkgInfoStr } = await exec(`pnpm view ${pkg} --json`);
392
+ const pkgInfo = JSON.parse(pkgInfoStr.trim());
393
+ if (!pkgInfo.karin) return;
394
+ const currentVersion = version.replace(/[\^~]/g, "");
395
+ const { stdout: distTagsStr } = await exec(`pnpm view ${pkg} dist-tags --json`);
396
+ const distTags = JSON.parse(distTagsStr.trim());
397
+ const isPreRelease = /[-+]/.test(currentVersion);
398
+ const latestVersion = distTags.latest;
399
+ console.log(`[npm] ${pkg}:`);
400
+ console.log(` \u5F53\u524D\u7248\u672C: ${currentVersion}${isPreRelease ? " (\u9884\u53D1\u5E03\u7248\u672C)" : ""}`);
401
+ console.log(` \u6700\u65B0\u7248\u672C: ${latestVersion}`);
402
+ if (isPreRelease || currentVersion !== latestVersion) {
403
+ console.log(`[npm] \u53D1\u73B0\u65B0\u7248\u672C ${pkg}: ${currentVersion} -> ${latestVersion}`);
404
+ packagesToUpdate.push(`${pkg}@latest`);
405
+ } else {
406
+ console.log(`[npm] ${pkg} \u5DF2\u7ECF\u662F\u6700\u65B0\u7248\u672C`);
407
+ }
408
+ } catch (error) {
409
+ console.error(`[npm] \u68C0\u67E5 ${pkg} \u7248\u672C\u5931\u8D25:`, error);
410
+ }
411
+ });
412
+ await Promise.all(checkVersionTasks);
413
+ if (packagesToUpdate.length > 0) {
414
+ console.log("[npm] \u5F00\u59CB\u66F4\u65B0\u4EE5\u4E0B\u5305:\n", packagesToUpdate.join("\n"));
415
+ try {
416
+ const { status, error } = await exec(`pnpm update ${packagesToUpdate.join(" ")}`);
417
+ if (status) {
418
+ console.log("[npm] \u6240\u6709\u63D2\u4EF6\u66F4\u65B0\u5B8C\u6210");
419
+ } else {
420
+ console.error("[npm] \u6279\u91CF\u66F4\u65B0\u5931\u8D25:", error);
421
+ }
422
+ } catch (error) {
423
+ console.error("[npm] \u6279\u91CF\u66F4\u65B0\u5931\u8D25:", error);
424
+ }
425
+ } else {
426
+ console.log("[npm] \u6240\u6709\u63D2\u4EF6\u90FD\u5DF2\u7ECF\u662F\u6700\u65B0\u7248\u672C");
427
+ }
428
+ } catch (error) {
429
+ console.error("[npm] \u66F4\u65B0\u4F9D\u8D56\u5931\u8D25:", error);
430
+ }
431
+ };
432
+ var updatePlugins = async (pluginsPath) => {
433
+ if (!await checkGitInstalled()) {
434
+ console.error("[git] \u8BF7\u5148\u5B89\u88C5git");
435
+ return;
436
+ }
437
+ if (!fs2__default.default.existsSync(pluginsPath)) {
438
+ console.error("[git] plugins\u76EE\u5F55\u4E0D\u5B58\u5728");
439
+ return;
440
+ }
441
+ const isDirectory = (await fs2__default.default.promises.stat(pluginsPath)).isDirectory();
442
+ if (!isDirectory) {
443
+ console.error("[git] plugins\u8DEF\u5F84\u4E0D\u662F\u4E00\u4E2A\u76EE\u5F55");
444
+ return;
445
+ }
446
+ const dirs = await fs2__default.default.promises.readdir(pluginsPath);
447
+ const updateTasks = dirs.map(async (dir2) => {
448
+ const pluginPath = path2.join(pluginsPath, dir2);
449
+ const gitPath = path2.join(pluginPath, ".git");
450
+ const packageJsonPath = path2.join(pluginPath, "package.json");
451
+ if (!dir2.startsWith("karin-plugin-") || !(await fs2__default.default.promises.stat(pluginPath)).isDirectory()) {
452
+ return;
453
+ }
454
+ if (!fs2__default.default.existsSync(gitPath)) {
455
+ console.log(`[git] ${dir2} \u4E0D\u662Fgit\u4ED3\u5E93\uFF0C\u8DF3\u8FC7`);
456
+ return;
457
+ }
458
+ try {
459
+ const packageJson = JSON.parse(fs2__default.default.readFileSync(packageJsonPath, "utf-8"));
460
+ if (!packageJson.karin) {
461
+ console.log(`[git] ${dir2} \u7684package.json\u4E2D\u6CA1\u6709karin\u5B57\u6BB5\uFF0C\u8DF3\u8FC7`);
462
+ return;
463
+ }
464
+ console.log(`[git] \u6B63\u5728\u66F4\u65B0 ${dir2}...`);
465
+ const { status, error } = await exec("git pull", { cwd: pluginPath });
466
+ if (!status) {
467
+ console.error(`[git] \u66F4\u65B0 ${dir2} \u5931\u8D25:`, error);
468
+ }
469
+ } catch (error) {
470
+ console.error(`[git] \u66F4\u65B0 ${dir2} \u5931\u8D25:`, error);
471
+ }
472
+ });
473
+ await Promise.all(updateTasks);
474
+ };
475
+ var updateAll = async () => {
476
+ try {
477
+ console.log("[all] \u5F00\u59CB\u6267\u884C\u66F4\u65B0\u4EFB\u52A1\n");
478
+ await Promise.all([updateDependencies("./package.json"), updatePlugins("./plugins")]);
479
+ console.log("\n[all] \u66F4\u65B0\u4EFB\u52A1\u6267\u884C\u5B8C\u6210");
480
+ } finally {
481
+ process.exit(0);
482
+ }
483
+ };
484
+ var _a;
485
+ if (!((_a = process.argv) == null ? undefined : _a[2])) process.argv.push("-h");
486
+ var addEnvOption = (command) => {
487
+ return command.option("-e, --env <files>", "\u6307\u5B9A\u73AF\u5883\u53D8\u91CF\u6587\u4EF6\uFF0C\u591A\u4E2A\u6587\u4EF6\u7528\u9017\u53F7\u5206\u9694");
488
+ };
489
+ var getVersion = () => {
490
+ try {
491
+ const file = url.fileURLToPath(new URL("../../package.json", (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))));
492
+ const packageJson = JSON.parse(fs2__default.default.readFileSync(file, "utf-8"));
493
+ return packageJson.version;
494
+ } catch {
495
+ return "unknown";
496
+ }
497
+ };
498
+ commander.program.version(getVersion(), "-v, --version", "\u663E\u793A\u7248\u672C\u53F7");
499
+ commander.program.command("pm2").description("\u540E\u53F0\u8FD0\u884C").action(pm2.start);
500
+ commander.program.command("stop").description("\u505C\u6B62\u540E\u53F0\u8FD0\u884C").action(pm2.stop);
501
+ commander.program.command("rs").description("\u91CD\u542Fpm2\u670D\u52A1").action(pm2.restart);
502
+ commander.program.command("log").description("\u67E5\u770B\u65E5\u5FD7").action(pm2.log);
503
+ commander.program.command("up").description("\u66F4\u65B0\u63D2\u4EF6").action(updateAll);
504
+ commander.program.command("init").description("\u521D\u59CB\u5316\u9879\u76EE").action(init);
505
+ addEnvOption(commander.program.command(".").description("\u524D\u53F0\u542F\u52A8")).action((options) => start2(options.env));
506
+ addEnvOption(commander.program.command("app").description("\u524D\u53F0\u542F\u52A8")).action((options) => start2(options.env));
507
+ addEnvOption(commander.program.command("start").description("\u524D\u53F0\u542F\u52A8")).action((options) => start2(options.env));
508
+ addEnvOption(commander.program.command("dev").description("JavaScript\u5F00\u53D1\u6A21\u5F0F")).action((options) => dev(options.env));
509
+ addEnvOption(
510
+ commander.program.command("ts").description("TypeScript\u5F00\u53D1\u6A21\u5F0F").addHelpText("after", `
511
+ \u793A\u4F8B:
512
+ $ karin ts # \u4F7F\u7528\u9ED8\u8BA4 .env \u6587\u4EF6\u542F\u52A8
513
+ $ karin ts -e .env.dev # \u4F7F\u7528\u6307\u5B9A\u7684\u73AF\u5883\u53D8\u91CF\u6587\u4EF6\u542F\u52A8
514
+ $ karin ts -e .env.dev,.env.local # \u4F7F\u7528\u591A\u4E2A\u73AF\u5883\u53D8\u91CF\u6587\u4EF6\u542F\u52A8
515
+ `)
516
+ ).action((options) => tsStart(options.env));
517
+ addEnvOption(
518
+ commander.program.command("watch").description("TypeScript\u76D1\u89C6\u6A21\u5F0F").option("--include <patterns>", "\u6DFB\u52A0\u8981\u76D1\u89C6\u7684\u6587\u4EF6/\u76EE\u5F55\uFF0C\u591A\u4E2A\u7528\u9017\u53F7\u5206\u9694").option("--exclude <patterns>", "\u6392\u9664\u8981\u76D1\u89C6\u7684\u6587\u4EF6/\u76EE\u5F55\uFF0C\u591A\u4E2A\u7528\u9017\u53F7\u5206\u9694").option("--clear-screen", "\u91CD\u65B0\u8FD0\u884C\u65F6\u662F\u5426\u6E05\u5C4F", true).addHelpText("after", `
519
+ \u793A\u4F8B:
520
+ $ karin watch # \u9ED8\u8BA4\u76D1\u89C6\u6A21\u5F0F
521
+ $ karin watch --include src # \u76D1\u89C6 src \u76EE\u5F55
522
+ $ karin watch --exclude node_modules,dist # \u6392\u9664\u6307\u5B9A\u76EE\u5F55
523
+ $ karin watch --no-clear-screen # \u7981\u7528\u6E05\u5C4F
524
+ `)
525
+ ).action((options) => tsWatch(options));
526
+ commander.program.parse(process.argv);
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node
@@ -0,0 +1,517 @@
1
+ #!/usr/bin/env node
2
+ import fs2 from 'node:fs';
3
+ import { fileURLToPath, URL as URL$1, pathToFileURL } from 'node:url';
4
+ import path2, { join } from 'node:path';
5
+ import { fork, spawn, execSync as execSync$1, exec as exec$1 } from 'node:child_process';
6
+ import dotenv from 'dotenv';
7
+ import { program } from 'commander';
8
+
9
+ var execSync = (cmd, options = {}) => {
10
+ try {
11
+ const result = execSync$1(cmd, options);
12
+ return { status: true, error: null, stdout: result.toString(), stderr: "" };
13
+ } catch (error) {
14
+ return { status: false, error, stdout: "", stderr: "" };
15
+ }
16
+ };
17
+ var exec = (cmd, options = {}) => {
18
+ return new Promise((resolve) => {
19
+ exec$1(cmd, options, (error, stdout, stderr) => {
20
+ const status = !error;
21
+ resolve({ status, error, stdout, stderr });
22
+ });
23
+ });
24
+ };
25
+ var pm2Dir = path2.join(process.cwd(), "./@karinjs/config/pm2.json");
26
+ var start = () => {
27
+ if (!fs2.existsSync(pm2Dir)) {
28
+ console.log(`[pm2] \u914D\u7F6E\u6587\u4EF6\u4E0D\u5B58\u5728 \u8BF7\u68C0\u67E5 ${pm2Dir} \u662F\u5426\u5B58\u5728`);
29
+ console.log("[pm2] \u5982\u679C\u662F\u65B0\u9879\u76EE\uFF0C\u8BF7\u5148\u524D\u53F0\u542F\u52A8\u751F\u6210\u914D\u7F6E\u6587\u4EF6: pnpm app");
30
+ process.exit(1);
31
+ }
32
+ console.log("[pm2] \u542F\u52A8\u4E2D...");
33
+ const { error } = execSync(`pm2 start ${pm2Dir}`, { cwd: process.cwd() });
34
+ if (error) {
35
+ console.log("[pm2] \u542F\u52A8\u5931\u8D25");
36
+ console.log(error);
37
+ process.exit(1);
38
+ }
39
+ console.log("[pm2] \u542F\u52A8\u6210\u529F");
40
+ console.log("[pm2] \u91CD\u542F\u670D\u52A1: pnpm rs");
41
+ console.log("[pm2] \u67E5\u770B\u65E5\u5FD7: pnpm log");
42
+ console.log("[pm2] \u505C\u6B62\u670D\u52A1: pnpm stop");
43
+ console.log("[pm2] \u67E5\u770B\u76D1\u63A7: pm2 monit");
44
+ console.log("[pm2] \u67E5\u770B\u5217\u8868: pm2 list");
45
+ process.exit(0);
46
+ };
47
+ var log = () => {
48
+ if (!fs2.existsSync(pm2Dir)) {
49
+ console.log(`[pm2] \u914D\u7F6E\u6587\u4EF6\u4E0D\u5B58\u5728 \u8BF7\u68C0\u67E5 ${pm2Dir} \u662F\u5426\u5B58\u5728`);
50
+ console.log("[pm2] \u5982\u679C\u662F\u65B0\u9879\u76EE\uFF0C\u8BF7\u5148\u524D\u53F0\u542F\u52A8\u751F\u6210\u914D\u7F6E\u6587\u4EF6: pnpm app");
51
+ process.exit(1);
52
+ }
53
+ const data = JSON.parse(fs2.readFileSync(pm2Dir, "utf-8"));
54
+ try {
55
+ const prefix = process.platform === "win32" ? "pm2.cmd" : "pm2";
56
+ spawn(prefix, ["logs", data.name, "--lines", data.lines || 1e3], { stdio: "inherit", shell: true });
57
+ } catch (error) {
58
+ console.error("[pm2] \u53D1\u751F\u672A\u77E5\u9519\u8BEF: \u8BF7\u68C0\u67E5pm2\u662F\u5426\u5B89\u88C5 \u3010npm install -g pm2\u3011");
59
+ console.error(error);
60
+ process.exit(1);
61
+ }
62
+ };
63
+ var stop = () => {
64
+ if (!fs2.existsSync(pm2Dir)) {
65
+ console.log(`[pm2] \u914D\u7F6E\u6587\u4EF6\u4E0D\u5B58\u5728 \u8BF7\u68C0\u67E5 ${pm2Dir} \u662F\u5426\u5B58\u5728`);
66
+ console.log("[pm2] \u5982\u679C\u662F\u65B0\u9879\u76EE\uFF0C\u8BF7\u5148\u524D\u53F0\u542F\u52A8\u751F\u6210\u914D\u7F6E\u6587\u4EF6: pnpm app");
67
+ process.exit(1);
68
+ }
69
+ const data = JSON.parse(fs2.readFileSync(pm2Dir, "utf-8"));
70
+ execSync(`pm2 stop ${data.name}`, { cwd: process.cwd() });
71
+ console.log("[pm2] \u505C\u6B62\u6210\u529F");
72
+ process.exit(0);
73
+ };
74
+ var restart = () => {
75
+ if (!fs2.existsSync(pm2Dir)) {
76
+ console.log(`[pm2] \u914D\u7F6E\u6587\u4EF6\u4E0D\u5B58\u5728 \u8BF7\u68C0\u67E5 ${pm2Dir} \u662F\u5426\u5B58\u5728`);
77
+ console.log("[pm2] \u5982\u679C\u662F\u65B0\u9879\u76EE\uFF0C\u8BF7\u5148\u524D\u53F0\u542F\u52A8\u751F\u6210\u914D\u7F6E\u6587\u4EF6: pnpm app");
78
+ process.exit(1);
79
+ }
80
+ };
81
+ var pm2 = {
82
+ start,
83
+ log,
84
+ stop,
85
+ restart
86
+ };
87
+ var dir = process.env.INIT_CWD || process.cwd();
88
+ var pkgDir = fileURLToPath(new URL$1("../..", import.meta.url));
89
+ var createDir = () => {
90
+ const list = [
91
+ path2.join(dir, "logs"),
92
+ path2.join(dir, "plugins", "karin-plugin-example"),
93
+ path2.join(dir, "@karinjs", "config"),
94
+ path2.join(dir, "@karinjs", "data"),
95
+ path2.join(dir, "@karinjs", "temp", "console"),
96
+ path2.join(dir, "@karinjs", "temp", "html"),
97
+ path2.join(dir, "@karinjs", "resource")
98
+ ];
99
+ list.forEach((item) => {
100
+ if (!fs2.existsSync(item)) fs2.mkdirSync(item, { recursive: true });
101
+ });
102
+ };
103
+ var createPnpmFile = (dir2) => {
104
+ const pnpmfile = path2.join(dir2, ".pnpmfile.cjs");
105
+ if (fs2.existsSync(pnpmfile)) return;
106
+ const content = [
107
+ "// \u6E05\u7A7A\u5BF9\u7B49\u4F9D\u8D56\u4E2D\u7684node-karin",
108
+ "function readPackage (pkg, context) {",
109
+ " if (pkg?.['peerDependencies']?.['node-karin'] && pkg['peerDependencies']['node-karin'] !== 'file:./lib') {",
110
+ " delete pkg['peerDependencies']['node-karin']",
111
+ " }",
112
+ " return pkg",
113
+ "}",
114
+ "module.exports = {",
115
+ " hooks: {",
116
+ " readPackage",
117
+ " },",
118
+ "}"
119
+ ].join("\n");
120
+ fs2.writeFileSync(pnpmfile, content);
121
+ };
122
+ var shouldSkipNpmrc = () => {
123
+ const { stdout } = execSync("npm config get registry");
124
+ if (stdout.includes("registry.npmjs.org")) return true;
125
+ const { stdout: proxy } = execSync("npm config get proxy");
126
+ return !!proxy;
127
+ };
128
+ var createOrUpdateNpmrc = (dir2) => {
129
+ const list = [
130
+ "node_sqlite3_binary_host_mirror=https://registry.npmmirror.com/-/binary/sqlite3",
131
+ "better_sqlite3_binary_host_mirror=https://registry.npmmirror.com/-/binary/better-sqlite3",
132
+ "sass_binary_site=https://registry.npmmirror.com/-/binary/node-sass",
133
+ "sharp_binary_host=https://registry.npmmirror.com/-/binary/sharp",
134
+ "sharp_libvips_binary_host=https://registry.npmmirror.com/-/binary/sharp-libvips",
135
+ "canvas_binary_host_mirror=https://registry.npmmirror.com/-/binary/canvas",
136
+ "# 19\u4EE5\u4E0B\u7248\u672C",
137
+ "puppeteer_download_host=https://registry.npmmirror.com/mirrors",
138
+ "# 20\u4EE5\u4E0A\u7248\u672C",
139
+ "PUPPETEER_DOWNLOAD_BASE_URL = https://registry.npmmirror.com/binaries/chrome-for-testing"
140
+ ];
141
+ const npmrc = path2.join(dir2, ".npmrc");
142
+ if (!fs2.existsSync(npmrc)) {
143
+ fs2.writeFileSync(npmrc, list.join("\n"));
144
+ return;
145
+ }
146
+ const data = fs2.readFileSync(npmrc, "utf-8");
147
+ const newEntries = list.filter((item) => {
148
+ const key = item.split("=")[0];
149
+ return !data.includes(key);
150
+ });
151
+ if (newEntries.length > 0) {
152
+ fs2.appendFileSync(npmrc, "\n" + newEntries.join("\n"));
153
+ }
154
+ };
155
+ var createOrUpdateEnv = (dir2) => {
156
+ const generateRandomKey = () => {
157
+ const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
158
+ return Array.from({ length: 6 }, () => chars.charAt(Math.floor(Math.random() * chars.length))).join("");
159
+ };
160
+ const envData = [
161
+ "# \u662F\u5426\u542F\u7528HTTP",
162
+ "HTTP_ENABLE=true",
163
+ "# HTTP\u76D1\u542C\u7AEF\u53E3",
164
+ "HTTP_PORT=7777",
165
+ "# HTTP\u76D1\u542C\u5730\u5740",
166
+ "HTTP_HOST=0.0.0.0",
167
+ "# HTTP\u9274\u6743\u79D8\u94A5 \u4EC5\u7528\u4E8Ekarin\u81EA\u8EABApi",
168
+ `HTTP_AUTH_KEY=${generateRandomKey()}`,
169
+ "# ws_server\u9274\u6743\u79D8\u94A5",
170
+ `WS_SERVER_AUTH_KEY=${generateRandomKey()}`,
171
+ "\n",
172
+ "# \u662F\u5426\u542F\u7528Redis \u5173\u95ED\u540E\u5C06\u4F7F\u7528\u5185\u90E8\u865A\u62DFRedis",
173
+ "REDIS_ENABLE=true",
174
+ "# \u91CD\u542F\u662F\u5426\u8C03\u7528pm2 \u5982\u679C\u4E0D\u8C03\u7528\u5219\u4F1A\u76F4\u63A5\u5173\u673A \u6B64\u914D\u7F6E\u9002\u5408\u6709\u8FDB\u7A0B\u5B88\u62A4\u7684\u7A0B\u5E8F",
175
+ "PM2_RESTART=true",
176
+ "\n",
177
+ "# \u65E5\u5FD7\u7B49\u7EA7",
178
+ "LOG_LEVEL=info",
179
+ "# \u65E5\u5FD7\u4FDD\u7559\u5929\u6570",
180
+ "LOG_DAYS_TO_KEEP=7",
181
+ "# \u65E5\u5FD7\u6587\u4EF6\u6700\u5927\u5927\u5C0F \u5982\u679C\u6B64\u9879\u5927\u4E8E0\u5219\u542F\u7528\u65E5\u5FD7\u5206\u5272",
182
+ "LOG_MAX_LOG_SIZE=0",
183
+ "# logger.fnc\u989C\u8272",
184
+ 'LOG_FNC_COLOR="#E1D919"',
185
+ "\n",
186
+ "# ffmpeg",
187
+ "FFMPEG_PATH=",
188
+ "# ffprobe",
189
+ "FFPROBE_PATH=",
190
+ "# ffplay",
191
+ "FFPLAY_PATH=",
192
+ "\n",
193
+ "# \u8FD9\u91CC\u8BF7\u52FF\u4FEE\u6539",
194
+ "RUNTIME=node"
195
+ ];
196
+ const env = path2.join(dir2, ".env");
197
+ if (!fs2.existsSync(env)) {
198
+ fs2.writeFileSync(env, envData.join("\n"));
199
+ return;
200
+ }
201
+ const value = fs2.readFileSync(env, "utf-8");
202
+ const newEntries = envData.filter((item) => {
203
+ if (item.includes("#")) return false;
204
+ const key = item.split("=")[0];
205
+ return !value.includes(key);
206
+ });
207
+ if (newEntries.length > 0) {
208
+ fs2.appendFileSync(env, "\n" + newEntries.join("\n"));
209
+ }
210
+ };
211
+ var createWorkspace = (dir2) => {
212
+ const workspace = path2.join(dir2, "pnpm-workspace.yaml");
213
+ if (fs2.existsSync(workspace)) return;
214
+ const content = "packages:\n - 'plugins/**'\n";
215
+ fs2.writeFileSync(workspace, content);
216
+ };
217
+ var createOtherFile = async () => {
218
+ createPnpmFile(dir);
219
+ createWorkspace(dir);
220
+ if (!shouldSkipNpmrc()) {
221
+ createOrUpdateNpmrc(dir);
222
+ }
223
+ createOrUpdateEnv(dir);
224
+ };
225
+ var createConfig = () => {
226
+ const defCfg = path2.join(pkgDir, "default", "config");
227
+ const files = fs2.readdirSync(defCfg);
228
+ files.forEach((file) => {
229
+ if (!file.endsWith(".json")) return;
230
+ const filePath = path2.join(defCfg, file);
231
+ const targetPath = path2.join(dir, "@karinjs", "config");
232
+ const targetFile = path2.join(targetPath, file);
233
+ if (!fs2.existsSync(targetFile)) {
234
+ fs2.copyFileSync(filePath, targetFile);
235
+ return;
236
+ }
237
+ const defData = fs2.readFileSync(filePath, "utf-8");
238
+ const targetData = fs2.readFileSync(targetFile, "utf-8");
239
+ const mergedData = { ...JSON.parse(defData), ...JSON.parse(targetData) };
240
+ fs2.writeFileSync(targetFile, JSON.stringify(mergedData, null, 2));
241
+ });
242
+ };
243
+ var modifyPackageJson = () => {
244
+ const pkg = fs2.readFileSync(path2.join(dir, "package.json"), "utf-8");
245
+ const data = JSON.parse(pkg);
246
+ data.type = "module";
247
+ data.scripts.karin = "karin";
248
+ const list = [
249
+ "app",
250
+ "start",
251
+ "pm2",
252
+ "stop",
253
+ "rs",
254
+ "log",
255
+ "up",
256
+ "init",
257
+ "dev",
258
+ "ts",
259
+ "watch"
260
+ ];
261
+ list.forEach((v) => {
262
+ data.scripts[v] = `karin ${v}`;
263
+ });
264
+ fs2.writeFileSync(path2.join(dir, "package.json"), JSON.stringify(data, null, 2));
265
+ return data;
266
+ };
267
+ var init = async () => {
268
+ createDir();
269
+ await createOtherFile();
270
+ createConfig();
271
+ modifyPackageJson();
272
+ process.exit(0);
273
+ };
274
+ var parseEnvFiles = (env) => {
275
+ if (!env) return [".env"];
276
+ return env.split(",").map((file) => file.trim());
277
+ };
278
+ var loadEnv = (env) => {
279
+ const dir2 = process.cwd();
280
+ const files = parseEnvFiles(env);
281
+ if (!files.includes(".env")) {
282
+ files.unshift(".env");
283
+ }
284
+ files.forEach((file) => {
285
+ if (!fs2.existsSync(`${dir2}/${file}`)) {
286
+ if (file === ".env") {
287
+ console.error(`\u672A\u627E\u5230${file}\u6587\u4EF6\uFF0C\u8BF7\u4F7F\u7528 pnpm init \u8FDB\u884C\u521D\u59CB\u5316\u9879\u76EE`);
288
+ } else {
289
+ console.error(`\u672A\u627E\u5230${file}\u6587\u4EF6\uFF0C\u8BF7\u5C06\u5176\u653E\u7F6E\u5728\u9879\u76EE\u6839\u76EE\u5F55`);
290
+ }
291
+ process.exit(1);
292
+ }
293
+ });
294
+ const paths = files.map((file) => `${dir2}/${file}`);
295
+ dotenv.config({ path: paths, override: true });
296
+ };
297
+ var start2 = async (env) => {
298
+ loadEnv(env);
299
+ const index = "../root.js";
300
+ const { karinMain } = await import(index);
301
+ const child = fork(karinMain);
302
+ child.on("message", (message) => {
303
+ if (message === "restart") {
304
+ child.kill();
305
+ child.removeAllListeners();
306
+ start2(env);
307
+ }
308
+ });
309
+ child.on("exit", (code) => process.exit(code));
310
+ };
311
+ var dev = async (env) => {
312
+ loadEnv(env);
313
+ const index = "../root.js";
314
+ process.env.NODE_ENV = "development";
315
+ const { karinMain } = await import(index);
316
+ await import(pathToFileURL(karinMain).toString());
317
+ };
318
+ var tsStart = async (env) => {
319
+ loadEnv(env);
320
+ process.env.NODE_ENV = "development";
321
+ const index = "../root.js";
322
+ const { karinMain } = await import(index);
323
+ const child = spawn("npx", ["tsx", karinMain], {
324
+ env: {
325
+ ...process.env,
326
+ RUNTIME: "tsx"
327
+ },
328
+ stdio: "inherit",
329
+ shell: true
330
+ });
331
+ child.on("exit", (code) => process.exit(code ?? 0));
332
+ };
333
+ var tsWatch = async (options) => {
334
+ loadEnv(options.env);
335
+ process.env.NODE_ENV = "development";
336
+ const index = "../root.js";
337
+ const { karinMain } = await import(index);
338
+ const args = ["tsx", "watch"];
339
+ if (options.include) {
340
+ options.include.split(",").forEach((pattern) => {
341
+ args.push("--include", pattern.trim());
342
+ });
343
+ }
344
+ if (options.exclude) {
345
+ options.exclude.split(",").forEach((pattern) => {
346
+ args.push("--exclude", pattern.trim());
347
+ });
348
+ }
349
+ if (!options.clearScreen) {
350
+ args.push("--clear-screen=false");
351
+ }
352
+ args.push(karinMain);
353
+ const child = spawn("npx", args, {
354
+ env: {
355
+ ...process.env,
356
+ RUNTIME: "tsx",
357
+ TSX_WATCH: "true"
358
+ },
359
+ stdio: "inherit",
360
+ shell: true
361
+ });
362
+ child.on("exit", (code) => process.exit(code ?? 0));
363
+ };
364
+ var checkGitInstalled = async () => {
365
+ try {
366
+ const { status } = await exec("git --version");
367
+ return status;
368
+ } catch {
369
+ return false;
370
+ }
371
+ };
372
+ var updateDependencies = async (packagePath) => {
373
+ try {
374
+ const packageJson = JSON.parse(fs2.readFileSync(packagePath, "utf-8"));
375
+ const dependencies = packageJson.dependencies || {};
376
+ const packagesToUpdate = [];
377
+ const checkVersionTasks = Object.entries(dependencies).map(async ([pkg, version]) => {
378
+ if (pkg.startsWith("@types/")) {
379
+ return;
380
+ }
381
+ try {
382
+ const { stdout: pkgInfoStr } = await exec(`pnpm view ${pkg} --json`);
383
+ const pkgInfo = JSON.parse(pkgInfoStr.trim());
384
+ if (!pkgInfo.karin) return;
385
+ const currentVersion = version.replace(/[\^~]/g, "");
386
+ const { stdout: distTagsStr } = await exec(`pnpm view ${pkg} dist-tags --json`);
387
+ const distTags = JSON.parse(distTagsStr.trim());
388
+ const isPreRelease = /[-+]/.test(currentVersion);
389
+ const latestVersion = distTags.latest;
390
+ console.log(`[npm] ${pkg}:`);
391
+ console.log(` \u5F53\u524D\u7248\u672C: ${currentVersion}${isPreRelease ? " (\u9884\u53D1\u5E03\u7248\u672C)" : ""}`);
392
+ console.log(` \u6700\u65B0\u7248\u672C: ${latestVersion}`);
393
+ if (isPreRelease || currentVersion !== latestVersion) {
394
+ console.log(`[npm] \u53D1\u73B0\u65B0\u7248\u672C ${pkg}: ${currentVersion} -> ${latestVersion}`);
395
+ packagesToUpdate.push(`${pkg}@latest`);
396
+ } else {
397
+ console.log(`[npm] ${pkg} \u5DF2\u7ECF\u662F\u6700\u65B0\u7248\u672C`);
398
+ }
399
+ } catch (error) {
400
+ console.error(`[npm] \u68C0\u67E5 ${pkg} \u7248\u672C\u5931\u8D25:`, error);
401
+ }
402
+ });
403
+ await Promise.all(checkVersionTasks);
404
+ if (packagesToUpdate.length > 0) {
405
+ console.log("[npm] \u5F00\u59CB\u66F4\u65B0\u4EE5\u4E0B\u5305:\n", packagesToUpdate.join("\n"));
406
+ try {
407
+ const { status, error } = await exec(`pnpm update ${packagesToUpdate.join(" ")}`);
408
+ if (status) {
409
+ console.log("[npm] \u6240\u6709\u63D2\u4EF6\u66F4\u65B0\u5B8C\u6210");
410
+ } else {
411
+ console.error("[npm] \u6279\u91CF\u66F4\u65B0\u5931\u8D25:", error);
412
+ }
413
+ } catch (error) {
414
+ console.error("[npm] \u6279\u91CF\u66F4\u65B0\u5931\u8D25:", error);
415
+ }
416
+ } else {
417
+ console.log("[npm] \u6240\u6709\u63D2\u4EF6\u90FD\u5DF2\u7ECF\u662F\u6700\u65B0\u7248\u672C");
418
+ }
419
+ } catch (error) {
420
+ console.error("[npm] \u66F4\u65B0\u4F9D\u8D56\u5931\u8D25:", error);
421
+ }
422
+ };
423
+ var updatePlugins = async (pluginsPath) => {
424
+ if (!await checkGitInstalled()) {
425
+ console.error("[git] \u8BF7\u5148\u5B89\u88C5git");
426
+ return;
427
+ }
428
+ if (!fs2.existsSync(pluginsPath)) {
429
+ console.error("[git] plugins\u76EE\u5F55\u4E0D\u5B58\u5728");
430
+ return;
431
+ }
432
+ const isDirectory = (await fs2.promises.stat(pluginsPath)).isDirectory();
433
+ if (!isDirectory) {
434
+ console.error("[git] plugins\u8DEF\u5F84\u4E0D\u662F\u4E00\u4E2A\u76EE\u5F55");
435
+ return;
436
+ }
437
+ const dirs = await fs2.promises.readdir(pluginsPath);
438
+ const updateTasks = dirs.map(async (dir2) => {
439
+ const pluginPath = join(pluginsPath, dir2);
440
+ const gitPath = join(pluginPath, ".git");
441
+ const packageJsonPath = join(pluginPath, "package.json");
442
+ if (!dir2.startsWith("karin-plugin-") || !(await fs2.promises.stat(pluginPath)).isDirectory()) {
443
+ return;
444
+ }
445
+ if (!fs2.existsSync(gitPath)) {
446
+ console.log(`[git] ${dir2} \u4E0D\u662Fgit\u4ED3\u5E93\uFF0C\u8DF3\u8FC7`);
447
+ return;
448
+ }
449
+ try {
450
+ const packageJson = JSON.parse(fs2.readFileSync(packageJsonPath, "utf-8"));
451
+ if (!packageJson.karin) {
452
+ console.log(`[git] ${dir2} \u7684package.json\u4E2D\u6CA1\u6709karin\u5B57\u6BB5\uFF0C\u8DF3\u8FC7`);
453
+ return;
454
+ }
455
+ console.log(`[git] \u6B63\u5728\u66F4\u65B0 ${dir2}...`);
456
+ const { status, error } = await exec("git pull", { cwd: pluginPath });
457
+ if (!status) {
458
+ console.error(`[git] \u66F4\u65B0 ${dir2} \u5931\u8D25:`, error);
459
+ }
460
+ } catch (error) {
461
+ console.error(`[git] \u66F4\u65B0 ${dir2} \u5931\u8D25:`, error);
462
+ }
463
+ });
464
+ await Promise.all(updateTasks);
465
+ };
466
+ var updateAll = async () => {
467
+ try {
468
+ console.log("[all] \u5F00\u59CB\u6267\u884C\u66F4\u65B0\u4EFB\u52A1\n");
469
+ await Promise.all([updateDependencies("./package.json"), updatePlugins("./plugins")]);
470
+ console.log("\n[all] \u66F4\u65B0\u4EFB\u52A1\u6267\u884C\u5B8C\u6210");
471
+ } finally {
472
+ process.exit(0);
473
+ }
474
+ };
475
+ var _a;
476
+ if (!((_a = process.argv) == null ? undefined : _a[2])) process.argv.push("-h");
477
+ var addEnvOption = (command) => {
478
+ return command.option("-e, --env <files>", "\u6307\u5B9A\u73AF\u5883\u53D8\u91CF\u6587\u4EF6\uFF0C\u591A\u4E2A\u6587\u4EF6\u7528\u9017\u53F7\u5206\u9694");
479
+ };
480
+ var getVersion = () => {
481
+ try {
482
+ const file = fileURLToPath(new URL("../../package.json", import.meta.url));
483
+ const packageJson = JSON.parse(fs2.readFileSync(file, "utf-8"));
484
+ return packageJson.version;
485
+ } catch {
486
+ return "unknown";
487
+ }
488
+ };
489
+ program.version(getVersion(), "-v, --version", "\u663E\u793A\u7248\u672C\u53F7");
490
+ program.command("pm2").description("\u540E\u53F0\u8FD0\u884C").action(pm2.start);
491
+ program.command("stop").description("\u505C\u6B62\u540E\u53F0\u8FD0\u884C").action(pm2.stop);
492
+ program.command("rs").description("\u91CD\u542Fpm2\u670D\u52A1").action(pm2.restart);
493
+ program.command("log").description("\u67E5\u770B\u65E5\u5FD7").action(pm2.log);
494
+ program.command("up").description("\u66F4\u65B0\u63D2\u4EF6").action(updateAll);
495
+ program.command("init").description("\u521D\u59CB\u5316\u9879\u76EE").action(init);
496
+ addEnvOption(program.command(".").description("\u524D\u53F0\u542F\u52A8")).action((options) => start2(options.env));
497
+ addEnvOption(program.command("app").description("\u524D\u53F0\u542F\u52A8")).action((options) => start2(options.env));
498
+ addEnvOption(program.command("start").description("\u524D\u53F0\u542F\u52A8")).action((options) => start2(options.env));
499
+ addEnvOption(program.command("dev").description("JavaScript\u5F00\u53D1\u6A21\u5F0F")).action((options) => dev(options.env));
500
+ addEnvOption(
501
+ program.command("ts").description("TypeScript\u5F00\u53D1\u6A21\u5F0F").addHelpText("after", `
502
+ \u793A\u4F8B:
503
+ $ karin ts # \u4F7F\u7528\u9ED8\u8BA4 .env \u6587\u4EF6\u542F\u52A8
504
+ $ karin ts -e .env.dev # \u4F7F\u7528\u6307\u5B9A\u7684\u73AF\u5883\u53D8\u91CF\u6587\u4EF6\u542F\u52A8
505
+ $ karin ts -e .env.dev,.env.local # \u4F7F\u7528\u591A\u4E2A\u73AF\u5883\u53D8\u91CF\u6587\u4EF6\u542F\u52A8
506
+ `)
507
+ ).action((options) => tsStart(options.env));
508
+ addEnvOption(
509
+ program.command("watch").description("TypeScript\u76D1\u89C6\u6A21\u5F0F").option("--include <patterns>", "\u6DFB\u52A0\u8981\u76D1\u89C6\u7684\u6587\u4EF6/\u76EE\u5F55\uFF0C\u591A\u4E2A\u7528\u9017\u53F7\u5206\u9694").option("--exclude <patterns>", "\u6392\u9664\u8981\u76D1\u89C6\u7684\u6587\u4EF6/\u76EE\u5F55\uFF0C\u591A\u4E2A\u7528\u9017\u53F7\u5206\u9694").option("--clear-screen", "\u91CD\u65B0\u8FD0\u884C\u65F6\u662F\u5426\u6E05\u5C4F", true).addHelpText("after", `
510
+ \u793A\u4F8B:
511
+ $ karin watch # \u9ED8\u8BA4\u76D1\u89C6\u6A21\u5F0F
512
+ $ karin watch --include src # \u76D1\u89C6 src \u76EE\u5F55
513
+ $ karin watch --exclude node_modules,dist # \u6392\u9664\u6307\u5B9A\u76EE\u5F55
514
+ $ karin watch --no-clear-screen # \u7981\u7528\u6E05\u5C4F
515
+ `)
516
+ ).action((options) => tsWatch(options));
517
+ program.parse(process.argv);
package/dist/index.js CHANGED
@@ -408,8 +408,8 @@ var init_file = __esm({
408
408
  copyConfigSync = (defaulPath, userPath, suffixs = [], isThrow = false) => {
409
409
  try {
410
410
  const files = getFiles(defaulPath, suffixs);
411
- fs4.mkdirSync(userPath);
412
- fs4.mkdirSync(defaulPath);
411
+ fs4.mkdirSync(userPath, { recursive: true });
412
+ fs4.mkdirSync(defaulPath, { recursive: true });
413
413
  copyFilesSync(files, defaulPath, userPath);
414
414
  return true;
415
415
  } catch (error) {
@@ -2005,7 +2005,7 @@ var init_list = __esm({
2005
2005
  return;
2006
2006
  }
2007
2007
  if (type === "git" || type === "root") {
2008
- const file = path7.join(pluginDir, name);
2008
+ const file = type === "root" ? process.cwd() : path7.join(pluginDir, name);
2009
2009
  await getGitInfo(info, file, name, ext);
2010
2010
  return;
2011
2011
  }
@@ -2741,7 +2741,8 @@ var init_common = __esm({
2741
2741
  const config2 = typeof paramOrUrl === "string" ? { ...param, url: paramOrUrl, method: type } : paramOrUrl;
2742
2742
  return await Axios(config2);
2743
2743
  } catch (error) {
2744
- logger.trace(error.stack || error);
2744
+ logger.debug("[common] axios\u8BF7\u6C42\u5931\u8D25:");
2745
+ logger.debug(error.stack || error);
2745
2746
  return null;
2746
2747
  }
2747
2748
  };
@@ -3843,6 +3844,7 @@ var init_process = __esm({
3843
3844
  listeners.on("error", (...args) => {
3844
3845
  logger.error(...args);
3845
3846
  });
3847
+ if (process.env.pm_id) process.env.RUNTIME = "pm2";
3846
3848
  };
3847
3849
  checkProcess = async (port2) => {
3848
3850
  var _a, _b;
@@ -3862,8 +3864,8 @@ var init_process = __esm({
3862
3864
  if (((_b = data == null ? void 0 : data.data) == null ? void 0 : _b.pm2_id) === process.pid) {
3863
3865
  return;
3864
3866
  }
3867
+ logger.error("\u68C0\u6D4B\u5230\u540E\u53F0\u8FDB\u7A0B \u6B63\u5728\u5173\u95ED...");
3865
3868
  await axios3({ url: `${host2}/exit`, method: "get", timeout: 500 });
3866
- logger.mark(logger.red("\u68C0\u6D4B\u5230\u540E\u53F0\u8FDB\u7A0B \u6B63\u5728\u5173\u95ED..."));
3867
3869
  for (let i = 0; i < 100; i++) {
3868
3870
  const result = await axios3({ url: `${host2}/ping`, method: "get", timeout: 100 });
3869
3871
  if (result) {
@@ -3873,7 +3875,7 @@ var init_process = __esm({
3873
3875
  logger.mark(logger.green("\u540E\u53F0\u8FDB\u7A0B\u5DF2\u5173\u95ED"));
3874
3876
  return;
3875
3877
  }
3876
- logger.error(`\u540E\u53F0\u8FDB\u7A0B\u5173\u95ED\u5931\u8D25\uFF0C\u8BF7\u68C0\u67E5\u662F\u5426\u6709\u8FDB\u7A0B\u6B63\u5728\u5360\u7528\u7AEF\u53E3${port2}`);
3878
+ logger.error(logger.red(`\u540E\u53F0\u8FDB\u7A0B\u5173\u95ED\u5931\u8D25\uFF0C\u8BF7\u68C0\u67E5\u662F\u5426\u6709\u8FDB\u7A0B\u6B63\u5728\u5360\u7528\u7AEF\u53E3 ${port2} `));
3877
3879
  processExit(1);
3878
3880
  };
3879
3881
  processExit = async (code) => {
@@ -4452,9 +4454,9 @@ var init_router2 = __esm({
4452
4454
  });
4453
4455
 
4454
4456
  // src/server/app.ts
4457
+ import path12 from "node:path";
4455
4458
  import express2 from "express";
4456
4459
  import { createServer } from "node:http";
4457
- import path12 from "path";
4458
4460
  var app, server, listen;
4459
4461
  var init_app = __esm({
4460
4462
  "src/server/app.ts"() {
@@ -4462,15 +4464,20 @@ var init_app = __esm({
4462
4464
  init_esm_shims();
4463
4465
  init_router();
4464
4466
  init_router2();
4467
+ init_internal();
4465
4468
  app = express2();
4466
4469
  server = createServer(app);
4467
4470
  app.use("/web", express2.static(path12.join(process.cwd(), "web")));
4468
- app.use("/v1", router);
4469
4471
  app.use("/api/web", router2);
4472
+ app.use("/v1", router);
4470
4473
  listen = (port2, host2) => {
4471
4474
  server.listen(port2, host2, () => {
4472
4475
  logger.info(`[server] express \u5DF2\u542F\u52A8 \u6B63\u5728\u76D1\u542C: http://${host2}:${port2}`);
4473
4476
  });
4477
+ listeners.once("online", () => {
4478
+ console.log(`[server] http\u9274\u6743token: ${logger.green(process.env.HTTP_AUTH_KEY)}`);
4479
+ console.log(`[server] ws\u9274\u6743token: ${logger.green(process.env.WS_SERVER_AUTH_KEY)}`);
4480
+ });
4474
4481
  };
4475
4482
  }
4476
4483
  });
@@ -6205,6 +6212,7 @@ var init_groups2 = __esm({
6205
6212
  App.next = () => {
6206
6213
  next = true;
6207
6214
  };
6215
+ App.reply = App.e.reply.bind(App.e);
6208
6216
  const result = await App[plugin.file.method](App.e);
6209
6217
  if (next === false && result === false) next = true;
6210
6218
  }
@@ -6317,6 +6325,7 @@ var init_private = __esm({
6317
6325
  App.next = () => {
6318
6326
  next = true;
6319
6327
  };
6328
+ App.reply = App.e.reply.bind(App.e);
6320
6329
  const result = await App[plugin.file.method](App.e);
6321
6330
  if (next === false && result === false) next = true;
6322
6331
  }
@@ -8889,7 +8898,7 @@ import util from "node:util";
8889
8898
  var time = Date.now();
8890
8899
  var debugEnabled = false;
8891
8900
  var isDebugMode = () => {
8892
- return debugEnabled || process.env.NODE_ENV === "development" || process.argv.some((arg) => arg.includes("debug"));
8901
+ return debugEnabled || typeof process.env.DEBUG === "string" || process.argv.some((arg) => arg.includes("debug"));
8893
8902
  };
8894
8903
  var createDebug = (prefix) => {
8895
8904
  let color = (text2) => chalk.hex("#0cafff")(text2);
@@ -8943,7 +8952,7 @@ var initLogger = (options = {}) => {
8943
8952
  type: "console",
8944
8953
  layout: {
8945
8954
  type: "pattern",
8946
- pattern: `%[[Karin][%d{hh:mm:ss.SSS}][%4.4p]%] ${process.env.karin_dev === "dev" ? "[%f{3}:%l] " : ""}%m`
8955
+ pattern: `%[[Karin][%d{hh:mm:ss.SSS}][%4.4p]%] ${process.env.RUNTIME === "tsx" ? "[%f{3}:%l] " : ""}%m`
8947
8956
  }
8948
8957
  },
8949
8958
  overall: {
@@ -8970,7 +8979,7 @@ var initLogger = (options = {}) => {
8970
8979
  default: {
8971
8980
  appenders: ["overall", "console"],
8972
8981
  level: level2,
8973
- enableCallStack: process.env.karin_dev === "dev"
8982
+ enableCallStack: process.env.RUNTIME === "tsx"
8974
8983
  }
8975
8984
  },
8976
8985
  levels: {
@@ -9047,7 +9056,7 @@ var logger2 = createLogger({
9047
9056
  level: process.env.LOG_LEVEL || "info",
9048
9057
  daysToKeep: Number(process.env.LOG_DAYS_TO_KEEP) || 30,
9049
9058
  maxLogSize: Number(process.env.LOG_MAX_LOG_SIZE) || 0,
9050
- logColor: process.env.LOG_FORMAT || "#E1D919"
9059
+ logColor: process.env.LOG_FNC_COLOR || "#E1D919"
9051
9060
  }
9052
9061
  });
9053
9062
 
@@ -12387,7 +12396,6 @@ var Plugin = class {
12387
12396
  this.desc = options.desc || "\u65E0\u63CF\u8FF0";
12388
12397
  this.event = options.event || "message";
12389
12398
  this.priority = options.priority || 1e4;
12390
- this.reply = this.e.reply.bind(this.e);
12391
12399
  }
12392
12400
  /**
12393
12401
  * 快速回复合并转发
@@ -10,86 +10,6 @@ var express__default = /*#__PURE__*/_interopDefault(express);
10
10
 
11
11
 
12
12
 
13
- Object.defineProperty(exports, "Application", {
14
- enumerable: true,
15
- get: function () { return express.Application; }
16
- });
17
- Object.defineProperty(exports, "CookieOptions", {
18
- enumerable: true,
19
- get: function () { return express.CookieOptions; }
20
- });
21
- Object.defineProperty(exports, "Errback", {
22
- enumerable: true,
23
- get: function () { return express.Errback; }
24
- });
25
- Object.defineProperty(exports, "ErrorRequestHandler", {
26
- enumerable: true,
27
- get: function () { return express.ErrorRequestHandler; }
28
- });
29
- Object.defineProperty(exports, "Express", {
30
- enumerable: true,
31
- get: function () { return express.Express; }
32
- });
33
- Object.defineProperty(exports, "Handler", {
34
- enumerable: true,
35
- get: function () { return express.Handler; }
36
- });
37
- Object.defineProperty(exports, "IRoute", {
38
- enumerable: true,
39
- get: function () { return express.IRoute; }
40
- });
41
- Object.defineProperty(exports, "IRouter", {
42
- enumerable: true,
43
- get: function () { return express.IRouter; }
44
- });
45
- Object.defineProperty(exports, "IRouterHandler", {
46
- enumerable: true,
47
- get: function () { return express.IRouterHandler; }
48
- });
49
- Object.defineProperty(exports, "IRouterMatcher", {
50
- enumerable: true,
51
- get: function () { return express.IRouterMatcher; }
52
- });
53
- Object.defineProperty(exports, "Locals", {
54
- enumerable: true,
55
- get: function () { return express.Locals; }
56
- });
57
- Object.defineProperty(exports, "MediaType", {
58
- enumerable: true,
59
- get: function () { return express.MediaType; }
60
- });
61
- Object.defineProperty(exports, "NextFunction", {
62
- enumerable: true,
63
- get: function () { return express.NextFunction; }
64
- });
65
- Object.defineProperty(exports, "Request", {
66
- enumerable: true,
67
- get: function () { return express.Request; }
68
- });
69
- Object.defineProperty(exports, "RequestHandler", {
70
- enumerable: true,
71
- get: function () { return express.RequestHandler; }
72
- });
73
- Object.defineProperty(exports, "RequestParamHandler", {
74
- enumerable: true,
75
- get: function () { return express.RequestParamHandler; }
76
- });
77
- Object.defineProperty(exports, "Response", {
78
- enumerable: true,
79
- get: function () { return express.Response; }
80
- });
81
- Object.defineProperty(exports, "Router", {
82
- enumerable: true,
83
- get: function () { return express.Router; }
84
- });
85
- Object.defineProperty(exports, "RouterOptions", {
86
- enumerable: true,
87
- get: function () { return express.RouterOptions; }
88
- });
89
- Object.defineProperty(exports, "Send", {
90
- enumerable: true,
91
- get: function () { return express.Send; }
92
- });
93
13
  Object.defineProperty(exports, "default", {
94
14
  enumerable: true,
95
15
  get: function () { return express__default.default; }
@@ -1 +1 @@
1
- export { Application, CookieOptions, Errback, ErrorRequestHandler, Express, Handler, IRoute, IRouter, IRouterHandler, IRouterMatcher, Locals, MediaType, NextFunction, Request, RequestHandler, RequestParamHandler, Response, Router, RouterOptions, Send, default, json, query, raw, text } from 'express';
1
+ export { default, json, query, raw, text } from 'express';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-karin",
3
- "version": "0.12.25.pr.206.027f2f2",
3
+ "version": "0.12.25.pr.206.02ba956",
4
4
  "description": "Lightweight, efficient, concise, and stable robot framework.",
5
5
  "keywords": [
6
6
  "node",
@@ -26,6 +26,11 @@
26
26
  "type": "module",
27
27
  "main": "./dist/index.js",
28
28
  "types": "./dist/index.d.ts",
29
+ "bin": {
30
+ "k": "./dist/cli/index.cjs",
31
+ "karin": "./dist/cli/index.js",
32
+ "kr": "./dist/cli/index.cjs"
33
+ },
29
34
  "files": [
30
35
  "/dist/**/*.js",
31
36
  "/dist/**/*.cjs",
@@ -46,9 +51,11 @@
46
51
  "build:cli": "tsup --tsconfig tsconfig.cli.json --config tsup.cli.ts",
47
52
  "build:dev": "pnpm build && node cli/build.js -dev",
48
53
  "build:module": "tsup --tsconfig tsconfig.module.json --config tsup.modules.ts && node cli/module.js",
49
- "build:prod": "pnpm build:module && pnpm build && node cli/build.js",
54
+ "build:prod": "pnpm build:module && pnpm build:cli && pnpm build && node cli/build.js",
55
+ "cli": "node dist/cli/index.cjs",
50
56
  "debug": "node lib/index.js --debug",
51
57
  "dev": "tsx src/index.ts",
58
+ "dev:cli": "tsx exports/cli/index.ts",
52
59
  "dev:w": "tsx watch --include \"./src/**/*.ts\" src/index.ts",
53
60
  "dev:watch": "pnpm dev:w",
54
61
  "pr": "node cli/pr.js all",
@@ -59,24 +66,23 @@
59
66
  "dependencies": {
60
67
  "@types/express": "^5.0.0",
61
68
  "@types/lodash": "^4.17.10",
62
- "@types/node": "^22.5.0",
63
69
  "@types/node-schedule": "^2.1.7",
64
70
  "@types/ws": "^8.5.12",
65
71
  "art-template": "4.13.2",
66
72
  "axios": "1.7.9",
67
- "chalk": "5.3.0",
73
+ "chalk": "5.4.1",
68
74
  "chokidar": "3.6.0",
69
- "commander": "^12.1.0",
70
- "dotenv": "^16.0.0",
75
+ "commander": "^13.0.0",
76
+ "dotenv": "^16.4.7",
71
77
  "express": "4.21.2",
72
- "level": "8.0.1",
78
+ "level": "9.0.0",
73
79
  "lodash": "4.17.21",
74
80
  "log4js": "6.9.1",
75
81
  "moment": "2.30.1",
76
82
  "node-schedule": "2.1.1",
77
83
  "redis": "4.7.0",
78
84
  "ws": "8.18.0",
79
- "yaml": "2.5.0"
85
+ "yaml": "2.7.0"
80
86
  },
81
87
  "engines": {
82
88
  "node": ">=18"