node-karin 0.12.2-5.pr.206.e65b502 → 0.12.2-5.pr.206.f697b50

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": {
@@ -2,11 +2,10 @@
2
2
  'use strict';
3
3
 
4
4
  var fs2 = require('fs');
5
+ var url = require('url');
5
6
  var path2 = require('path');
6
7
  var child_process = require('child_process');
7
- var url = require('url');
8
8
  var dotenv = require('dotenv');
9
- var promises = require('fs/promises');
10
9
  var commander = require('commander');
11
10
 
12
11
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
@@ -16,7 +15,7 @@ var fs2__default = /*#__PURE__*/_interopDefault(fs2);
16
15
  var path2__default = /*#__PURE__*/_interopDefault(path2);
17
16
  var dotenv__default = /*#__PURE__*/_interopDefault(dotenv);
18
17
 
19
- var exec = (cmd, options = {}) => {
18
+ var execSync = (cmd, options = {}) => {
20
19
  try {
21
20
  const result = child_process.execSync(cmd, options);
22
21
  return { status: true, error: null, stdout: result.toString(), stderr: "" };
@@ -24,6 +23,14 @@ var exec = (cmd, options = {}) => {
24
23
  return { status: false, error, stdout: "", stderr: "" };
25
24
  }
26
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
+ };
27
34
  var pm2Dir = path2__default.default.join(process.cwd(), "./@karinjs/config/pm2.json");
28
35
  var start = () => {
29
36
  if (!fs2__default.default.existsSync(pm2Dir)) {
@@ -32,7 +39,7 @@ var start = () => {
32
39
  process.exit(1);
33
40
  }
34
41
  console.log("[pm2] \u542F\u52A8\u4E2D...");
35
- const { error } = exec(`pm2 start ${pm2Dir}`, { cwd: process.cwd() });
42
+ const { error } = execSync(`pm2 start ${pm2Dir}`, { cwd: process.cwd() });
36
43
  if (error) {
37
44
  console.log("[pm2] \u542F\u52A8\u5931\u8D25");
38
45
  console.log(error);
@@ -69,7 +76,7 @@ var stop = () => {
69
76
  process.exit(1);
70
77
  }
71
78
  const data = JSON.parse(fs2__default.default.readFileSync(pm2Dir, "utf-8"));
72
- exec(`pm2 stop ${data.name}`, { cwd: process.cwd() });
79
+ execSync(`pm2 stop ${data.name}`, { cwd: process.cwd() });
73
80
  console.log("[pm2] \u505C\u6B62\u6210\u529F");
74
81
  process.exit(0);
75
82
  };
@@ -122,9 +129,9 @@ var createPnpmFile = (dir2) => {
122
129
  fs2__default.default.writeFileSync(pnpmfile, content);
123
130
  };
124
131
  var shouldSkipNpmrc = () => {
125
- const { stdout } = exec("npm config get registry");
132
+ const { stdout } = execSync("npm config get registry");
126
133
  if (stdout.includes("registry.npmjs.org")) return true;
127
- const { stdout: proxy } = exec("npm config get proxy");
134
+ const { stdout: proxy } = execSync("npm config get proxy");
128
135
  return !!proxy;
129
136
  };
130
137
  var createOrUpdateNpmrc = (dir2) => {
@@ -210,28 +217,6 @@ var createOrUpdateEnv = (dir2) => {
210
217
  fs2__default.default.appendFileSync(env, "\n" + newEntries.join("\n"));
211
218
  }
212
219
  };
213
- var createOrUpdateEnvDev = (dir2) => {
214
- const envDevData = [
215
- "# \u662F\u5426\u4E3A\u5F00\u53D1\u73AF\u5883",
216
- "NODE_ENV=development",
217
- "# \u8FD0\u884C\u5668",
218
- "RUNTIME=tsx"
219
- ];
220
- const envDev = path2__default.default.join(dir2, ".env.dev");
221
- if (!fs2__default.default.existsSync(envDev)) {
222
- fs2__default.default.writeFileSync(envDev, envDevData.join("\n"));
223
- return;
224
- }
225
- const value = fs2__default.default.readFileSync(envDev, "utf-8");
226
- const newEntries = envDevData.filter((item) => {
227
- if (item.includes("#")) return false;
228
- const key = item.split("=")[0];
229
- return !value.includes(key);
230
- });
231
- if (newEntries.length > 0) {
232
- fs2__default.default.appendFileSync(envDev, "\n" + newEntries.join("\n"));
233
- }
234
- };
235
220
  var createWorkspace = (dir2) => {
236
221
  const workspace = path2__default.default.join(dir2, "pnpm-workspace.yaml");
237
222
  if (fs2__default.default.existsSync(workspace)) return;
@@ -245,7 +230,6 @@ var createOtherFile = async () => {
245
230
  createOrUpdateNpmrc(dir);
246
231
  }
247
232
  createOrUpdateEnv(dir);
248
- createOrUpdateEnvDev(dir);
249
233
  };
250
234
  var createConfig = () => {
251
235
  const defCfg = path2__default.default.join(pkgDir, "default", "config");
@@ -267,11 +251,27 @@ var createConfig = () => {
267
251
  };
268
252
  var modifyPackageJson = () => {
269
253
  const pkg = fs2__default.default.readFileSync(path2__default.default.join(dir, "package.json"), "utf-8");
270
- const pkgData = JSON.parse(pkg);
271
- if (pkgData.type === "module") return pkgData;
272
- pkgData.type = "module";
273
- fs2__default.default.writeFileSync(path2__default.default.join(dir, "package.json"), JSON.stringify(pkgData, null, 2));
274
- return pkgData;
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
275
  };
276
276
  var init = async () => {
277
277
  createDir();
@@ -280,21 +280,31 @@ var init = async () => {
280
280
  modifyPackageJson();
281
281
  process.exit(0);
282
282
  };
283
- var start2 = async (env = ".env") => {
283
+ var parseEnvFiles = (env) => {
284
+ if (!env) return [".env"];
285
+ return env.split(",").map((file) => file.trim());
286
+ };
287
+ var loadEnv = (env) => {
284
288
  const dir2 = process.cwd();
285
- const list = env === ".env" ? [".env"] : [".env", env];
286
- list.forEach((item) => {
287
- if (!fs2__default.default.existsSync(`${dir2}/${item}`)) {
288
- if (env === ".env") {
289
- console.error(`\u672A\u627E\u5230${item}\u6587\u4EF6\uFF0C\u8BF7\u4F7F\u7528 pnpm init \u8FDB\u884C\u521D\u59CB\u5316\u9879\u76EE`);
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`);
290
297
  } else {
291
- console.error(`\u672A\u627E\u5230${item}\u6587\u4EF6\uFF0C\u8BF7\u5C06\u5176\u653E\u7F6E\u5728\u9879\u76EE\u6839\u76EE\u5F55`);
298
+ console.error(`\u672A\u627E\u5230${file}\u6587\u4EF6\uFF0C\u8BF7\u5C06\u5176\u653E\u7F6E\u5728\u9879\u76EE\u6839\u76EE\u5F55`);
292
299
  }
293
300
  process.exit(1);
294
301
  }
295
302
  });
296
- const path3 = list.map((item) => `${dir2}/${item}`);
297
- dotenv__default.default.config({ path: path3, override: true });
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);
298
308
  const index = "../root.js";
299
309
  const { karinMain } = await import(index);
300
310
  const child = child_process.fork(karinMain);
@@ -307,106 +317,211 @@ var start2 = async (env = ".env") => {
307
317
  });
308
318
  child.on("exit", (code) => process.exit(code));
309
319
  };
310
- var checkGitInstalled = () => {
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 () => {
311
374
  try {
312
- child_process.execSync("git --version");
313
- return true;
375
+ const { status } = await exec("git --version");
376
+ return status;
314
377
  } catch {
315
378
  return false;
316
379
  }
317
380
  };
318
381
  var updateDependencies = async (packagePath) => {
319
382
  try {
320
- const packageJson = JSON.parse(fs2.readFileSync(packagePath, "utf-8"));
383
+ const packageJson = JSON.parse(fs2__default.default.readFileSync(packagePath, "utf-8"));
321
384
  const dependencies = packageJson.dependencies || {};
322
385
  const packagesToUpdate = [];
323
- for (const [pkg, version] of Object.entries(dependencies)) {
386
+ const checkVersionTasks = Object.entries(dependencies).map(async ([pkg, version]) => {
324
387
  if (pkg.startsWith("@types/")) {
325
- continue;
388
+ return;
326
389
  }
327
390
  try {
328
- const latestVersion = child_process.execSync(`pnpm view ${pkg} version`, { encoding: "utf-8" }).trim();
391
+ const { stdout: pkgInfoStr } = await exec(`pnpm view ${pkg} --json`);
392
+ const pkgInfo = JSON.parse(pkgInfoStr.trim());
393
+ if (!pkgInfo.karin) return;
329
394
  const currentVersion = version.replace(/[\^~]/g, "");
330
- if (latestVersion !== currentVersion) {
331
- console.log(`\u53D1\u73B0\u65B0\u7248\u672C ${pkg}: ${currentVersion} -> ${latestVersion}`);
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}`);
332
404
  packagesToUpdate.push(`${pkg}@latest`);
333
405
  } else {
334
- console.log(`${pkg} \u5DF2\u7ECF\u662F\u6700\u65B0\u7248\u672C`);
406
+ console.log(`[npm] ${pkg} \u5DF2\u7ECF\u662F\u6700\u65B0\u7248\u672C`);
335
407
  }
336
408
  } catch (error) {
337
- console.error(`\u68C0\u67E5 ${pkg} \u7248\u672C\u5931\u8D25:`, error);
409
+ console.error(`[npm] \u68C0\u67E5 ${pkg} \u7248\u672C\u5931\u8D25:`, error);
338
410
  }
339
- }
411
+ });
412
+ await Promise.all(checkVersionTasks);
340
413
  if (packagesToUpdate.length > 0) {
341
- console.log("\n\u5F00\u59CB\u66F4\u65B0\u4EE5\u4E0B\u5305:\n", packagesToUpdate.join("\n"));
414
+ console.log("[npm] \u5F00\u59CB\u66F4\u65B0\u4EE5\u4E0B\u5305:\n", packagesToUpdate.join("\n"));
342
415
  try {
343
- child_process.execSync(`pnpm update ${packagesToUpdate.join(" ")}`, {
344
- stdio: "inherit"
345
- });
346
- console.log("\n\u6240\u6709\u5305\u66F4\u65B0\u5B8C\u6210");
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
+ }
347
422
  } catch (error) {
348
- console.error("\u6279\u91CF\u66F4\u65B0\u5931\u8D25:", error);
423
+ console.error("[npm] \u6279\u91CF\u66F4\u65B0\u5931\u8D25:", error);
349
424
  }
350
425
  } else {
351
- console.log("\n\u6240\u6709\u5305\u90FD\u5DF2\u7ECF\u662F\u6700\u65B0\u7248\u672C");
426
+ console.log("[npm] \u6240\u6709\u63D2\u4EF6\u90FD\u5DF2\u7ECF\u662F\u6700\u65B0\u7248\u672C");
352
427
  }
353
428
  } catch (error) {
354
- console.error("\u66F4\u65B0\u4F9D\u8D56\u5931\u8D25:", error);
429
+ console.error("[npm] \u66F4\u65B0\u4F9D\u8D56\u5931\u8D25:", error);
355
430
  }
356
431
  };
357
432
  var updatePlugins = async (pluginsPath) => {
358
- if (!checkGitInstalled()) {
359
- console.error("\u8BF7\u5148\u5B89\u88C5git");
433
+ if (!await checkGitInstalled()) {
434
+ console.error("[git] \u8BF7\u5148\u5B89\u88C5git");
360
435
  return;
361
436
  }
362
- if (!fs2.existsSync(pluginsPath)) {
363
- console.error("plugins\u76EE\u5F55\u4E0D\u5B58\u5728");
437
+ if (!fs2__default.default.existsSync(pluginsPath)) {
438
+ console.error("[git] plugins\u76EE\u5F55\u4E0D\u5B58\u5728");
364
439
  return;
365
440
  }
366
- const isDirectory = (await promises.stat(pluginsPath)).isDirectory();
441
+ const isDirectory = (await fs2__default.default.promises.stat(pluginsPath)).isDirectory();
367
442
  if (!isDirectory) {
368
- console.error("plugins\u8DEF\u5F84\u4E0D\u662F\u4E00\u4E2A\u76EE\u5F55");
443
+ console.error("[git] plugins\u8DEF\u5F84\u4E0D\u662F\u4E00\u4E2A\u76EE\u5F55");
369
444
  return;
370
445
  }
371
- const dirs = await promises.readdir(pluginsPath);
372
- for (const dir2 of dirs) {
446
+ const dirs = await fs2__default.default.promises.readdir(pluginsPath);
447
+ const updateTasks = dirs.map(async (dir2) => {
373
448
  const pluginPath = path2.join(pluginsPath, dir2);
374
449
  const gitPath = path2.join(pluginPath, ".git");
375
450
  const packageJsonPath = path2.join(pluginPath, "package.json");
376
- if (!dir2.startsWith("karin-plugin-") || !(await promises.stat(pluginPath)).isDirectory()) {
377
- continue;
451
+ if (!dir2.startsWith("karin-plugin-") || !(await fs2__default.default.promises.stat(pluginPath)).isDirectory()) {
452
+ return;
378
453
  }
379
- if (!fs2.existsSync(gitPath)) {
380
- console.log(`${dir2} \u4E0D\u662Fgit\u4ED3\u5E93\uFF0C\u8DF3\u8FC7`);
381
- continue;
454
+ if (!fs2__default.default.existsSync(gitPath)) {
455
+ console.log(`[git] ${dir2} \u4E0D\u662Fgit\u4ED3\u5E93\uFF0C\u8DF3\u8FC7`);
456
+ return;
382
457
  }
383
458
  try {
384
- const packageJson = JSON.parse(fs2.readFileSync(packageJsonPath, "utf-8"));
459
+ const packageJson = JSON.parse(fs2__default.default.readFileSync(packageJsonPath, "utf-8"));
385
460
  if (!packageJson.karin) {
386
- console.log(`${dir2} \u7684package.json\u4E2D\u6CA1\u6709karin\u5B57\u6BB5\uFF0C\u8DF3\u8FC7`);
387
- continue;
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);
388
468
  }
389
- console.log(`\u6B63\u5728\u66F4\u65B0 ${dir2}...`);
390
- child_process.execSync("git pull", { cwd: pluginPath, stdio: "inherit" });
391
469
  } catch (error) {
392
- console.error(`\u66F4\u65B0 ${dir2} \u5931\u8D25:`, error);
470
+ console.error(`[git] \u66F4\u65B0 ${dir2} \u5931\u8D25:`, error);
393
471
  }
394
- }
472
+ });
473
+ await Promise.all(updateTasks);
395
474
  };
396
475
  var updateAll = async () => {
397
476
  try {
477
+ console.log("[all] \u5F00\u59CB\u6267\u884C\u66F4\u65B0\u4EFB\u52A1\n");
398
478
  await Promise.all([updateDependencies("./package.json"), updatePlugins("./plugins")]);
479
+ console.log("\n[all] \u66F4\u65B0\u4EFB\u52A1\u6267\u884C\u5B8C\u6210");
399
480
  } finally {
400
481
  process.exit(0);
401
482
  }
402
483
  };
403
- commander.program.version(process.env.npm_package_version, "-v, --version", "\u663E\u793A\u7248\u672C\u53F7");
404
- commander.program.command(".").description("\u524D\u53F0\u542F\u52A8").action(() => start2());
405
- commander.program.command("start").description("\u524D\u53F0\u542F\u52A8").action(() => start2());
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
+ if (process.env.npm_package_version) return process.env.npm_package_version;
491
+ try {
492
+ 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))));
493
+ const packageJson = JSON.parse(fs2__default.default.readFileSync(file, "utf-8"));
494
+ return packageJson.version;
495
+ } catch {
496
+ return "unknown";
497
+ }
498
+ };
499
+ commander.program.version(getVersion(), "-v, --version", "\u663E\u793A\u7248\u672C\u53F7");
406
500
  commander.program.command("pm2").description("\u540E\u53F0\u8FD0\u884C").action(pm2.start);
407
501
  commander.program.command("stop").description("\u505C\u6B62\u540E\u53F0\u8FD0\u884C").action(pm2.stop);
408
502
  commander.program.command("rs").description("\u91CD\u542Fpm2\u670D\u52A1").action(pm2.restart);
409
503
  commander.program.command("log").description("\u67E5\u770B\u65E5\u5FD7").action(pm2.log);
410
504
  commander.program.command("up").description("\u66F4\u65B0\u63D2\u4EF6").action(updateAll);
411
505
  commander.program.command("init").description("\u521D\u59CB\u5316\u9879\u76EE").action(init);
506
+ addEnvOption(commander.program.command(".").description("\u524D\u53F0\u542F\u52A8")).action((options) => start2(options.env));
507
+ addEnvOption(commander.program.command("app").description("\u524D\u53F0\u542F\u52A8")).action((options) => start2(options.env));
508
+ addEnvOption(commander.program.command("start").description("\u524D\u53F0\u542F\u52A8")).action((options) => start2(options.env));
509
+ addEnvOption(commander.program.command("dev").description("JavaScript\u5F00\u53D1\u6A21\u5F0F")).action((options) => dev(options.env));
510
+ addEnvOption(
511
+ commander.program.command("ts").description("TypeScript\u5F00\u53D1\u6A21\u5F0F").addHelpText("after", `
512
+ \u793A\u4F8B:
513
+ $ karin ts # \u4F7F\u7528\u9ED8\u8BA4 .env \u6587\u4EF6\u542F\u52A8
514
+ $ karin ts -e .env.dev # \u4F7F\u7528\u6307\u5B9A\u7684\u73AF\u5883\u53D8\u91CF\u6587\u4EF6\u542F\u52A8
515
+ $ karin ts -e .env.dev,.env.local # \u4F7F\u7528\u591A\u4E2A\u73AF\u5883\u53D8\u91CF\u6587\u4EF6\u542F\u52A8
516
+ `)
517
+ ).action((options) => tsStart(options.env));
518
+ addEnvOption(
519
+ 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", `
520
+ \u793A\u4F8B:
521
+ $ karin watch # \u9ED8\u8BA4\u76D1\u89C6\u6A21\u5F0F
522
+ $ karin watch --include src # \u76D1\u89C6 src \u76EE\u5F55
523
+ $ karin watch --exclude node_modules,dist # \u6392\u9664\u6307\u5B9A\u76EE\u5F55
524
+ $ karin watch --no-clear-screen # \u7981\u7528\u6E05\u5C4F
525
+ `)
526
+ ).action((options) => tsWatch(options));
412
527
  commander.program.parse(process.argv);
package/dist/cli/index.js CHANGED
@@ -1,16 +1,12 @@
1
1
  #!/usr/bin/env node
2
2
  import fs2 from 'node:fs';
3
- import path2 from 'node:path';
4
- import { fork, spawn, execSync as execSync$1 } from 'node:child_process';
5
- import { fileURLToPath, URL } from 'node:url';
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
6
  import dotenv from 'dotenv';
7
- import { join } from 'path';
8
- import { execSync } from 'child_process';
9
- import { readFileSync, existsSync } from 'fs';
10
- import { stat, readdir } from 'fs/promises';
11
7
  import { program } from 'commander';
12
8
 
13
- var exec = (cmd, options = {}) => {
9
+ var execSync = (cmd, options = {}) => {
14
10
  try {
15
11
  const result = execSync$1(cmd, options);
16
12
  return { status: true, error: null, stdout: result.toString(), stderr: "" };
@@ -18,6 +14,14 @@ var exec = (cmd, options = {}) => {
18
14
  return { status: false, error, stdout: "", stderr: "" };
19
15
  }
20
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
+ };
21
25
  var pm2Dir = path2.join(process.cwd(), "./@karinjs/config/pm2.json");
22
26
  var start = () => {
23
27
  if (!fs2.existsSync(pm2Dir)) {
@@ -26,7 +30,7 @@ var start = () => {
26
30
  process.exit(1);
27
31
  }
28
32
  console.log("[pm2] \u542F\u52A8\u4E2D...");
29
- const { error } = exec(`pm2 start ${pm2Dir}`, { cwd: process.cwd() });
33
+ const { error } = execSync(`pm2 start ${pm2Dir}`, { cwd: process.cwd() });
30
34
  if (error) {
31
35
  console.log("[pm2] \u542F\u52A8\u5931\u8D25");
32
36
  console.log(error);
@@ -63,7 +67,7 @@ var stop = () => {
63
67
  process.exit(1);
64
68
  }
65
69
  const data = JSON.parse(fs2.readFileSync(pm2Dir, "utf-8"));
66
- exec(`pm2 stop ${data.name}`, { cwd: process.cwd() });
70
+ execSync(`pm2 stop ${data.name}`, { cwd: process.cwd() });
67
71
  console.log("[pm2] \u505C\u6B62\u6210\u529F");
68
72
  process.exit(0);
69
73
  };
@@ -81,7 +85,7 @@ var pm2 = {
81
85
  restart
82
86
  };
83
87
  var dir = process.env.INIT_CWD || process.cwd();
84
- var pkgDir = fileURLToPath(new URL("../..", import.meta.url));
88
+ var pkgDir = fileURLToPath(new URL$1("../..", import.meta.url));
85
89
  var createDir = () => {
86
90
  const list = [
87
91
  path2.join(dir, "logs"),
@@ -116,9 +120,9 @@ var createPnpmFile = (dir2) => {
116
120
  fs2.writeFileSync(pnpmfile, content);
117
121
  };
118
122
  var shouldSkipNpmrc = () => {
119
- const { stdout } = exec("npm config get registry");
123
+ const { stdout } = execSync("npm config get registry");
120
124
  if (stdout.includes("registry.npmjs.org")) return true;
121
- const { stdout: proxy } = exec("npm config get proxy");
125
+ const { stdout: proxy } = execSync("npm config get proxy");
122
126
  return !!proxy;
123
127
  };
124
128
  var createOrUpdateNpmrc = (dir2) => {
@@ -204,28 +208,6 @@ var createOrUpdateEnv = (dir2) => {
204
208
  fs2.appendFileSync(env, "\n" + newEntries.join("\n"));
205
209
  }
206
210
  };
207
- var createOrUpdateEnvDev = (dir2) => {
208
- const envDevData = [
209
- "# \u662F\u5426\u4E3A\u5F00\u53D1\u73AF\u5883",
210
- "NODE_ENV=development",
211
- "# \u8FD0\u884C\u5668",
212
- "RUNTIME=tsx"
213
- ];
214
- const envDev = path2.join(dir2, ".env.dev");
215
- if (!fs2.existsSync(envDev)) {
216
- fs2.writeFileSync(envDev, envDevData.join("\n"));
217
- return;
218
- }
219
- const value = fs2.readFileSync(envDev, "utf-8");
220
- const newEntries = envDevData.filter((item) => {
221
- if (item.includes("#")) return false;
222
- const key = item.split("=")[0];
223
- return !value.includes(key);
224
- });
225
- if (newEntries.length > 0) {
226
- fs2.appendFileSync(envDev, "\n" + newEntries.join("\n"));
227
- }
228
- };
229
211
  var createWorkspace = (dir2) => {
230
212
  const workspace = path2.join(dir2, "pnpm-workspace.yaml");
231
213
  if (fs2.existsSync(workspace)) return;
@@ -239,7 +221,6 @@ var createOtherFile = async () => {
239
221
  createOrUpdateNpmrc(dir);
240
222
  }
241
223
  createOrUpdateEnv(dir);
242
- createOrUpdateEnvDev(dir);
243
224
  };
244
225
  var createConfig = () => {
245
226
  const defCfg = path2.join(pkgDir, "default", "config");
@@ -261,11 +242,27 @@ var createConfig = () => {
261
242
  };
262
243
  var modifyPackageJson = () => {
263
244
  const pkg = fs2.readFileSync(path2.join(dir, "package.json"), "utf-8");
264
- const pkgData = JSON.parse(pkg);
265
- if (pkgData.type === "module") return pkgData;
266
- pkgData.type = "module";
267
- fs2.writeFileSync(path2.join(dir, "package.json"), JSON.stringify(pkgData, null, 2));
268
- return pkgData;
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;
269
266
  };
270
267
  var init = async () => {
271
268
  createDir();
@@ -274,21 +271,31 @@ var init = async () => {
274
271
  modifyPackageJson();
275
272
  process.exit(0);
276
273
  };
277
- var start2 = async (env = ".env") => {
274
+ var parseEnvFiles = (env) => {
275
+ if (!env) return [".env"];
276
+ return env.split(",").map((file) => file.trim());
277
+ };
278
+ var loadEnv = (env) => {
278
279
  const dir2 = process.cwd();
279
- const list = env === ".env" ? [".env"] : [".env", env];
280
- list.forEach((item) => {
281
- if (!fs2.existsSync(`${dir2}/${item}`)) {
282
- if (env === ".env") {
283
- console.error(`\u672A\u627E\u5230${item}\u6587\u4EF6\uFF0C\u8BF7\u4F7F\u7528 pnpm init \u8FDB\u884C\u521D\u59CB\u5316\u9879\u76EE`);
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`);
284
288
  } else {
285
- console.error(`\u672A\u627E\u5230${item}\u6587\u4EF6\uFF0C\u8BF7\u5C06\u5176\u653E\u7F6E\u5728\u9879\u76EE\u6839\u76EE\u5F55`);
289
+ console.error(`\u672A\u627E\u5230${file}\u6587\u4EF6\uFF0C\u8BF7\u5C06\u5176\u653E\u7F6E\u5728\u9879\u76EE\u6839\u76EE\u5F55`);
286
290
  }
