node-karin 0.12.2-5.pr.206.dad353f → 0.12.2-5.pr.206.e09f093

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.
@@ -3,7 +3,7 @@
3
3
  "apps": [
4
4
  {
5
5
  "name": "karin",
6
- "script": "index.js",
6
+ "script": "./node_modules/node-karin/dist/cli/pm2.js",
7
7
  "autorestart": true,
8
8
  "max_restarts": 60,
9
9
  "max_memory_restart": "1G",
@@ -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;
@@ -40,6 +39,12 @@ var start = () => {
40
39
  process.exit(1);
41
40
  }
42
41
  console.log("[pm2] \u542F\u52A8\u4E2D...");
42
+ const data = JSON.parse(fs2__default.default.readFileSync(pm2Dir, "utf-8"));
43
+ const script = "./node_modules/node-karin/dist/cli/pm2.js";
44
+ if (data.apps[0].script !== script) {
45
+ data.apps[0].script = script;
46
+ fs2__default.default.writeFileSync(pm2Dir, JSON.stringify(data, null, 2));
47
+ }
43
48
  const { error } = execSync(`pm2 start ${pm2Dir}`, { cwd: process.cwd() });
44
49
  if (error) {
45
50
  console.log("[pm2] \u542F\u52A8\u5931\u8D25");
@@ -63,7 +68,7 @@ var log = () => {
63
68
  const data = JSON.parse(fs2__default.default.readFileSync(pm2Dir, "utf-8"));
64
69
  try {
65
70
  const prefix = process.platform === "win32" ? "pm2.cmd" : "pm2";
66
- child_process.spawn(prefix, ["logs", data.name, "--lines", data.lines || 1e3], { stdio: "inherit", shell: true });
71
+ child_process.spawn(prefix, ["logs", data.apps[0].name, "--lines", data.lines || 1e3], { stdio: "inherit", shell: true });
67
72
  } catch (error) {
68
73
  console.error("[pm2] \u53D1\u751F\u672A\u77E5\u9519\u8BEF: \u8BF7\u68C0\u67E5pm2\u662F\u5426\u5B89\u88C5 \u3010npm install -g pm2\u3011");
69
74
  console.error(error);
@@ -77,7 +82,7 @@ var stop = () => {
77
82
  process.exit(1);
78
83
  }
79
84
  const data = JSON.parse(fs2__default.default.readFileSync(pm2Dir, "utf-8"));
80
- execSync(`pm2 stop ${data.name}`, { cwd: process.cwd() });
85
+ execSync(`pm2 stop ${data.apps[0].name}`, { cwd: process.cwd() });
81
86
  console.log("[pm2] \u505C\u6B62\u6210\u529F");
82
87
  process.exit(0);
83
88
  };
@@ -218,28 +223,6 @@ var createOrUpdateEnv = (dir2) => {
218
223
  fs2__default.default.appendFileSync(env, "\n" + newEntries.join("\n"));
219
224
  }
220
225
  };
221
- var createOrUpdateEnvDev = (dir2) => {
222
- const envDevData = [
223
- "# \u662F\u5426\u4E3A\u5F00\u53D1\u73AF\u5883",
224
- "NODE_ENV=development",
225
- "# \u8FD0\u884C\u5668",
226
- "RUNTIME=tsx"
227
- ];
228
- const envDev = path2__default.default.join(dir2, ".env.dev");
229
- if (!fs2__default.default.existsSync(envDev)) {
230
- fs2__default.default.writeFileSync(envDev, envDevData.join("\n"));
231
- return;
232
- }
233
- const value = fs2__default.default.readFileSync(envDev, "utf-8");
234
- const newEntries = envDevData.filter((item) => {
235
- if (item.includes("#")) return false;
236
- const key = item.split("=")[0];
237
- return !value.includes(key);
238
- });
239
- if (newEntries.length > 0) {
240
- fs2__default.default.appendFileSync(envDev, "\n" + newEntries.join("\n"));
241
- }
242
- };
243
226
  var createWorkspace = (dir2) => {
244
227
  const workspace = path2__default.default.join(dir2, "pnpm-workspace.yaml");
245
228
  if (fs2__default.default.existsSync(workspace)) return;
@@ -253,7 +236,6 @@ var createOtherFile = async () => {
253
236
  createOrUpdateNpmrc(dir);
254
237
  }
255
238
  createOrUpdateEnv(dir);
256
- createOrUpdateEnvDev(dir);
257
239
  };
258
240
  var createConfig = () => {
259
241
  const defCfg = path2__default.default.join(pkgDir, "default", "config");
@@ -286,7 +268,10 @@ var modifyPackageJson = () => {
286
268
  "rs",
287
269
  "log",
288
270
  "up",
289
- "init"
271
+ "init",
272
+ "dev",
273
+ "ts",
274
+ "watch"
290
275
  ];
291
276
  list.forEach((v) => {
292
277
  data.scripts[v] = `karin ${v}`;
@@ -314,7 +299,7 @@ var loadEnv = (env) => {
314
299
  files.forEach((file) => {
315
300
  if (!fs2__default.default.existsSync(`${dir2}/${file}`)) {
316
301
  if (file === ".env") {
317
- console.error(`\u672A\u627E\u5230${file}\u6587\u4EF6\uFF0C\u8BF7\u4F7F\u7528 pnpm init \u8FDB\u884C\u521D\u59CB\u5316\u9879\u76EE`);
302
+ console.error(`\u672A\u627E\u5230${file}\u6587\u4EF6\uFF0C\u8BF7\u4F7F\u7528 npx karin init \u8FDB\u884C\u521D\u59CB\u5316\u9879\u76EE`);
318
303
  } else {
319
304
  console.error(`\u672A\u627E\u5230${file}\u6587\u4EF6\uFF0C\u8BF7\u5C06\u5176\u653E\u7F6E\u5728\u9879\u76EE\u6839\u76EE\u5F55`);
320
305
  }
@@ -343,21 +328,17 @@ var dev = async (env) => {
343
328
  const index = "../root.js";
344
329
  process.env.NODE_ENV = "development";
345
330
  const { karinMain } = await import(index);
346
- await import(karinMain);
331
+ await import(url.pathToFileURL(karinMain).toString());
347
332
  };
348
333
  var tsStart = async (env) => {
349
334
  loadEnv(env);
335
+ process.env.RUNTIME = "tsx";
350
336
  process.env.NODE_ENV = "development";
351
337
  const index = "../root.js";
352
338
  const { karinMain } = await import(index);
353
- const nodeOptions = process.env.NODE_OPTIONS ? `${process.env.NODE_OPTIONS} --import tsx` : "--import tsx";
354
- const child = child_process.spawn("node", [karinMain], {
355
- env: {
356
- ...process.env,
357
- NODE_OPTIONS: nodeOptions,
358
- RUNTIME: "tsx"
359
- },
360
- stdio: "inherit"
339
+ const child = child_process.spawn("npx", ["tsx", karinMain], {
340
+ stdio: "inherit",
341
+ shell: true
361
342
  });
362
343
  child.on("exit", (code) => process.exit(code ?? 0));
363
344
  };
@@ -381,12 +362,11 @@ var tsWatch = async (options) => {
381
362
  args.push("--clear-screen=false");
382
363
  }
383
364
  args.push(karinMain);
365
+ process.env.RUNTIME = "tsx";
366
+ process.env.TSX_WATCH = "true";
384
367
  const child = child_process.spawn("npx", args, {
385
- env: {
386
- ...process.env,
387
- RUNTIME: "tsx"
388
- },
389
- stdio: "inherit"
368
+ stdio: "inherit",
369
+ shell: true
390
370
  });
391
371
  child.on("exit", (code) => process.exit(code ?? 0));
392
372
  };
@@ -400,7 +380,7 @@ var checkGitInstalled = async () => {
400
380
  };
401
381
  var updateDependencies = async (packagePath) => {
402
382
  try {
403
- const packageJson = JSON.parse(fs2.readFileSync(packagePath, "utf-8"));
383
+ const packageJson = JSON.parse(fs2__default.default.readFileSync(packagePath, "utf-8"));
404
384
  const dependencies = packageJson.dependencies || {};
405
385
  const packagesToUpdate = [];
406
386
  const checkVersionTasks = Object.entries(dependencies).map(async ([pkg, version]) => {
@@ -454,29 +434,29 @@ var updatePlugins = async (pluginsPath) => {
454
434
  console.error("[git] \u8BF7\u5148\u5B89\u88C5git");
455
435
  return;
456
436
  }
457
- if (!fs2.existsSync(pluginsPath)) {
437
+ if (!fs2__default.default.existsSync(pluginsPath)) {
458
438
  console.error("[git] plugins\u76EE\u5F55\u4E0D\u5B58\u5728");
459
439
  return;
460
440
  }
461
- const isDirectory = (await promises.stat(pluginsPath)).isDirectory();
441
+ const isDirectory = (await fs2__default.default.promises.stat(pluginsPath)).isDirectory();
462
442
  if (!isDirectory) {
463
443
  console.error("[git] plugins\u8DEF\u5F84\u4E0D\u662F\u4E00\u4E2A\u76EE\u5F55");
464
444
  return;
465
445
  }
466
- const dirs = await promises.readdir(pluginsPath);
446
+ const dirs = await fs2__default.default.promises.readdir(pluginsPath);
467
447
  const updateTasks = dirs.map(async (dir2) => {
468
448
  const pluginPath = path2.join(pluginsPath, dir2);
469
449
  const gitPath = path2.join(pluginPath, ".git");
470
450
  const packageJsonPath = path2.join(pluginPath, "package.json");
471
- if (!dir2.startsWith("karin-plugin-") || !(await promises.stat(pluginPath)).isDirectory()) {
451
+ if (!dir2.startsWith("karin-plugin-") || !(await fs2__default.default.promises.stat(pluginPath)).isDirectory()) {
472
452
  return;
473
453
  }
474
- if (!fs2.existsSync(gitPath)) {
454
+ if (!fs2__default.default.existsSync(gitPath)) {
475
455
  console.log(`[git] ${dir2} \u4E0D\u662Fgit\u4ED3\u5E93\uFF0C\u8DF3\u8FC7`);
476
456
  return;
477
457
  }
478
458
  try {
479
- const packageJson = JSON.parse(fs2.readFileSync(packageJsonPath, "utf-8"));
459
+ const packageJson = JSON.parse(fs2__default.default.readFileSync(packageJsonPath, "utf-8"));
480
460
  if (!packageJson.karin) {
481
461
  console.log(`[git] ${dir2} \u7684package.json\u4E2D\u6CA1\u6709karin\u5B57\u6BB5\uFF0C\u8DF3\u8FC7`);
482
462
  return;
@@ -506,18 +486,28 @@ if (!((_a = process.argv) == null ? undefined : _a[2])) process.argv.push("-h");
506
486
  var addEnvOption = (command) => {
507
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");
508
488
  };
509
- commander.program.version(process.env.npm_package_version, "-v, --version", "\u663E\u793A\u7248\u672C\u53F7");
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");
510
499
  commander.program.command("pm2").description("\u540E\u53F0\u8FD0\u884C").action(pm2.start);
511
500
  commander.program.command("stop").description("\u505C\u6B62\u540E\u53F0\u8FD0\u884C").action(pm2.stop);
512
501
  commander.program.command("rs").description("\u91CD\u542Fpm2\u670D\u52A1").action(pm2.restart);
513
502
  commander.program.command("log").description("\u67E5\u770B\u65E5\u5FD7").action(pm2.log);
514
503
  commander.program.command("up").description("\u66F4\u65B0\u63D2\u4EF6").action(updateAll);
515
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));
516
506
  addEnvOption(commander.program.command("app").description("\u524D\u53F0\u542F\u52A8")).action((options) => start2(options.env));
517
507
  addEnvOption(commander.program.command("start").description("\u524D\u53F0\u542F\u52A8")).action((options) => start2(options.env));
518
508
  addEnvOption(commander.program.command("dev").description("JavaScript\u5F00\u53D1\u6A21\u5F0F")).action((options) => dev(options.env));
519
509
  addEnvOption(
520
- commander.program.command("ts").description("TypeScript\u5F00\u53D1\u6A21\u5F0F").option("-e, --env <files>", "\u6307\u5B9A\u73AF\u5883\u53D8\u91CF\u6587\u4EF6\uFF0C\u591A\u4E2A\u6587\u4EF6\u7528\u9017\u53F7\u5206\u9694\uFF0C\u4F8B\u5982\uFF1A.env.dev,.env.local").addHelpText("after", `
510
+ commander.program.command("ts").description("TypeScript\u5F00\u53D1\u6A21\u5F0F").addHelpText("after", `
521
511
  \u793A\u4F8B:
522
512
  $ karin ts # \u4F7F\u7528\u9ED8\u8BA4 .env \u6587\u4EF6\u542F\u52A8
523
513
  $ karin ts -e .env.dev # \u4F7F\u7528\u6307\u5B9A\u7684\u73AF\u5883\u53D8\u91CF\u6587\u4EF6\u542F\u52A8
package/dist/cli/index.js CHANGED
@@ -1,12 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
  import fs2 from 'node:fs';
3
- import path2 from 'node:path';
3
+ import { fileURLToPath, URL as URL$1, pathToFileURL } from 'node:url';
4
+ import path2, { join } from 'node:path';
4
5
  import { fork, spawn, execSync as execSync$1, exec as exec$1 } from 'node:child_process';
5
- import { fileURLToPath, URL } from 'node:url';
6
6
  import dotenv from 'dotenv';
7
- import { join } from 'path';
8
- import { readFileSync, existsSync } from 'fs';
9
- import { stat, readdir } from 'fs/promises';
10
7
  import { program } from 'commander';
11
8
 
12
9
  var execSync = (cmd, options = {}) => {
@@ -33,6 +30,12 @@ var start = () => {
33
30
  process.exit(1);
34
31
  }
35
32
  console.log("[pm2] \u542F\u52A8\u4E2D...");
33
+ const data = JSON.parse(fs2.readFileSync(pm2Dir, "utf-8"));
34
+ const script = "./node_modules/node-karin/dist/cli/pm2.js";
35
+ if (data.apps[0].script !== script) {
36
+ data.apps[0].script = script;
37
+ fs2.writeFileSync(pm2Dir, JSON.stringify(data, null, 2));
38
+ }
36
39
  const { error } = execSync(`pm2 start ${pm2Dir}`, { cwd: process.cwd() });
37
40
  if (error) {
38
41
  console.log("[pm2] \u542F\u52A8\u5931\u8D25");
@@ -56,7 +59,7 @@ var log = () => {
56
59
  const data = JSON.parse(fs2.readFileSync(pm2Dir, "utf-8"));
57
60
  try {
58
61
  const prefix = process.platform === "win32" ? "pm2.cmd" : "pm2";
59
- spawn(prefix, ["logs", data.name, "--lines", data.lines || 1e3], { stdio: "inherit", shell: true });
62
+ spawn(prefix, ["logs", data.apps[0].name, "--lines", data.lines || 1e3], { stdio: "inherit", shell: true });
60
63
  } catch (error) {
61
64
  console.error("[pm2] \u53D1\u751F\u672A\u77E5\u9519\u8BEF: \u8BF7\u68C0\u67E5pm2\u662F\u5426\u5B89\u88C5 \u3010npm install -g pm2\u3011");
62
65
  console.error(error);
@@ -70,7 +73,7 @@ var stop = () => {
70
73
  process.exit(1);
71
74
  }
72
75
  const data = JSON.parse(fs2.readFileSync(pm2Dir, "utf-8"));
73
- execSync(`pm2 stop ${data.name}`, { cwd: process.cwd() });
76
+ execSync(`pm2 stop ${data.apps[0].name}`, { cwd: process.cwd() });
74
77
  console.log("[pm2] \u505C\u6B62\u6210\u529F");
75
78
  process.exit(0);
76
79
  };
@@ -88,7 +91,7 @@ var pm2 = {
88
91
  restart
89
92
  };
90
93
  var dir = process.env.INIT_CWD || process.cwd();
91
- var pkgDir = fileURLToPath(new URL("../..", import.meta.url));
94
+ var pkgDir = fileURLToPath(new URL$1("../..", import.meta.url));
92
95
  var createDir = () => {
93
96
  const list = [
94
97
  path2.join(dir, "logs"),
@@ -211,28 +214,6 @@ var createOrUpdateEnv = (dir2) => {
211
214
  fs2.appendFileSync(env, "\n" + newEntries.join("\n"));
212
215
  }
213
216
  };
214
- var createOrUpdateEnvDev = (dir2) => {
215
- const envDevData = [
216
- "# \u662F\u5426\u4E3A\u5F00\u53D1\u73AF\u5883",
217
- "NODE_ENV=development",
218
- "# \u8FD0\u884C\u5668",
219
- "RUNTIME=tsx"
220
- ];
221
- const envDev = path2.join(dir2, ".env.dev");
222
- if (!fs2.existsSync(envDev)) {
223
- fs2.writeFileSync(envDev, envDevData.join("\n"));
224
- return;
225
- }
226
- const value = fs2.readFileSync(envDev, "utf-8");
227
- const newEntries = envDevData.filter((item) => {
228
- if (item.includes("#")) return false;
229
- const key = item.split("=")[0];
230
- return !value.includes(key);
231
- });
232
- if (newEntries.length > 0) {
233
- fs2.appendFileSync(envDev, "\n" + newEntries.join("\n"));
234
- }
235
- };
236
217
  var createWorkspace = (dir2) => {
237
218
  const workspace = path2.join(dir2, "pnpm-workspace.yaml");
238
219
  if (fs2.existsSync(workspace)) return;
@@ -246,7 +227,6 @@ var createOtherFile = async () => {
246
227
  createOrUpdateNpmrc(dir);
247
228
  }
248
229
  createOrUpdateEnv(dir);
249
- createOrUpdateEnvDev(dir);
250
230
  };
251
231
  var createConfig = () => {
252
232
  const defCfg = path2.join(pkgDir, "default", "config");
@@ -279,7 +259,10 @@ var modifyPackageJson = () => {
279
259
  "rs",
280
260
  "log",
281
261
  "up",
282
- "init"
262
+ "init",
263
+ "dev",
264
+ "ts",
265
+ "watch"
283
266
  ];
284
267
  list.forEach((v) => {
285
268
  data.scripts[v] = `karin ${v}`;
@@ -307,7 +290,7 @@ var loadEnv = (env) => {
307
290
  files.forEach((file) => {
308
291
  if (!fs2.existsSync(`${dir2}/${file}`)) {
309
292
  if (file === ".env") {
310
- console.error(`\u672A\u627E\u5230${file}\u6587\u4EF6\uFF0C\u8BF7\u4F7F\u7528 pnpm init \u8FDB\u884C\u521D\u59CB\u5316\u9879\u76EE`);
293
+ console.error(`\u672A\u627E\u5230${file}\u6587\u4EF6\uFF0C\u8BF7\u4F7F\u7528 npx karin init \u8FDB\u884C\u521D\u59CB\u5316\u9879\u76EE`);
311
294
  } else {
312
295
  console.error(`\u672A\u627E\u5230${file}\u6587\u4EF6\uFF0C\u8BF7\u5C06\u5176\u653E\u7F6E\u5728\u9879\u76EE\u6839\u76EE\u5F55`);
313
296
  }
@@ -336,21 +319,17 @@ var dev = async (env) => {
336
319
  const index = "../root.js";
337
320
  process.env.NODE_ENV = "development";
338
321
  const { karinMain } = await import(index);
339
- await import(karinMain);
322
+ await import(pathToFileURL(karinMain).toString());
340
323
  };
341
324
  var tsStart = async (env) => {
342
325
  loadEnv(env);
326
+ process.env.RUNTIME = "tsx";
343
327
  process.env.NODE_ENV = "development";
344
328
  const index = "../root.js";
345
329
  const { karinMain } = await import(index);
346
- const nodeOptions = process.env.NODE_OPTIONS ? `${process.env.NODE_OPTIONS} --import tsx` : "--import tsx";
347
- const child = spawn("node", [karinMain], {
348
- env: {
349
- ...process.env,
350
- NODE_OPTIONS: nodeOptions,
351
- RUNTIME: "tsx"
352
- },
353
- stdio: "inherit"
330
+ const child = spawn("npx", ["tsx", karinMain], {
331
+ stdio: "inherit",
332
+ shell: true
354
333
  });
355
334
  child.on("exit", (code) => process.exit(code ?? 0));
356
335
  };
@@ -374,12 +353,11 @@ var tsWatch = async (options) => {
374
353
  args.push("--clear-screen=false");
375
354
  }
376
355
  args.push(karinMain);
356
+ process.env.RUNTIME = "tsx";
357
+ process.env.TSX_WATCH = "true";
377
358
  const child = spawn("npx", args, {
378
- env: {
379
- ...process.env,
380
- RUNTIME: "tsx"
381
- },
382
- stdio: "inherit"
359
+ stdio: "inherit",
360
+ shell: true
383
361
  });
384
362
  child.on("exit", (code) => process.exit(code ?? 0));
385
363
  };
@@ -393,7 +371,7 @@ var checkGitInstalled = async () => {
393
371
  };
394
372
  var updateDependencies = async (packagePath) => {
395
373
  try {
396
- const packageJson = JSON.parse(readFileSync(packagePath, "utf-8"));
374
+ const packageJson = JSON.parse(fs2.readFileSync(packagePath, "utf-8"));
397
375
  const dependencies = packageJson.dependencies || {};
398
376
  const packagesToUpdate = [];
399
377
  const checkVersionTasks = Object.entries(dependencies).map(async ([pkg, version]) => {
@@ -447,29 +425,29 @@ var updatePlugins = async (pluginsPath) => {
447
425
  console.error("[git] \u8BF7\u5148\u5B89\u88C5git");
448
426
  return;
449
427
  }
450
- if (!existsSync(pluginsPath)) {
428
+ if (!fs2.existsSync(pluginsPath)) {
451
429
  console.error("[git] plugins\u76EE\u5F55\u4E0D\u5B58\u5728");
452
430
  return;
453
431
  }
454
- const isDirectory = (await stat(pluginsPath)).isDirectory();
432
+ const isDirectory = (await fs2.promises.stat(pluginsPath)).isDirectory();
455
433
  if (!isDirectory) {
456
434
  console.error("[git] plugins\u8DEF\u5F84\u4E0D\u662F\u4E00\u4E2A\u76EE\u5F55");
457
435
  return;
458
436
  }
459
- const dirs = await readdir(pluginsPath);
437
+ const dirs = await fs2.promises.readdir(pluginsPath);
460
438
  const updateTasks = dirs.map(async (dir2) => {
461
439
  const pluginPath = join(pluginsPath, dir2);
462
440
  const gitPath = join(pluginPath, ".git");
463
441
  const packageJsonPath = join(pluginPath, "package.json");
464
- if (!dir2.startsWith("karin-plugin-") || !(await stat(pluginPath)).isDirectory()) {
442
+ if (!dir2.startsWith("karin-plugin-") || !(await fs2.promises.stat(pluginPath)).isDirectory()) {
465
443
  return;
466
444
  }
467
- if (!existsSync(gitPath)) {
445
+ if (!fs2.existsSync(gitPath)) {
468
446
  console.log(`[git] ${dir2} \u4E0D\u662Fgit\u4ED3\u5E93\uFF0C\u8DF3\u8FC7`);
469
447
  return;
470
448
  }
471
449
  try {
472
- const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
450
+ const packageJson = JSON.parse(fs2.readFileSync(packageJsonPath, "utf-8"));
473
451
  if (!packageJson.karin) {
474
452
  console.log(`[git] ${dir2} \u7684package.json\u4E2D\u6CA1\u6709karin\u5B57\u6BB5\uFF0C\u8DF3\u8FC7`);
475
453
  return;
@@ -499,18 +477,28 @@ if (!((_a = process.argv) == null ? undefined : _a[2])) process.argv.push("-h");
499
477
  var addEnvOption = (command) => {
500
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");
501
479
  };
502
- program.version(process.env.npm_package_version, "-v, --version", "\u663E\u793A\u7248\u672C\u53F7");
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");
503
490
  program.command("pm2").description("\u540E\u53F0\u8FD0\u884C").action(pm2.start);
504
491
  program.command("stop").description("\u505C\u6B62\u540E\u53F0\u8FD0\u884C").action(pm2.stop);
505
492
  program.command("rs").description("\u91CD\u542Fpm2\u670D\u52A1").action(pm2.restart);
506
493
  program.command("log").description("\u67E5\u770B\u65E5\u5FD7").action(pm2.log);
507
494
  program.command("up").description("\u66F4\u65B0\u63D2\u4EF6").action(updateAll);
508
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));
509
497
  addEnvOption(program.command("app").description("\u524D\u53F0\u542F\u52A8")).action((options) => start2(options.env));
510
498
  addEnvOption(program.command("start").description("\u524D\u53F0\u542F\u52A8")).action((options) => start2(options.env));
511
499
  addEnvOption(program.command("dev").description("JavaScript\u5F00\u53D1\u6A21\u5F0F")).action((options) => dev(options.env));
512
500
  addEnvOption(
513
- program.command("ts").description("TypeScript\u5F00\u53D1\u6A21\u5F0F").option("-e, --env <files>", "\u6307\u5B9A\u73AF\u5883\u53D8\u91CF\u6587\u4EF6\uFF0C\u591A\u4E2A\u6587\u4EF6\u7528\u9017\u53F7\u5206\u9694\uFF0C\u4F8B\u5982\uFF1A.env.dev,.env.local").addHelpText("after", `
501
+ program.command("ts").description("TypeScript\u5F00\u53D1\u6A21\u5F0F").addHelpText("after", `
514
502
  \u793A\u4F8B:
515
503
  $ karin ts # \u4F7F\u7528\u9ED8\u8BA4 .env \u6587\u4EF6\u542F\u52A8
516
504
  $ karin ts -e .env.dev # \u4F7F\u7528\u6307\u5B9A\u7684\u73AF\u5883\u53D8\u91CF\u6587\u4EF6\u542F\u52A8
@@ -0,0 +1 @@
1
+ import 'node-karin'
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
  }
@@ -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;
@@ -4072,6 +4073,7 @@ var loader_exports = {};
4072
4073
  __export(loader_exports, {
4073
4074
  LoaderPlugin: () => LoaderPlugin
4074
4075
  });
4076
+ import fs14 from "node:fs";
4075
4077
  import lodash5 from "lodash";
4076
4078
  import path11 from "node:path";
4077
4079
  import util2 from "node:util";
@@ -4126,11 +4128,15 @@ var init_loader = __esm({
4126
4128
  if (pkg3.type !== "app") {
4127
4129
  if (isTsx() && ((_c = (_b = pkg3 == null ? void 0 : pkg3.pkgData) == null ? void 0 : _b.karin) == null ? void 0 : _c.main)) {
4128
4130
  const file = path11.join(pkg3.dir, pkg3.pkgData.karin.main);
4129
- entryPromises.push(this.loaderMain(pkg3.name, file));
4131
+ if (fs14.existsSync(file)) {
4132
+ entryPromises.push(this.loaderMain(pkg3.name, file));
4133
+ }
4130
4134
  }
4131
4135
  if ((_d = pkg3 == null ? void 0 : pkg3.pkgData) == null ? void 0 : _d.main) {
4132
4136
  const file = path11.join(pkg3.dir, pkg3.pkgData.main);
4133
- entryPromises.push(this.loaderMain(pkg3.name, file));
4137
+ if (fs14.existsSync(file)) {
4138
+ entryPromises.push(this.loaderMain(pkg3.name, file));
4139
+ }
4134
4140
  }
4135
4141
  }
4136
4142
  if (pkg3.type !== "app" && ((_f = (_e = pkg3 == null ? void 0 : pkg3.pkgData) == null ? void 0 : _e.karin) == null ? void 0 : _f.static)) {
@@ -4453,9 +4459,9 @@ var init_router2 = __esm({
4453
4459
  });
4454
4460
 
4455
4461
  // src/server/app.ts
4462
+ import path12 from "node:path";
4456
4463
  import express2 from "express";
4457
4464
  import { createServer } from "node:http";
4458
- import path12 from "path";
4459
4465
  var app, server, listen;
4460
4466
  var init_app = __esm({
4461
4467
  "src/server/app.ts"() {
@@ -4463,6 +4469,7 @@ var init_app = __esm({
4463
4469
  init_esm_shims();
4464
4470
  init_router();
4465
4471
  init_router2();
4472
+ init_internal();
4466
4473
  app = express2();
4467
4474
  server = createServer(app);
4468
4475
  app.use("/web", express2.static(path12.join(process.cwd(), "web")));
@@ -4471,6 +4478,8 @@ var init_app = __esm({
4471
4478
  listen = (port2, host2) => {
4472
4479
  server.listen(port2, host2, () => {
4473
4480
  logger.info(`[server] express \u5DF2\u542F\u52A8 \u6B63\u5728\u76D1\u542C: http://${host2}:${port2}`);
4481
+ });
4482
+ listeners.once("online", () => {
4474
4483
  console.log(`[server] http\u9274\u6743token: ${logger.green(process.env.HTTP_AUTH_KEY)}`);
4475
4484
  console.log(`[server] ws\u9274\u6743token: ${logger.green(process.env.WS_SERVER_AUTH_KEY)}`);
4476
4485
  });
@@ -4550,7 +4559,7 @@ var init_ip = __esm({
4550
4559
  });
4551
4560
 
4552
4561
  // src/server/api/console.ts
4553
- import fs14 from "node:fs";
4562
+ import fs15 from "node:fs";
4554
4563
  import path13 from "node:path";
4555
4564
  var consoleRouter;
4556
4565
  var init_console = __esm({
@@ -4591,11 +4600,11 @@ var init_console = __esm({
4591
4600
  }
4592
4601
  }
4593
4602
  const file = path13.join(consolePath, name);
4594
- if (!fs14.existsSync(file)) {
4603
+ if (!fs15.existsSync(file)) {
4595
4604
  res.status(404).json({ error: "\u6587\u4EF6\u4E0D\u5B58\u5728", message: "\u6587\u4EF6\u4E0D\u5B58\u5728" });
4596
4605
  return;
4597
4606
  }
4598
- const data = fs14.readFileSync(file);
4607
+ const data = fs15.readFileSync(file);
4599
4608
  if (!data) {
4600
4609
  res.status(500).json({ error: "\u5185\u90E8\u9519\u8BEF", message: "\u8BFB\u53D6\u5931\u8D25" });
4601
4610
  return;
@@ -6208,6 +6217,7 @@ var init_groups2 = __esm({
6208
6217
  App.next = () => {
6209
6218
  next = true;
6210
6219
  };
6220
+ App.reply = App.e.reply.bind(App.e);
6211
6221
  const result = await App[plugin.file.method](App.e);
6212
6222
  if (next === false && result === false) next = true;
6213
6223
  }
@@ -6320,6 +6330,7 @@ var init_private = __esm({
6320
6330
  App.next = () => {
6321
6331
  next = true;
6322
6332
  };
6333
+ App.reply = App.e.reply.bind(App.e);
6323
6334
  const result = await App[plugin.file.method](App.e);
6324
6335
  if (next === false && result === false) next = true;
6325
6336
  }
@@ -8503,7 +8514,7 @@ var init_event = __esm({
8503
8514
  });
8504
8515
 
8505
8516
  // src/adapter/input/index.ts
8506
- import fs15 from "node:fs";
8517
+ import fs16 from "node:fs";
8507
8518
  import path14 from "node:path";
8508
8519
  var index2, botID, AdapterConsole, adapter2;
8509
8520
  var init_input = __esm({
@@ -8615,7 +8626,7 @@ var init_input = __esm({
8615
8626
  const cfg = adapter();
8616
8627
  const name = (++index2).toString();
8617
8628
  const file = path14.join(consolePath, `${name}${ext}`);
8618
- await fs15.promises.writeFile(file, await buffer(data));
8629
+ await fs16.promises.writeFile(file, await buffer(data));
8619
8630
  if (cfg.console.isLocal) {
8620
8631
  return `http://127.0.0.1:${process.env.HTTP_PORT}/console/${name}${ext}`;
8621
8632
  }
@@ -8758,7 +8769,7 @@ var init_cache2 = __esm({
8758
8769
  });
8759
8770
 
8760
8771
  // src/adapter/render/admin/template.ts
8761
- import fs16 from "node:fs";
8772
+ import fs17 from "node:fs";
8762
8773
  import path15 from "node:path";
8763
8774
  import chokidar3 from "chokidar";
8764
8775
  import template from "art-template";
@@ -8780,7 +8791,7 @@ var init_template = __esm({
8780
8791
  const tplData = getCacheData(file);
8781
8792
  const renderData = template.render(tplData, options.data);
8782
8793
  const outputPath = getOutputPath(options.file, renderData, options.name);
8783
- fs16.writeFileSync(outputPath, renderData);
8794
+ fs17.writeFileSync(outputPath, renderData);
8784
8795
  delete options.data;
8785
8796
  delete options.name;
8786
8797
  options.file = `file://${outputPath}`;
@@ -8798,7 +8809,7 @@ var init_template = __esm({
8798
8809
  if (CachingData) {
8799
8810
  return CachingData;
8800
8811
  }
8801
- const tplData = fs16.readFileSync(file, "utf-8");
8812
+ const tplData = fs17.readFileSync(file, "utf-8");
8802
8813
  watch2(file, tplData);
8803
8814
  return tplData;
8804
8815
  };
@@ -8808,7 +8819,7 @@ var init_template = __esm({
8808
8819
  const fileDir = path15.join(htmlPath, name || "render");
8809
8820
  const filePath = path15.join(fileDir, `${basename}-${Date.now()}${extname}`);
8810
8821
  existToMkdirSync(fileDir);
8811
- fs16.writeFileSync(filePath, data);
8822
+ fs17.writeFileSync(filePath, data);
8812
8823
  return filePath;
8813
8824
  };
8814
8825
  watch2 = async (file, data) => {
@@ -8817,7 +8828,7 @@ var init_template = __esm({
8817
8828
  const watcher = chokidar3.watch(file);
8818
8829
  watcherCache.set(file, watcher);
8819
8830
  watcher.on("change", () => {
8820
- cache11.set(file, fs16.readFileSync(file, "utf-8"));
8831
+ cache11.set(file, fs17.readFileSync(file, "utf-8"));
8821
8832
  logger.info(`[\u6587\u4EF6\u53D8\u52A8] html\u6A21\u677F\u53D1\u9001\u53D8\u52A8: ${file}`);
8822
8833
  });
8823
8834
  watcher.on("unlink", () => {
@@ -9768,7 +9779,7 @@ init_esm_shims();
9768
9779
  init_exec();
9769
9780
  init_require();
9770
9781
  init_list();
9771
- import fs17 from "node:fs";
9782
+ import fs18 from "node:fs";
9772
9783
  var getPkg = (isForcibly = false) => {
9773
9784
  return requireFile("package.json", { force: isForcibly });
9774
9785
  };
@@ -9898,8 +9909,8 @@ var checkGitPluginUpdate = async (filePath, time2 = 120) => {
9898
9909
  var _a;
9899
9910
  const logger3 = (global == null ? void 0 : global.logger) || console;
9900
9911
  try {
9901
- if (!fs17.existsSync(filePath)) return { status: "error", data: new Error("\u8DEF\u5F84\u4E0D\u5B58\u5728") };
9902
- if (!fs17.existsSync(`${filePath}/.git`)) return { status: "error", data: new Error("\u8BE5\u8DEF\u5F84\u4E0D\u662F\u4E00\u4E2Agit\u4ED3\u5E93") };
9912
+ if (!fs18.existsSync(filePath)) return { status: "error", data: new Error("\u8DEF\u5F84\u4E0D\u5B58\u5728") };
9913
+ if (!fs18.existsSync(`${filePath}/.git`)) return { status: "error", data: new Error("\u8BE5\u8DEF\u5F84\u4E0D\u662F\u4E00\u4E2Agit\u4ED3\u5E93") };
9903
9914
  const timer = setTimeout(() => {
9904
9915
  return { status: "failed", data: "\u6267\u884C\u8D85\u65F6" };
9905
9916
  }, time2 * 1e3);
@@ -9950,8 +9961,8 @@ var getTime = async (filePath) => {
9950
9961
  var updateGitPlugin = async (filePath, cmd = "git pull", time2 = 120) => {
9951
9962
  const logger3 = (global == null ? void 0 : global.logger) || console;
9952
9963
  try {
9953
- if (!fs17.existsSync(filePath)) return { status: "failed", data: "\u8DEF\u5F84\u4E0D\u5B58\u5728" };
9954
- if (!fs17.existsSync(`${filePath}/.git`)) return { status: "failed", data: "\u8BE5\u8DEF\u5F84\u4E0D\u662F\u4E00\u4E2Agit\u4ED3\u5E93" };
9964
+ if (!fs18.existsSync(filePath)) return { status: "failed", data: "\u8DEF\u5F84\u4E0D\u5B58\u5728" };
9965
+ if (!fs18.existsSync(`${filePath}/.git`)) return { status: "failed", data: "\u8BE5\u8DEF\u5F84\u4E0D\u662F\u4E00\u4E2Agit\u4ED3\u5E93" };
9955
9966
  const timer = setTimeout(() => {
9956
9967
  return { status: "failed", data: "\u6267\u884C\u8D85\u65F6" };
9957
9968
  }, time2 * 1e3);
@@ -10212,7 +10223,7 @@ init_esm_shims();
10212
10223
  // src/adapter/onebot/core/convert.ts
10213
10224
  init_esm_shims();
10214
10225
  init_message2();
10215
- import fs18 from "node:fs";
10226
+ import fs19 from "node:fs";
10216
10227
  var buildError = (selfId, action, request, error) => {
10217
10228
  if (error) {
10218
10229
  const err = JSON.stringify(error, null, 2).replace(/\\n/g, "\n");
@@ -10277,7 +10288,7 @@ var fileToBase64 = (file, url) => {
10277
10288
  if (!url || !file.startsWith("file://")) return file;
10278
10289
  const list4 = ["127.0.0.1", "localhost"];
10279
10290
  const link = new URL(url);
10280
- return list4.includes(link.hostname) ? file : `base64://${fs18.readFileSync(file.replace("file://", "")).toString("base64")}`;
10291
+ return list4.includes(link.hostname) ? file : `base64://${fs19.readFileSync(file.replace("file://", "")).toString("base64")}`;
10281
10292
  };
10282
10293
  var KarinConvertAdapter = (data, onebot) => {
10283
10294
  var _a, _b, _c;
@@ -12390,7 +12401,6 @@ var Plugin = class {
12390
12401
  this.desc = options.desc || "\u65E0\u63CF\u8FF0";
12391
12402
  this.event = options.event || "message";
12392
12403
  this.priority = options.priority || 1e4;
12393
- this.reply = this.e.reply.bind(this.e);
12394
12404
  }
12395
12405
  /**
12396
12406
  * 快速回复合并转发
@@ -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.dad353f",
3
+ "version": "0.12.25.pr.206.e09f093",
4
4
  "description": "Lightweight, efficient, concise, and stable robot framework.",
5
5
  "keywords": [
6
6
  "node",