node-karin 0.12.2-5.pr.206.e170726 → 0.12.2-5.pr.206.e2e1f8d

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": {
@@ -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;
@@ -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,13 @@ 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 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
+ }
48
+ const { error } = execSync(`pm2 start ${pm2Dir}`, { cwd: process.cwd() });
36
49
  if (error) {
37
50
  console.log("[pm2] \u542F\u52A8\u5931\u8D25");
38
51
  console.log(error);
@@ -55,7 +68,7 @@ var log = () => {
55
68
  const data = JSON.parse(fs2__default.default.readFileSync(pm2Dir, "utf-8"));
56
69
  try {
57
70
  const prefix = process.platform === "win32" ? "pm2.cmd" : "pm2";
58
- 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 });
59
72
  } catch (error) {
60
73
  console.error("[pm2] \u53D1\u751F\u672A\u77E5\u9519\u8BEF: \u8BF7\u68C0\u67E5pm2\u662F\u5426\u5B89\u88C5 \u3010npm install -g pm2\u3011");
61
74
  console.error(error);
@@ -69,7 +82,7 @@ var stop = () => {
69
82
  process.exit(1);
70
83
  }
71
84
  const data = JSON.parse(fs2__default.default.readFileSync(pm2Dir, "utf-8"));
72
- exec(`pm2 stop ${data.name}`, { cwd: process.cwd() });
85
+ execSync(`pm2 stop ${data.apps[0].name}`, { cwd: process.cwd() });
73
86
  console.log("[pm2] \u505C\u6B62\u6210\u529F");
74
87
  process.exit(0);
75
88
  };
@@ -122,9 +135,9 @@ var createPnpmFile = (dir2) => {
122
135
  fs2__default.default.writeFileSync(pnpmfile, content);
123
136
  };
124
137
  var shouldSkipNpmrc = () => {
125
- const { stdout } = exec("npm config get registry");
138
+ const { stdout } = execSync("npm config get registry");
126
139
  if (stdout.includes("registry.npmjs.org")) return true;
127
- const { stdout: proxy } = exec("npm config get proxy");
140
+ const { stdout: proxy } = execSync("npm config get proxy");
128
141
  return !!proxy;
129
142
  };
130
143
  var createOrUpdateNpmrc = (dir2) => {
@@ -155,6 +168,10 @@ var createOrUpdateNpmrc = (dir2) => {
155
168
  }
156
169
  };