287
291
  process.exit(1);
288
292
  }
289
293
  });
290
- const path3 = list.map((item) => `${dir2}/${item}`);
291
- dotenv.config({ path: path3, override: true });
294
+ const paths = files.map((file) => `${dir2}/${file}`);
295
+ dotenv.config({ path: paths, override: true });
296
+ };
297
+ var start2 = async (env) => {
298
+ loadEnv(env);
292
299
  const index = "../root.js";
293
300
  const { karinMain } = await import(index);
294
301
  const child = fork(karinMain);
@@ -301,106 +308,211 @@ var start2 = async (env = ".env") => {
301
308
  });
302
309
  child.on("exit", (code) => process.exit(code));
303
310
  };
304
- var checkGitInstalled = () => {
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 () => {
305
365
  try {
306
- execSync("git --version");
307
- return true;
366
+ const { status } = await exec("git --version");
367
+ return status;
308
368
  } catch {
309
369
  return false;
310
370
  }
311
371
  };
312
372
  var updateDependencies = async (packagePath) => {
313
373
  try {
314
- const packageJson = JSON.parse(readFileSync(packagePath, "utf-8"));
374
+ const packageJson = JSON.parse(fs2.readFileSync(packagePath, "utf-8"));
315
375
  const dependencies = packageJson.dependencies || {};
316
376
  const packagesToUpdate = [];
317
- for (const [pkg, version] of Object.entries(dependencies)) {
377
+ const checkVersionTasks = Object.entries(dependencies).map(async ([pkg, version]) => {
318
378
  if (pkg.startsWith("@types/")) {
319
- continue;
379
+ return;
320
380
  }
321
381
  try {
322
- const latestVersion = execSync(`pnpm view ${pkg} version`, { encoding: "utf-8" }).trim();
382
+ const { stdout: pkgInfoStr } = await exec(`pnpm view ${pkg} --json`);
383
+ const pkgInfo = JSON.parse(pkgInfoStr.trim());
384
+ if (!pkgInfo.karin) return;
323
385
  const currentVersion = version.replace(/[\^~]/g, "");
324
- if (latestVersion !== currentVersion) {
325
- console.log(`\u53D1\u73B0\u65B0\u7248\u672C ${pkg}: ${currentVersion} -> ${latestVersion}`);
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}`);
326
395
  packagesToUpdate.push(`${pkg}@latest`);
327
396
  } else {
328
- console.log(`${pkg} \u5DF2\u7ECF\u662F\u6700\u65B0\u7248\u672C`);
397
+ console.log(`[npm] ${pkg} \u5DF2\u7ECF\u662F\u6700\u65B0\u7248\u672C`);
329
398
  }
330
399
  } catch (error) {
331
- console.error(`\u68C0\u67E5 ${pkg} \u7248\u672C\u5931\u8D25:`, error);
400
+ console.error(`[npm] \u68C0\u67E5 ${pkg} \u7248\u672C\u5931\u8D25:`, error);
332
401
  }
333
- }
402
+ });
403
+ await Promise.all(checkVersionTasks);
334
404
  if (packagesToUpdate.length > 0) {
335
- console.log("\n\u5F00\u59CB\u66F4\u65B0\u4EE5\u4E0B\u5305:\n", packagesToUpdate.join("\n"));
405
+ console.log("[npm] \u5F00\u59CB\u66F4\u65B0\u4EE5\u4E0B\u5305:\n", packagesToUpdate.join("\n"));
336
406
  try {
337
- execSync(`pnpm update ${packagesToUpdate.join(" ")}`, {
338
- stdio: "inherit"
339
- });
340
- console.log("\n\u6240\u6709\u5305\u66F4\u65B0\u5B8C\u6210");
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
+ }
341
413
  } catch (error) {
342
- console.error("\u6279\u91CF\u66F4\u65B0\u5931\u8D25:", error);
414
+ console.error("[npm] \u6279\u91CF\u66F4\u65B0\u5931\u8D25:", error);
343
415
  }
344
416
  } else {
345
- console.log("\n\u6240\u6709\u5305\u90FD\u5DF2\u7ECF\u662F\u6700\u65B0\u7248\u672C");
417
+ console.log("[npm] \u6240\u6709\u63D2\u4EF6\u90FD\u5DF2\u7ECF\u662F\u6700\u65B0\u7248\u672C");
346
418
  }
347
419
  } catch (error) {
348
- console.error("\u66F4\u65B0\u4F9D\u8D56\u5931\u8D25:", error);
420
+ console.error("[npm] \u66F4\u65B0\u4F9D\u8D56\u5931\u8D25:", error);
349
421
  }
350
422
  };
351
423
  var updatePlugins = async (pluginsPath) => {
352
- if (!checkGitInstalled()) {
353
- console.error("\u8BF7\u5148\u5B89\u88C5git");
424
+ if (!await checkGitInstalled()) {
425
+ console.error("[git] \u8BF7\u5148\u5B89\u88C5git");
354
426
  return;
355
427
  }
356
- if (!existsSync(pluginsPath)) {
357
- console.error("plugins\u76EE\u5F55\u4E0D\u5B58\u5728");
428
+ if (!fs2.existsSync(pluginsPath)) {
429
+ console.error("[git] plugins\u76EE\u5F55\u4E0D\u5B58\u5728");
358
430
  return;
359
431
  }
360
- const isDirectory = (await stat(pluginsPath)).isDirectory();
432
+ const isDirectory = (await fs2.promises.stat(pluginsPath)).isDirectory();
361
433
  if (!isDirectory) {
362
- console.error("plugins\u8DEF\u5F84\u4E0D\u662F\u4E00\u4E2A\u76EE\u5F55");
434
+ console.error("[git] plugins\u8DEF\u5F84\u4E0D\u662F\u4E00\u4E2A\u76EE\u5F55");
363
435
  return;
364
436
  }
365
- const dirs = await readdir(pluginsPath);
366
- for (const dir2 of dirs) {
437
+ const dirs = await fs2.promises.readdir(pluginsPath);
438
+ const updateTasks = dirs.map(async (dir2) => {
367
439
  const pluginPath = join(pluginsPath, dir2);
368
440
  const gitPath = join(pluginPath, ".git");
369
441
  const packageJsonPath = join(pluginPath, "package.json");
370
- if (!dir2.startsWith("karin-plugin-") || !(await stat(pluginPath)).isDirectory()) {
371
- continue;
442
+ if (!dir2.startsWith("karin-plugin-") || !(await fs2.promises.stat(pluginPath)).isDirectory()) {
443
+ return;
372
444
  }
373
- if (!existsSync(gitPath)) {
374
- console.log(`${dir2} \u4E0D\u662Fgit\u4ED3\u5E93\uFF0C\u8DF3\u8FC7`);
375
- continue;
445
+ if (!fs2.existsSync(gitPath)) {
446
+ console.log(`[git] ${dir2} \u4E0D\u662Fgit\u4ED3\u5E93\uFF0C\u8DF3\u8FC7`);
447
+ return;
376
448
  }
377
449
  try {
378
- const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
450
+ const packageJson = JSON.parse(fs2.readFileSync(packageJsonPath, "utf-8"));
379
451
  if (!packageJson.karin) {
380
- console.log(`${dir2} \u7684package.json\u4E2D\u6CA1\u6709karin\u5B57\u6BB5\uFF0C\u8DF3\u8FC7`);
381
- continue;
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);
382
459
  }
383
- console.log(`\u6B63\u5728\u66F4\u65B0 ${dir2}...`);
384
- execSync("git pull", { cwd: pluginPath, stdio: "inherit" });
385
460
  } catch (error) {
386
- console.error(`\u66F4\u65B0 ${dir2} \u5931\u8D25:`, error);
461
+ console.error(`[git] \u66F4\u65B0 ${dir2} \u5931\u8D25:`, error);
387
462
  }
388
- }
463
+ });
464
+ await Promise.all(updateTasks);
389
465
  };
390
466
  var updateAll = async () => {
391
467
  try {
468
+ console.log("[all] \u5F00\u59CB\u6267\u884C\u66F4\u65B0\u4EFB\u52A1\n");
392
469
  await Promise.all([updateDependencies("./package.json"), updatePlugins("./plugins")]);
470
+ console.log("\n[all] \u66F4\u65B0\u4EFB\u52A1\u6267\u884C\u5B8C\u6210");
393
471
  } finally {
394
472
  process.exit(0);
395
473
  }
396
474
  };
397
- program.version(process.env.npm_package_version, "-v, --version", "\u663E\u793A\u7248\u672C\u53F7");
398
- program.command(".").description("\u524D\u53F0\u542F\u52A8").action(() => start2());
399
- program.command("start").description("\u524D\u53F0\u542F\u52A8").action(() => start2());
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
+ if (process.env.npm_package_version) return process.env.npm_package_version;
482
+ try {
483
+ const file = fileURLToPath(new URL("../../package.json", import.meta.url));
484
+ const packageJson = JSON.parse(fs2.readFileSync(file, "utf-8"));
485
+ return packageJson.version;
486
+ } catch {
487
+ return "unknown";
488
+ }
489
+ };
490
+ program.version(getVersion(), "-v, --version", "\u663E\u793A\u7248\u672C\u53F7");
400
491
  program.command("pm2").description("\u540E\u53F0\u8FD0\u884C").action(pm2.start);
401
492
  program.command("stop").description("\u505C\u6B62\u540E\u53F0\u8FD0\u884C").action(pm2.stop);
402
493
  program.command("rs").description("\u91CD\u542Fpm2\u670D\u52A1").action(pm2.restart);
403
494
  program.command("log").description("\u67E5\u770B\u65E5\u5FD7").action(pm2.log);
404
495
  program.command("up").description("\u66F4\u65B0\u63D2\u4EF6").action(updateAll);
405
496
  program.command("init").description("\u521D\u59CB\u5316\u9879\u76EE").action(init);
497
+ addEnvOption(program.command(".").description("\u524D\u53F0\u542F\u52A8")).action((options) => start2(options.env));
498
+ addEnvOption(program.command("app").description("\u524D\u53F0\u542F\u52A8")).action((options) => start2(options.env));
499
+ addEnvOption(program.command("start").description("\u524D\u53F0\u542F\u52A8")).action((options) => start2(options.env));
500
+ addEnvOption(program.command("dev").description("JavaScript\u5F00\u53D1\u6A21\u5F0F")).action((options) => dev(options.env));
501
+ addEnvOption(
502
+ program.command("ts").description("TypeScript\u5F00\u53D1\u6A21\u5F0F").addHelpText("after", `
503
+ \u793A\u4F8B:
504
+ $ karin ts # \u4F7F\u7528\u9ED8\u8BA4 .env \u6587\u4EF6\u542F\u52A8
505
+ $ karin ts -e .env.dev # \u4F7F\u7528\u6307\u5B9A\u7684\u73AF\u5883\u53D8\u91CF\u6587\u4EF6\u542F\u52A8
506
+ $ karin ts -e .env.dev,.env.local # \u4F7F\u7528\u591A\u4E2A\u73AF\u5883\u53D8\u91CF\u6587\u4EF6\u542F\u52A8
507
+ `)
508
+ ).action((options) => tsStart(options.env));
509
+ addEnvOption(
510
+ 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", `
511
+ \u793A\u4F8B:
512
+ $ karin watch # \u9ED8\u8BA4\u76D1\u89C6\u6A21\u5F0F
513
+ $ karin watch --include src # \u76D1\u89C6 src \u76EE\u5F55
514
+ $ karin watch --exclude node_modules,dist # \u6392\u9664\u6307\u5B9A\u76EE\u5F55
515
+ $ karin watch --no-clear-screen # \u7981\u7528\u6E05\u5C4F
516
+ `)
517
+ ).action((options) => tsWatch(options));
406
518
  program.parse(process.argv);
package/dist/index.js CHANGED
@@ -3844,6 +3844,7 @@ var init_process = __esm({
3844
3844
  listeners.on("error", (...args) => {
3845
3845
  logger.error(...args);
3846
3846
  });
3847
+ if (process.env.pm_id) process.env.RUNTIME = "pm2";
3847
3848
  };
3848
3849
  checkProcess = async (port2) => {
3849
3850
  var _a, _b;
@@ -4453,9 +4454,9 @@ var init_router2 = __esm({
4453
4454
  });
4454
4455
 
4455
4456
  // src/server/app.ts
4457
+ import path12 from "node:path";
4456
4458
  import express2 from "express";
4457
4459
  import { createServer } from "node:http";
4458
- import path12 from "path";
4459
4460
  var app, server, listen;
4460
4461
  var init_app = __esm({
4461
4462
  "src/server/app.ts"() {
@@ -4463,6 +4464,7 @@ var init_app = __esm({
4463
4464
  init_esm_shims();
4464
4465
  init_router();
4465
4466
  init_router2();
4467
+ init_internal();
4466
4468
  app = express2();
4467
4469
  server = createServer(app);
4468
4470
  app.use("/web", express2.static(path12.join(process.cwd(), "web")));
@@ -4471,8 +4473,10 @@ var init_app = __esm({
4471
4473
  listen = (port2, host2) => {
4472
4474
  server.listen(port2, host2, () => {
4473
4475
  logger.info(`[server] express \u5DF2\u542F\u52A8 \u6B63\u5728\u76D1\u542C: http://${host2}:${port2}`);
4474
- console.log(logger.green(`[server] http\u9274\u6743token: ${process.env.HTTP_AUTH_KEY}`));
4475
- console.log(logger.green(`[server] ws\u9274\u6743token: ${process.env.WS_SERVER_AUTH_KEY}`));
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)}`);
4476
4480
  });
4477
4481
  };
4478
4482
  }
@@ -8892,7 +8896,7 @@ import util from "node:util";
8892
8896
  var time = Date.now();
8893
8897
  var debugEnabled = false;
8894
8898
  var isDebugMode = () => {
8895
- return debugEnabled || process.env.NODE_ENV === "development" || process.argv.some((arg) => arg.includes("debug"));
8899
+ return debugEnabled || typeof process.env.DEBUG === "string" || process.argv.some((arg) => arg.includes("debug"));
8896
8900
  };
8897
8901
  var createDebug = (prefix) => {
8898
8902
  let color = (text2) => chalk.hex("#0cafff")(text2);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-karin",
3
- "version": "0.12.25.pr.206.e65b502",
3
+ "version": "0.12.25.pr.206.f697b50",
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",
@@ -47,8 +52,10 @@
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
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"