node-karin 0.12.2-5.pr.206.df41fea → 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.
- package/default/config/config.json +1 -3
- package/default/config/pm2.json +1 -1
- package/dist/cli/index.cjs +208 -90
- package/dist/cli/index.js +211 -96
- package/dist/cli/pm2.js +1 -0
- package/dist/index.js +45 -32
- package/dist/module/express.cjs +0 -80
- package/dist/module/express.js +1 -1
- package/package.json +13 -7
package/default/config/pm2.json
CHANGED
package/dist/cli/index.cjs
CHANGED
|
@@ -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
|
|
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
|
|
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
|
-
|
|
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 } =
|
|
138
|
+
const { stdout } = execSync("npm config get registry");
|
|
126
139
|
if (stdout.includes("registry.npmjs.org")) return true;
|
|
127
|
-
const { stdout: 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
|
-
|
|
183
|
+
`HTTP_AUTH_KEY=${generateRandomKey()}`,
|
|
167
184
|
"# ws_server\u9274\u6743\u79D8\u94A5",
|
|
168
|
-
|
|
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,28 +223,6 @@ 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
|
-
}
|
|
230
|
-
};
|
|
231
226
|
var createWorkspace = (dir2) => {
|
|
232
227
|
const workspace = path2__default.default.join(dir2, "pnpm-workspace.yaml");
|
|
233
228
|
if (fs2__default.default.existsSync(workspace)) return;
|
|
@@ -241,7 +236,6 @@ var createOtherFile = async () => {
|
|
|
241
236
|
createOrUpdateNpmrc(dir);
|
|
242
237
|
}
|
|
243
238
|
createOrUpdateEnv(dir);
|
|
244
|
-
createOrUpdateEnvDev(dir);
|
|
245
239
|
};
|
|
246
240
|
var createConfig = () => {
|
|
247
241
|
const defCfg = path2__default.default.join(pkgDir, "default", "config");
|
|
@@ -263,11 +257,27 @@ var createConfig = () => {
|
|
|
263
257
|
};
|
|
264
258
|
var modifyPackageJson = () => {
|
|
265
259
|
const pkg = fs2__default.default.readFileSync(path2__default.default.join(dir, "package.json"), "utf-8");
|
|
266
|
-
const
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
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
|
+
"init",
|
|
272
|
+
"dev",
|
|
273
|
+
"ts",
|
|
274
|
+
"watch"
|
|
275
|
+
];
|
|
276
|
+
list.forEach((v) => {
|
|
277
|
+
data.scripts[v] = `karin ${v}`;
|
|
278
|
+
});
|
|
279
|
+
fs2__default.default.writeFileSync(path2__default.default.join(dir, "package.json"), JSON.stringify(data, null, 2));
|
|
280
|
+
return data;
|
|
271
281
|
};
|
|
272
282
|
var init = async () => {
|
|
273
283
|
createDir();
|
|
@@ -276,21 +286,31 @@ var init = async () => {
|
|
|
276
286
|
modifyPackageJson();
|
|
277
287
|
process.exit(0);
|
|
278
288
|
};
|
|
279
|
-
var
|
|
289
|
+
var parseEnvFiles = (env) => {
|
|
290
|
+
if (!env) return [".env"];
|
|
291
|
+
return env.split(",").map((file) => file.trim());
|
|
292
|
+
};
|
|
293
|
+
var loadEnv = (env) => {
|
|
280
294
|
const dir2 = process.cwd();
|
|
281
|
-
const
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
295
|
+
const files = parseEnvFiles(env);
|
|
296
|
+
if (!files.includes(".env")) {
|
|
297
|
+
files.unshift(".env");
|
|
298
|
+
}
|
|
299
|
+
files.forEach((file) => {
|
|
300
|
+
if (!fs2__default.default.existsSync(`${dir2}/${file}`)) {
|
|
301
|
+
if (file === ".env") {
|
|
302
|
+
console.error(`\u672A\u627E\u5230${file}\u6587\u4EF6\uFF0C\u8BF7\u4F7F\u7528 npx karin init \u8FDB\u884C\u521D\u59CB\u5316\u9879\u76EE`);
|
|
286
303
|
} else {
|
|
287
|
-
console.error(`\u672A\u627E\u5230${
|
|
304
|
+
console.error(`\u672A\u627E\u5230${file}\u6587\u4EF6\uFF0C\u8BF7\u5C06\u5176\u653E\u7F6E\u5728\u9879\u76EE\u6839\u76EE\u5F55`);
|
|
288
305
|
}
|
|
289
306
|
process.exit(1);
|
|
290
307
|
}
|
|
291
308
|
});
|
|
292
|
-
const
|
|
293
|
-
dotenv__default.default.config({ path:
|
|
309
|
+
const paths = files.map((file) => `${dir2}/${file}`);
|
|
310
|
+
dotenv__default.default.config({ path: paths, override: true });
|
|
311
|
+
};
|
|
312
|
+
var start2 = async (env) => {
|
|
313
|
+
loadEnv(env);
|
|
294
314
|
const index = "../root.js";
|
|
295
315
|
const { karinMain } = await import(index);
|
|
296
316
|
const child = child_process.fork(karinMain);
|
|
@@ -303,106 +323,204 @@ var start2 = async (env = ".env") => {
|
|
|
303
323
|
});
|
|
304
324
|
child.on("exit", (code) => process.exit(code));
|
|
305
325
|
};
|
|
306
|
-
var
|
|
326
|
+
var dev = async (env) => {
|
|
327
|
+
loadEnv(env);
|
|
328
|
+
const index = "../root.js";
|
|
329
|
+
process.env.NODE_ENV = "development";
|
|
330
|
+
const { karinMain } = await import(index);
|
|
331
|
+
await import(url.pathToFileURL(karinMain).toString());
|
|
332
|
+
};
|
|
333
|
+
var tsStart = async (env) => {
|
|
334
|
+
loadEnv(env);
|
|
335
|
+
process.env.RUNTIME = "tsx";
|
|
336
|
+
process.env.NODE_ENV = "development";
|
|
337
|
+
const index = "../root.js";
|
|
338
|
+
const { karinMain } = await import(index);
|
|
339
|
+
const child = child_process.spawn("npx", ["tsx", karinMain], {
|
|
340
|
+
stdio: "inherit",
|
|
341
|
+
shell: true
|
|
342
|
+
});
|
|
343
|
+
child.on("exit", (code) => process.exit(code ?? 0));
|
|
344
|
+
};
|
|
345
|
+
var tsWatch = async (options) => {
|
|
346
|
+
loadEnv(options.env);
|
|
347
|
+
process.env.NODE_ENV = "development";
|
|
348
|
+
const index = "../root.js";
|
|
349
|
+
const { karinMain } = await import(index);
|
|
350
|
+
const args = ["tsx", "watch"];
|
|
351
|
+
if (options.include) {
|
|
352
|
+
options.include.split(",").forEach((pattern) => {
|
|
353
|
+
args.push("--include", pattern.trim());
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
if (options.exclude) {
|
|
357
|
+
options.exclude.split(",").forEach((pattern) => {
|
|
358
|
+
args.push("--exclude", pattern.trim());
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
if (!options.clearScreen) {
|
|
362
|
+
args.push("--clear-screen=false");
|
|
363
|
+
}
|
|
364
|
+
args.push(karinMain);
|
|
365
|
+
process.env.RUNTIME = "tsx";
|
|
366
|
+
process.env.TSX_WATCH = "true";
|
|
367
|
+
const child = child_process.spawn("npx", args, {
|
|
368
|
+
stdio: "inherit",
|
|
369
|
+
shell: true
|
|
370
|
+
});
|
|
371
|
+
child.on("exit", (code) => process.exit(code ?? 0));
|
|
372
|
+
};
|
|
373
|
+
var checkGitInstalled = async () => {
|
|
307
374
|
try {
|
|
308
|
-
|
|
309
|
-
return
|
|
375
|
+
const { status } = await exec("git --version");
|
|
376
|
+
return status;
|
|
310
377
|
} catch {
|
|
311
378
|
return false;
|
|
312
379
|
}
|
|
313
380
|
};
|
|
314
381
|
var updateDependencies = async (packagePath) => {
|
|
315
382
|
try {
|
|
316
|
-
const packageJson = JSON.parse(
|
|
383
|
+
const packageJson = JSON.parse(fs2__default.default.readFileSync(packagePath, "utf-8"));
|
|
317
384
|
const dependencies = packageJson.dependencies || {};
|
|
318
385
|
const packagesToUpdate = [];
|
|
319
|
-
|
|
386
|
+
const checkVersionTasks = Object.entries(dependencies).map(async ([pkg, version]) => {
|
|
320
387
|
if (pkg.startsWith("@types/")) {
|
|
321
|
-
|
|
388
|
+
return;
|
|
322
389
|
}
|
|
323
390
|
try {
|
|
324
|
-
const
|
|
391
|
+
const { stdout: pkgInfoStr } = await exec(`pnpm view ${pkg} --json`);
|
|
392
|
+
const pkgInfo = JSON.parse(pkgInfoStr.trim());
|
|
393
|
+
if (!pkgInfo.karin) return;
|
|
325
394
|
const currentVersion = version.replace(/[\^~]/g, "");
|
|
326
|
-
|
|
327
|
-
|
|
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}`);
|
|
328
404
|
packagesToUpdate.push(`${pkg}@latest`);
|
|
329
405
|
} else {
|
|
330
|
-
console.log(
|
|
406
|
+
console.log(`[npm] ${pkg} \u5DF2\u7ECF\u662F\u6700\u65B0\u7248\u672C`);
|
|
331
407
|
}
|
|
332
408
|
} catch (error) {
|
|
333
|
-
console.error(
|
|
409
|
+
console.error(`[npm] \u68C0\u67E5 ${pkg} \u7248\u672C\u5931\u8D25:`, error);
|
|
334
410
|
}
|
|
335
|
-
}
|
|
411
|
+
});
|
|
412
|
+
await Promise.all(checkVersionTasks);
|
|
336
413
|
if (packagesToUpdate.length > 0) {
|
|
337
|
-
console.log("\
|
|
414
|
+
console.log("[npm] \u5F00\u59CB\u66F4\u65B0\u4EE5\u4E0B\u5305:\n", packagesToUpdate.join("\n"));
|
|
338
415
|
try {
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
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
|
+
}
|
|
343
422
|
} catch (error) {
|
|
344
|
-
console.error("\u6279\u91CF\u66F4\u65B0\u5931\u8D25:", error);
|
|
423
|
+
console.error("[npm] \u6279\u91CF\u66F4\u65B0\u5931\u8D25:", error);
|
|
345
424
|
}
|
|
346
425
|
} else {
|
|
347
|
-
console.log("\
|
|
426
|
+
console.log("[npm] \u6240\u6709\u63D2\u4EF6\u90FD\u5DF2\u7ECF\u662F\u6700\u65B0\u7248\u672C");
|
|
348
427
|
}
|
|
349
428
|
} catch (error) {
|
|
350
|
-
console.error("\u66F4\u65B0\u4F9D\u8D56\u5931\u8D25:", error);
|
|
429
|
+
console.error("[npm] \u66F4\u65B0\u4F9D\u8D56\u5931\u8D25:", error);
|
|
351
430
|
}
|
|
352
431
|
};
|
|
353
432
|
var updatePlugins = async (pluginsPath) => {
|
|
354
|
-
if (!checkGitInstalled()) {
|
|
355
|
-
console.error("\u8BF7\u5148\u5B89\u88C5git");
|
|
433
|
+
if (!await checkGitInstalled()) {
|
|
434
|
+
console.error("[git] \u8BF7\u5148\u5B89\u88C5git");
|
|
356
435
|
return;
|
|
357
436
|
}
|
|
358
|
-
if (!
|
|
359
|
-
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");
|
|
360
439
|
return;
|
|
361
440
|
}
|
|
362
|
-
const isDirectory = (await promises.stat(pluginsPath)).isDirectory();
|
|
441
|
+
const isDirectory = (await fs2__default.default.promises.stat(pluginsPath)).isDirectory();
|
|
363
442
|
if (!isDirectory) {
|
|
364
|
-
console.error("plugins\u8DEF\u5F84\u4E0D\u662F\u4E00\u4E2A\u76EE\u5F55");
|
|
443
|
+
console.error("[git] plugins\u8DEF\u5F84\u4E0D\u662F\u4E00\u4E2A\u76EE\u5F55");
|
|
365
444
|
return;
|
|
366
445
|
}
|
|
367
|
-
const dirs = await promises.readdir(pluginsPath);
|
|
368
|
-
|
|
446
|
+
const dirs = await fs2__default.default.promises.readdir(pluginsPath);
|
|
447
|
+
const updateTasks = dirs.map(async (dir2) => {
|
|
369
448
|
const pluginPath = path2.join(pluginsPath, dir2);
|
|
370
449
|
const gitPath = path2.join(pluginPath, ".git");
|
|
371
450
|
const packageJsonPath = path2.join(pluginPath, "package.json");
|
|
372
|
-
if (!dir2.startsWith("karin-plugin-") || !(await promises.stat(pluginPath)).isDirectory()) {
|
|
373
|
-
|
|
451
|
+
if (!dir2.startsWith("karin-plugin-") || !(await fs2__default.default.promises.stat(pluginPath)).isDirectory()) {
|
|
452
|
+
return;
|
|
374
453
|
}
|
|
375
|
-
if (!
|
|
376
|
-
console.log(
|
|
377
|
-
|
|
454
|
+
if (!fs2__default.default.existsSync(gitPath)) {
|
|
455
|
+
console.log(`[git] ${dir2} \u4E0D\u662Fgit\u4ED3\u5E93\uFF0C\u8DF3\u8FC7`);
|
|
456
|
+
return;
|
|
378
457
|
}
|
|
379
458
|
try {
|
|
380
|
-
const packageJson = JSON.parse(
|
|
459
|
+
const packageJson = JSON.parse(fs2__default.default.readFileSync(packageJsonPath, "utf-8"));
|
|
381
460
|
if (!packageJson.karin) {
|
|
382
|
-
console.log(
|
|
383
|
-
|
|
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);
|
|
384
468
|
}
|
|
385
|
-
console.log(`\u6B63\u5728\u66F4\u65B0 ${dir2}...`);
|
|
386
|
-
child_process.execSync("git pull", { cwd: pluginPath, stdio: "inherit" });
|
|
387
469
|
} catch (error) {
|
|
388
|
-
console.error(
|
|
470
|
+
console.error(`[git] \u66F4\u65B0 ${dir2} \u5931\u8D25:`, error);
|
|
389
471
|
}
|
|
390
|
-
}
|
|
472
|
+
});
|
|
473
|
+
await Promise.all(updateTasks);
|
|
391
474
|
};
|
|
392
475
|
var updateAll = async () => {
|
|
393
476
|
try {
|
|
477
|
+
console.log("[all] \u5F00\u59CB\u6267\u884C\u66F4\u65B0\u4EFB\u52A1\n");
|
|
394
478
|
await Promise.all([updateDependencies("./package.json"), updatePlugins("./plugins")]);
|
|
479
|
+
console.log("\n[all] \u66F4\u65B0\u4EFB\u52A1\u6267\u884C\u5B8C\u6210");
|
|
395
480
|
} finally {
|
|
396
481
|
process.exit(0);
|
|
397
482
|
}
|
|
398
483
|
};
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
484
|
+
var _a;
|
|
485
|
+
if (!((_a = process.argv) == null ? undefined : _a[2])) process.argv.push("-h");
|
|
486
|
+
var addEnvOption = (command) => {
|
|
487
|
+
return command.option("-e, --env <files>", "\u6307\u5B9A\u73AF\u5883\u53D8\u91CF\u6587\u4EF6\uFF0C\u591A\u4E2A\u6587\u4EF6\u7528\u9017\u53F7\u5206\u9694");
|
|
488
|
+
};
|
|
489
|
+
var getVersion = () => {
|
|
490
|
+
try {
|
|
491
|
+
const file = url.fileURLToPath(new URL("../../package.json", (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))));
|
|
492
|
+
const packageJson = JSON.parse(fs2__default.default.readFileSync(file, "utf-8"));
|
|
493
|
+
return packageJson.version;
|
|
494
|
+
} catch {
|
|
495
|
+
return "unknown";
|
|
496
|
+
}
|
|
497
|
+
};
|
|
498
|
+
commander.program.version(getVersion(), "-v, --version", "\u663E\u793A\u7248\u672C\u53F7");
|
|
402
499
|
commander.program.command("pm2").description("\u540E\u53F0\u8FD0\u884C").action(pm2.start);
|
|
403
500
|
commander.program.command("stop").description("\u505C\u6B62\u540E\u53F0\u8FD0\u884C").action(pm2.stop);
|
|
404
501
|
commander.program.command("rs").description("\u91CD\u542Fpm2\u670D\u52A1").action(pm2.restart);
|
|
405
502
|
commander.program.command("log").description("\u67E5\u770B\u65E5\u5FD7").action(pm2.log);
|
|
406
503
|
commander.program.command("up").description("\u66F4\u65B0\u63D2\u4EF6").action(updateAll);
|
|
407
504
|
commander.program.command("init").description("\u521D\u59CB\u5316\u9879\u76EE").action(init);
|
|
505
|
+
addEnvOption(commander.program.command(".").description("\u524D\u53F0\u542F\u52A8")).action((options) => start2(options.env));
|
|
506
|
+
addEnvOption(commander.program.command("app").description("\u524D\u53F0\u542F\u52A8")).action((options) => start2(options.env));
|
|
507
|
+
addEnvOption(commander.program.command("start").description("\u524D\u53F0\u542F\u52A8")).action((options) => start2(options.env));
|
|
508
|
+
addEnvOption(commander.program.command("dev").description("JavaScript\u5F00\u53D1\u6A21\u5F0F")).action((options) => dev(options.env));
|
|
509
|
+
addEnvOption(
|
|
510
|
+
commander.program.command("ts").description("TypeScript\u5F00\u53D1\u6A21\u5F0F").addHelpText("after", `
|
|
511
|
+
\u793A\u4F8B:
|
|
512
|
+
$ karin ts # \u4F7F\u7528\u9ED8\u8BA4 .env \u6587\u4EF6\u542F\u52A8
|
|
513
|
+
$ karin ts -e .env.dev # \u4F7F\u7528\u6307\u5B9A\u7684\u73AF\u5883\u53D8\u91CF\u6587\u4EF6\u542F\u52A8
|
|
514
|
+
$ karin ts -e .env.dev,.env.local # \u4F7F\u7528\u591A\u4E2A\u73AF\u5883\u53D8\u91CF\u6587\u4EF6\u542F\u52A8
|
|
515
|
+
`)
|
|
516
|
+
).action((options) => tsStart(options.env));
|
|
517
|
+
addEnvOption(
|
|
518
|
+
commander.program.command("watch").description("TypeScript\u76D1\u89C6\u6A21\u5F0F").option("--include <patterns>", "\u6DFB\u52A0\u8981\u76D1\u89C6\u7684\u6587\u4EF6/\u76EE\u5F55\uFF0C\u591A\u4E2A\u7528\u9017\u53F7\u5206\u9694").option("--exclude <patterns>", "\u6392\u9664\u8981\u76D1\u89C6\u7684\u6587\u4EF6/\u76EE\u5F55\uFF0C\u591A\u4E2A\u7528\u9017\u53F7\u5206\u9694").option("--clear-screen", "\u91CD\u65B0\u8FD0\u884C\u65F6\u662F\u5426\u6E05\u5C4F", true).addHelpText("after", `
|
|
519
|
+
\u793A\u4F8B:
|
|
520
|
+
$ karin watch # \u9ED8\u8BA4\u76D1\u89C6\u6A21\u5F0F
|
|
521
|
+
$ karin watch --include src # \u76D1\u89C6 src \u76EE\u5F55
|
|
522
|
+
$ karin watch --exclude node_modules,dist # \u6392\u9664\u6307\u5B9A\u76EE\u5F55
|
|
523
|
+
$ karin watch --no-clear-screen # \u7981\u7528\u6E05\u5C4F
|
|
524
|
+
`)
|
|
525
|
+
).action((options) => tsWatch(options));
|
|
408
526
|
commander.program.parse(process.argv);
|