157
170
  var createOrUpdateEnv = (dir2) => {
171
+ const generateRandomKey = () => {
172
+ const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
173
+ return Array.from({ length: 6 }, () => chars.charAt(Math.floor(Math.random() * chars.length))).join("");
174
+ };
158
175
  const envData = [
159
176
  "# \u662F\u5426\u542F\u7528HTTP",
160
177
  "HTTP_ENABLE=true",
@@ -163,9 +180,9 @@ var createOrUpdateEnv = (dir2) => {
163
180
  "# HTTP\u76D1\u542C\u5730\u5740",
164
181
  "HTTP_HOST=0.0.0.0",
165
182
  "# HTTP\u9274\u6743\u79D8\u94A5 \u4EC5\u7528\u4E8Ekarin\u81EA\u8EABApi",
166
- "HTTP_AUTH_KEY=default",
183
+ `HTTP_AUTH_KEY=${generateRandomKey()}`,
167
184
  "# ws_server\u9274\u6743\u79D8\u94A5",
168
- "WS_SERVER_AUTH_KEY=",
185
+ `WS_SERVER_AUTH_KEY=${generateRandomKey()}`,
169
186
  "\n",
170
187
  "# \u662F\u5426\u542F\u7528Redis \u5173\u95ED\u540E\u5C06\u4F7F\u7528\u5185\u90E8\u865A\u62DFRedis",
171
188
  "REDIS_ENABLE=true",
@@ -206,35 +223,19 @@ var createOrUpdateEnv = (dir2) => {
206
223
  fs2__default.default.appendFileSync(env, "\n" + newEntries.join("\n"));
207
224
  }
208
225
  };
209
- var createOrUpdateEnvDev = (dir2) => {
210
- const envDevData = [
211
- "# \u662F\u5426\u4E3A\u5F00\u53D1\u73AF\u5883",
212
- "NODE_ENV=development",
213
- "# \u8FD0\u884C\u5668",
214
- "RUNTIME=tsx"
215
- ];
216
- const envDev = path2__default.default.join(dir2, ".env.dev");
217
- if (!fs2__default.default.existsSync(envDev)) {
218
- fs2__default.default.writeFileSync(envDev, envDevData.join("\n"));
219
- return;
220
- }
221
- const value = fs2__default.default.readFileSync(envDev, "utf-8");
222
- const newEntries = envDevData.filter((item) => {
223
- if (item.includes("#")) return false;
224
- const key = item.split("=")[0];
225
- return !value.includes(key);
226
- });
227
- if (newEntries.length > 0) {
228
- fs2__default.default.appendFileSync(envDev, "\n" + newEntries.join("\n"));
229
- }
226
+ var createWorkspace = (dir2) => {
227
+ const workspace = path2__default.default.join(dir2, "pnpm-workspace.yaml");
228
+ if (fs2__default.default.existsSync(workspace)) return;
229
+ const content = "packages:\n - 'plugins/**'\n";
230
+ fs2__default.default.writeFileSync(workspace, content);
230
231
  };
231
232
  var createOtherFile = async () => {
232
233
  createPnpmFile(dir);
234
+ createWorkspace(dir);
233
235
  if (!shouldSkipNpmrc()) {
234
236
  createOrUpdateNpmrc(dir);
235
237
  }
236
238
  createOrUpdateEnv(dir);
237
- createOrUpdateEnvDev(dir);
238
239
  };
239
240
  var createConfig = () => {
240
241
  const defCfg = path2__default.default.join(pkgDir, "default", "config");
@@ -256,11 +257,26 @@ var createConfig = () => {
256
257
  };
257
258
  var modifyPackageJson = () => {
258
259
  const pkg = fs2__default.default.readFileSync(path2__default.default.join(dir, "package.json"), "utf-8");
259
- const pkgData = JSON.parse(pkg);
260
- if (pkgData.type === "module") return pkgData;
261
- pkgData.type = "module";
262
- fs2__default.default.writeFileSync(path2__default.default.join(dir, "package.json"), JSON.stringify(pkgData, null, 2));
263
- return pkgData;
260
+ const data = JSON.parse(pkg);
261
+ data.type = "module";
262
+ data.scripts.karin = "karin";
263
+ const list = [
264
+ "app",
265
+ "start",
266
+ "pm2",
267
+ "stop",
268
+ "rs",
269
+ "log",
270
+ "up",
271
+ "dev",
272
+ "ts",
273
+ "watch"
274
+ ];
275
+ list.forEach((v) => {
276
+ data.scripts[v] = `karin ${v}`;
277
+ });
278
+ fs2__default.default.writeFileSync(path2__default.default.join(dir, "package.json"), JSON.stringify(data, null, 2));
279
+ return data;
264
280
  };
265
281
  var init = async () => {
266
282
  createDir();
@@ -269,21 +285,31 @@ var init = async () => {
269
285
  modifyPackageJson();
270
286
  process.exit(0);
271
287
  };
272
- var start2 = async (env = ".env") => {
288
+ var parseEnvFiles = (env) => {
289
+ if (!env) return [".env"];
290
+ return env.split(",").map((file) => file.trim());
291
+ };
292
+ var loadEnv = (env) => {
273
293
  const dir2 = process.cwd();
274
- const list = env === ".env" ? [".env"] : [".env", env];
275
- list.forEach((item) => {
276
- if (!fs2__default.default.existsSync(`${dir2}/${item}`)) {
277
- if (env === ".env") {
278
- console.error(`\u672A\u627E\u5230${item}\u6587\u4EF6\uFF0C\u8BF7\u4F7F\u7528 pnpm init \u8FDB\u884C\u521D\u59CB\u5316\u9879\u76EE`);
294
+ const files = parseEnvFiles(env);
295
+ if (!files.includes(".env")) {
296
+ files.unshift(".env");
297
+ }
298
+ files.forEach((file) => {
299
+ if (!fs2__default.default.existsSync(`${dir2}/${file}`)) {
300
+ if (file === ".env") {
301
+ console.error(`\u672A\u627E\u5230${file}\u6587\u4EF6\uFF0C\u8BF7\u4F7F\u7528 npx karin init \u8FDB\u884C\u521D\u59CB\u5316\u9879\u76EE`);
279
302
  } else {
280
- console.error(`\u672A\u627E\u5230${item}\u6587\u4EF6\uFF0C\u8BF7\u5C06\u5176\u653E\u7F6E\u5728\u9879\u76EE\u6839\u76EE\u5F55`);
303
+ console.error(`\u672A\u627E\u5230${file}\u6587\u4EF6\uFF0C\u8BF7\u5C06\u5176\u653E\u7F6E\u5728\u9879\u76EE\u6839\u76EE\u5F55`);
281
304
  }
282
305
  process.exit(1);
283
306
  }
284
307
  });
285
- const path3 = list.map((item) => `${dir2}/${item}`);
286
- dotenv__default.default.config({ path: path3, override: true });
308
+ const paths = files.map((file) => `${dir2}/${file}`);
309
+ dotenv__default.default.config({ path: paths, override: true });
310
+ };
311
+ var start2 = async (env) => {
312
+ loadEnv(env);
287
313
  const index = "../root.js";
288
314
  const { karinMain } = await import(index);
289
315
  const child = child_process.fork(karinMain);
@@ -296,106 +322,204 @@ var start2 = async (env = ".env") => {
296
322
  });
297
323
  child.on("exit", (code) => process.exit(code));
298
324
  };
299
- var checkGitInstalled = () => {
325
+ var dev = async (env) => {
326
+ loadEnv(env);
327
+ const index = "../root.js";
328
+ process.env.NODE_ENV = "development";
329
+ const { karinMain } = await import(index);
330
+ await import(url.pathToFileURL(karinMain).toString());
331
+ };
332
+ var tsStart = async (env) => {
333
+ loadEnv(env);
334
+ process.env.RUNTIME = "tsx";
335
+ process.env.NODE_ENV = "development";
336
+ const index = "../root.js";
337
+ const { karinMain } = await import(index);
338
+ const child = child_process.spawn("npx", ["tsx", karinMain], {
339
+ stdio: "inherit",
340
+ shell: true
341
+ });
342
+ child.on("exit", (code) => process.exit(code ?? 0));
343
+ };
344
+ var tsWatch = async (options) => {
345
+ loadEnv(options.env);
346
+ process.env.NODE_ENV = "development";
347
+ const index = "../root.js";
348
+ const { karinMain } = await import(index);
349
+ const args = ["tsx", "watch"];
350
+ if (options.include) {
351
+ options.include.split(",").forEach((pattern) => {
352
+ args.push("--include", pattern.trim());
353
+ });
354
+ }
355
+ if (options.exclude) {
356
+ options.exclude.split(",").forEach((pattern) => {
357
+ args.push("--exclude", pattern.trim());
358
+ });
359
+ }
360
+ if (!options.clearScreen) {
361
+ args.push("--clear-screen=false");
362
+ }
363
+ args.push(karinMain);
364
+ process.env.RUNTIME = "tsx";
365
+ process.env.TSX_WATCH = "true";
366
+ const child = child_process.spawn("npx", args, {
367
+ stdio: "inherit",
368
+ shell: true
369
+ });
370
+ child.on("exit", (code) => process.exit(code ?? 0));
371
+ };
372
+ var checkGitInstalled = async () => {
300
373
  try {
301
- child_process.execSync("git --version");
302
- return true;
374
+ const { status } = await exec("git --version");
375
+ return status;
303
376
  } catch {
304
377
  return false;
305
378
  }
306
379
  };
307
380
  var updateDependencies = async (packagePath) => {
308
381
  try {
309
- const packageJson = JSON.parse(fs2.readFileSync(packagePath, "utf-8"));
382
+ const packageJson = JSON.parse(fs2__default.default.readFileSync(packagePath, "utf-8"));
310
383
  const dependencies = packageJson.dependencies || {};
311
384
  const packagesToUpdate = [];
312
- for (const [pkg, version] of Object.entries(dependencies)) {
385
+ const checkVersionTasks = Object.entries(dependencies).map(async ([pkg, version]) => {
313
386
  if (pkg.startsWith("@types/")) {
314
- continue;
387
+ return;
315
388
  }
316
389
  try {
317
- const latestVersion = child_process.execSync(`pnpm view ${pkg} version`, { encoding: "utf-8" }).trim();
390
+ const { stdout: pkgInfoStr } = await exec(`pnpm view ${pkg} --json`);
391
+ const pkgInfo = JSON.parse(pkgInfoStr.trim());
392
+ if (!pkgInfo.karin) return;
318
393
  const currentVersion = version.replace(/[\^~]/g, "");
319
- if (latestVersion !== currentVersion) {
320
- console.log(`\u53D1\u73B0\u65B0\u7248\u672C ${pkg}: ${currentVersion} -> ${latestVersion}`);
394
+ const { stdout: distTagsStr } = await exec(`pnpm view ${pkg} dist-tags --json`);
395
+ const distTags = JSON.parse(distTagsStr.trim());
396
+ const isPreRelease = /[-+]/.test(currentVersion);
397
+ const latestVersion = distTags.latest;
398
+ console.log(`[npm] ${pkg}:`);
399
+ console.log(` \u5F53\u524D\u7248\u672C: ${currentVersion}${isPreRelease ? " (\u9884\u53D1\u5E03\u7248\u672C)" : ""}`);
400
+ console.log(` \u6700\u65B0\u7248\u672C: ${latestVersion}`);
401
+ if (isPreRelease || currentVersion !== latestVersion) {
402
+ console.log(`[npm] \u53D1\u73B0\u65B0\u7248\u672C ${pkg}: ${currentVersion} -> ${latestVersion}`);
321
403
  packagesToUpdate.push(`${pkg}@latest`);
322
404
  } else {
323
- console.log(`${pkg} \u5DF2\u7ECF\u662F\u6700\u65B0\u7248\u672C`);
405
+ console.log(`[npm] ${pkg} \u5DF2\u7ECF\u662F\u6700\u65B0\u7248\u672C`);
324
406
  }
325
407
  } catch (error) {
326
- console.error(`\u68C0\u67E5 ${pkg} \u7248\u672C\u5931\u8D25:`, error);
408
+ console.error(`[npm] \u68C0\u67E5 ${pkg} \u7248\u672C\u5931\u8D25:`, error);
327
409
  }
328
- }
410
+ });
411
+ await Promise.all(checkVersionTasks);
329
412
  if (packagesToUpdate.length > 0) {
330
- console.log("\n\u5F00\u59CB\u66F4\u65B0\u4EE5\u4E0B\u5305:\n", packagesToUpdate.join("\n"));
413
+ console.log("[npm] \u5F00\u59CB\u66F4\u65B0\u4EE5\u4E0B\u5305:\n", packagesToUpdate.join("\n"));
331
414
  try {
332
- child_process.execSync(`pnpm update ${packagesToUpdate.join(" ")}`, {
333
- stdio: "inherit"
334
- });
335
- console.log("\n\u6240\u6709\u5305\u66F4\u65B0\u5B8C\u6210");
415
+ const { status, error } = await exec(`pnpm update ${packagesToUpdate.join(" ")}`);
416
+ if (status) {
417
+ console.log("[npm] \u6240\u6709\u63D2\u4EF6\u66F4\u65B0\u5B8C\u6210");
418
+ } else {
419
+ console.error("[npm] \u6279\u91CF\u66F4\u65B0\u5931\u8D25:", error);
420
+ }
336
421
  } catch (error) {
337
- console.error("\u6279\u91CF\u66F4\u65B0\u5931\u8D25:", error);
422
+ console.error("[npm] \u6279\u91CF\u66F4\u65B0\u5931\u8D25:", error);
338
423
  }
339
424
  } else {
340
- console.log("\n\u6240\u6709\u5305\u90FD\u5DF2\u7ECF\u662F\u6700\u65B0\u7248\u672C");
425
+ console.log("[npm] \u6240\u6709\u63D2\u4EF6\u90FD\u5DF2\u7ECF\u662F\u6700\u65B0\u7248\u672C");
341
426
  }
342
427
  } catch (error) {
343
- console.error("\u66F4\u65B0\u4F9D\u8D56\u5931\u8D25:", error);
428
+ console.error("[npm] \u66F4\u65B0\u4F9D\u8D56\u5931\u8D25:", error);
344
429
  }
345
430
  };
346
431
  var updatePlugins = async (pluginsPath) => {
347
- if (!checkGitInstalled()) {
348
- console.error("\u8BF7\u5148\u5B89\u88C5git");
432
+ if (!await checkGitInstalled()) {
433
+ console.error("[git] \u8BF7\u5148\u5B89\u88C5git");
349
434
  return;
350
435
  }
351
- if (!fs2.existsSync(pluginsPath)) {
352
- console.error("plugins\u76EE\u5F55\u4E0D\u5B58\u5728");
436
+ if (!fs2__default.default.existsSync(pluginsPath)) {
437
+ console.error("[git] plugins\u76EE\u5F55\u4E0D\u5B58\u5728");
353
438
  return;
354
439
  }
355
- const isDirectory = (await promises.stat(pluginsPath)).isDirectory();
440
+ const isDirectory = (await fs2__default.default.promises.stat(pluginsPath)).isDirectory();
356
441
  if (!isDirectory) {
357
- console.error("plugins\u8DEF\u5F84\u4E0D\u662F\u4E00\u4E2A\u76EE\u5F55");
442
+ console.error("[git] plugins\u8DEF\u5F84\u4E0D\u662F\u4E00\u4E2A\u76EE\u5F55");
358
443
  return;
359
444
  }
360
- const dirs = await promises.readdir(pluginsPath);
361
- for (const dir2 of dirs) {
445
+ const dirs = await fs2__default.default.promises.readdir(pluginsPath);
446
+ const updateTasks = dirs.map(async (dir2) => {
362
447
  const pluginPath = path2.join(pluginsPath, dir2);
363
448
  const gitPath = path2.join(pluginPath, ".git");
364
449
  const packageJsonPath = path2.join(pluginPath, "package.json");
365
- if (!dir2.startsWith("karin-plugin-") || !(await promises.stat(pluginPath)).isDirectory()) {
366
- continue;
450
+ if (!dir2.startsWith("karin-plugin-") || !(await fs2__default.default.promises.stat(pluginPath)).isDirectory()) {
451
+ return;
367
452
  }
368
- if (!fs2.existsSync(gitPath)) {
369
- console.log(`${dir2} \u4E0D\u662Fgit\u4ED3\u5E93\uFF0C\u8DF3\u8FC7`);
370
- continue;
453
+ if (!fs2__default.default.existsSync(gitPath)) {
454
+ console.log(`[git] ${dir2} \u4E0D\u662Fgit\u4ED3\u5E93\uFF0C\u8DF3\u8FC7`);
455
+ return;
371
456
  }
372
457
  try {
373
- const packageJson = JSON.parse(fs2.readFileSync(packageJsonPath, "utf-8"));
458
+ const packageJson = JSON.parse(fs2__default.default.readFileSync(packageJsonPath, "utf-8"));
374
459
  if (!packageJson.karin) {
375
- console.log(`${dir2} \u7684package.json\u4E2D\u6CA1\u6709karin\u5B57\u6BB5\uFF0C\u8DF3\u8FC7`);
376
- continue;
460
+ console.log(`[git] ${dir2} \u7684package.json\u4E2D\u6CA1\u6709karin\u5B57\u6BB5\uFF0C\u8DF3\u8FC7`);
461
+ return;
462
+ }
463
+ console.log(`[git] \u6B63\u5728\u66F4\u65B0 ${dir2}...`);
464
+ const { status, error } = await exec("git pull", { cwd: pluginPath });
465
+ if (!status) {
466
+ console.error(`[git] \u66F4\u65B0 ${dir2} \u5931\u8D25:`, error);
377
467
  }
378
- console.log(`\u6B63\u5728\u66F4\u65B0 ${dir2}...`);
379
- child_process.execSync("git pull", { cwd: pluginPath, stdio: "inherit" });
380
468
  } catch (error) {
381
- console.error(`\u66F4\u65B0 ${dir2} \u5931\u8D25:`, error);
469
+ console.error(`[git] \u66F4\u65B0 ${dir2} \u5931\u8D25:`, error);
382
470
  }
383
- }
471
+ });
472
+ await Promise.all(updateTasks);
384
473
  };
385
474
  var updateAll = async () => {
386
475
  try {
476
+ console.log("[all] \u5F00\u59CB\u6267\u884C\u66F4\u65B0\u4EFB\u52A1\n");
387
477
  await Promise.all([updateDependencies("./package.json"), updatePlugins("./plugins")]);
478
+ console.log("\n[all] \u66F4\u65B0\u4EFB\u52A1\u6267\u884C\u5B8C\u6210");
388
479
  } finally {
389
480
  process.exit(0);
390
481
  }
391
482
  };
392
- commander.program.version(process.env.npm_package_version, "-v, --version", "\u663E\u793A\u7248\u672C\u53F7");
393
- commander.program.command(".").description("\u524D\u53F0\u542F\u52A8").action(start2);
394
- commander.program.command("start").description("\u524D\u53F0\u542F\u52A8").action(start2);
483
+ var _a;
484
+ if (!((_a = process.argv) == null ? undefined : _a[2])) process.argv.push("-h");
485
+ var addEnvOption = (command) => {
486
+ return command.option("-e, --env <files>", "\u6307\u5B9A\u73AF\u5883\u53D8\u91CF\u6587\u4EF6\uFF0C\u591A\u4E2A\u6587\u4EF6\u7528\u9017\u53F7\u5206\u9694");
487
+ };
488
+ var getVersion = () => {
489
+ try {
490
+ 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))));
491
+ const packageJson = JSON.parse(fs2__default.default.readFileSync(file, "utf-8"));
492
+ return packageJson.version;
493
+ } catch {
494
+ return "unknown";
495
+ }
496
+ };
497
+ commander.program.version(getVersion(), "-v, --version", "\u663E\u793A\u7248\u672C\u53F7");
395
498
  commander.program.command("pm2").description("\u540E\u53F0\u8FD0\u884C").action(pm2.start);
396
499
  commander.program.command("stop").description("\u505C\u6B62\u540E\u53F0\u8FD0\u884C").action(pm2.stop);
397
500
  commander.program.command("rs").description("\u91CD\u542Fpm2\u670D\u52A1").action(pm2.restart);
398
501
  commander.program.command("log").description("\u67E5\u770B\u65E5\u5FD7").action(pm2.log);
399
502
  commander.program.command("up").description("\u66F4\u65B0\u63D2\u4EF6").action(updateAll);
400
503
  commander.program.command("init").description("\u521D\u59CB\u5316\u9879\u76EE").action(init);
504
+ addEnvOption(commander.program.command(".").description("\u524D\u53F0\u542F\u52A8")).action((options) => start2(options.env));
505
+ addEnvOption(commander.program.command("app").description("\u524D\u53F0\u542F\u52A8")).action((options) => start2(options.env));
506
+ addEnvOption(commander.program.command("start").description("\u524D\u53F0\u542F\u52A8")).action((options) => start2(options.env));
507
+ addEnvOption(commander.program.command("dev").description("JavaScript\u5F00\u53D1\u6A21\u5F0F")).action((options) => dev(options.env));
508
+ addEnvOption(
509
+ commander.program.command("ts").description("TypeScript\u5F00\u53D1\u6A21\u5F0F").addHelpText("after", `
510
+ \u793A\u4F8B:
511
+ $ karin ts # \u4F7F\u7528\u9ED8\u8BA4 .env \u6587\u4EF6\u542F\u52A8
512
+ $ karin ts -e .env.dev # \u4F7F\u7528\u6307\u5B9A\u7684\u73AF\u5883\u53D8\u91CF\u6587\u4EF6\u542F\u52A8
513
+ $ karin ts -e .env.dev,.env.local # \u4F7F\u7528\u591A\u4E2A\u73AF\u5883\u53D8\u91CF\u6587\u4EF6\u542F\u52A8
514
+ `)
515
+ ).action((options) => tsStart(options.env));
516
+ addEnvOption(
517
+ 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", `
518
+ \u793A\u4F8B:
519
+ $ karin watch # \u9ED8\u8BA4\u76D1\u89C6\u6A21\u5F0F
520
+ $ karin watch --include src # \u76D1\u89C6 src \u76EE\u5F55
521
+ $ karin watch --exclude node_modules,dist # \u6392\u9664\u6307\u5B9A\u76EE\u5F55
522
+ $ karin watch --no-clear-screen # \u7981\u7528\u6E05\u5C4F
523
+ `)
524
+ ).action((options) => tsWatch(options));
401
525
  commander.program.parse(process.argv);