pangu-vis-cli 1.0.3 → 1.1.0

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.
Files changed (44) hide show
  1. package/README.md +41 -34
  2. package/dist/index.js +2220 -1
  3. package/{template → dist/template}/chart/example/App.vue +1 -3
  4. package/dist/template/chart/example/main.js +4 -0
  5. package/{template → dist/template}/chart/index.js +6 -6
  6. package/dist/template/chart/jsconfig.json +14 -0
  7. package/dist/template/chart/package.json +15 -0
  8. package/{template → dist/template}/chart/render.js +8 -8
  9. package/{template → dist/template}/chart/src/style.js +2 -2
  10. package/dist/template/ts/tsconfig.app.json +13 -0
  11. package/dist/template/ts/tsconfig.json +11 -0
  12. package/dist/template/ts/tsconfig.node.json +17 -0
  13. package/package.json +74 -66
  14. package/bin/index.js +0 -3
  15. package/dist/action.js +0 -1
  16. package/dist/auth/index.js +0 -1
  17. package/dist/auth/select.js +0 -1
  18. package/dist/build/index.js +0 -1
  19. package/dist/config/index.js +0 -1
  20. package/dist/create/chart/index.js +0 -1
  21. package/dist/create/index.js +0 -1
  22. package/dist/dev/index.js +0 -1
  23. package/dist/pack/index.js +0 -1
  24. package/dist/renew/index.js +0 -1
  25. package/dist/tar/index.js +0 -1
  26. package/dist/tidier/index.js +0 -1
  27. package/dist/update/index.js +0 -1
  28. package/dist/upload/index.js +0 -1
  29. package/dist/utils.js +0 -1
  30. package/dist/vpack/index.js +0 -1
  31. package/dist/vpack/menu.js +0 -1
  32. package/template/chart/example/main.js +0 -4
  33. package/template/chart/jsconfig.json +0 -14
  34. package/template/chart/package.json +0 -15
  35. package/template/ts/tsconfig.app.json +0 -13
  36. package/template/ts/tsconfig.json +0 -11
  37. package/template/ts/tsconfig.node.json +0 -19
  38. /package/{template → dist/template}/chart/README.md +0 -0
  39. /package/{template → dist/template}/chart/index.html +0 -0
  40. /package/{template → dist/template}/chart/public/images/index.png +0 -0
  41. /package/{template → dist/template}/chart/src/config.js +0 -0
  42. /package/{template → dist/template}/chart/src/data.js +0 -0
  43. /package/{template → dist/template}/chart/src/index.vue +0 -0
  44. /package/{template → dist/template}/ts/env.d.ts +0 -0
package/dist/index.js CHANGED
@@ -1 +1,2220 @@
1
- "use strict";const{checkUpdate:e}=require("./renew"),r=require("./action"),{program:o}=require("commander"),{version:s}=require("../package.json"),i=require("chalk"),c=require("path"),{log:a,get_cli_config:n,exit:t}=require("./utils"),d=(e,r=[])=>{try{require(c.resolve(__dirname,e,"index.js"))(r,{})}catch(e){t(e?.message)}};r.forEach(r=>{(r.option?r.option.reduce((e,r)=>e.option(r),o):o).command(r.command).alias(r.alias).description(r.desc).action(async()=>{const o=process.argv.slice(3);if(await e(),"*"===r.command)a.err(r.desc);else if(r.isAuth){const[e]=await n();if(e.user)d(r.command,o);else{await require("./auth/index.js")()&&d(r.command,o)}}else d(r.command,o)})}),"-v"===process.argv[2]&&(console.log(s),t()),o.version(s).parse(process.argv),process.on("uncaughtException",function(e){console.log(i.bold.red("err:"),i.bold.red(e?.message||"异常错误!")),process.exit(1)});
1
+ #!/usr/bin/env node
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __esm = (fn, res) => function __init() {
9
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
10
+ };
11
+ var __commonJS = (cb, mod) => function __require() {
12
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
13
+ };
14
+ var __export = (target, all) => {
15
+ for (var name in all)
16
+ __defProp(target, name, { get: all[name], enumerable: true });
17
+ };
18
+ var __copyProps = (to4, from, except, desc) => {
19
+ if (from && typeof from === "object" || typeof from === "function") {
20
+ for (let key of __getOwnPropNames(from))
21
+ if (!__hasOwnProp.call(to4, key) && key !== except)
22
+ __defProp(to4, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
+ }
24
+ return to4;
25
+ };
26
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
27
+ // If the importer is in node compatibility mode or this is not an ESM
28
+ // file that has been converted to a CommonJS file using a Babel-
29
+ // compatible transform (i.e. "__esModule" has not been set), then set
30
+ // "default" to the CommonJS "module.exports" for node compatibility.
31
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
32
+ mod
33
+ ));
34
+
35
+ // src/types/cli.ts
36
+ var DEFAULT_CLI_CONFIG;
37
+ var init_cli = __esm({
38
+ "src/types/cli.ts"() {
39
+ "use strict";
40
+ DEFAULT_CLI_CONFIG = {
41
+ autoRemove: true,
42
+ autoRemoveEs: true
43
+ };
44
+ }
45
+ });
46
+
47
+ // src/utils/config.ts
48
+ import { homedir } from "node:os";
49
+ import path from "node:path";
50
+ import { to } from "await-to-js";
51
+ import fs from "fs-extra";
52
+ var DEFAULT_PRIVATE_SOURCE, getConfigDir, packagePath, getPackagePath, cli_config, privateSourceCache, set_update_log, get_update_log, getPrivateSource, filterValidConfigFields, set_cli_config, get_cli_config, setUpdateCheckTime, shouldCheckUpdate;
53
+ var init_config = __esm({
54
+ "src/utils/config.ts"() {
55
+ "use strict";
56
+ init_cli();
57
+ DEFAULT_PRIVATE_SOURCE = "http://192.168.12.88:10000";
58
+ getConfigDir = () => {
59
+ const envConfigDir = process.env.PANGU_CONFIG_DIR;
60
+ if (envConfigDir && envConfigDir.trim() !== "") {
61
+ return path.resolve(envConfigDir);
62
+ }
63
+ return path.resolve(homedir(), ".pangu-vis-store");
64
+ };
65
+ packagePath = getConfigDir();
66
+ getPackagePath = () => getConfigDir();
67
+ cli_config = null;
68
+ privateSourceCache = null;
69
+ set_update_log = async (isExpired = false) => {
70
+ const time = Date.now() + 24 * 60 * 60 * 1e3;
71
+ await fs.outputJson(path.resolve(getPackagePath(), ".update_log"), {
72
+ time,
73
+ isExpired
74
+ });
75
+ };
76
+ get_update_log = async () => {
77
+ const [err, res] = await to(fs.readJson(path.resolve(getPackagePath(), ".update_log")));
78
+ if (err || !res) {
79
+ return { isExpired: true, time: 0 };
80
+ }
81
+ return res;
82
+ };
83
+ getPrivateSource = async () => {
84
+ if (privateSourceCache !== null) {
85
+ return privateSourceCache;
86
+ }
87
+ const envRegistry = process.env.PANGU_REGISTRY;
88
+ if (envRegistry?.startsWith("http")) {
89
+ privateSourceCache = envRegistry;
90
+ return privateSourceCache;
91
+ }
92
+ const [config2] = await get_cli_config();
93
+ if (config2.privateRegistry && typeof config2.privateRegistry === "string") {
94
+ privateSourceCache = config2.privateRegistry;
95
+ return privateSourceCache;
96
+ }
97
+ privateSourceCache = DEFAULT_PRIVATE_SOURCE;
98
+ return privateSourceCache;
99
+ };
100
+ filterValidConfigFields = (config2) => {
101
+ const result = {
102
+ autoRemove: typeof config2.autoRemove === "boolean" ? config2.autoRemove : DEFAULT_CLI_CONFIG.autoRemove,
103
+ autoRemoveEs: typeof config2.autoRemoveEs === "boolean" ? config2.autoRemoveEs : DEFAULT_CLI_CONFIG.autoRemoveEs
104
+ };
105
+ if (typeof config2.lastUpdateCheck === "number") {
106
+ result.lastUpdateCheck = config2.lastUpdateCheck;
107
+ }
108
+ if (typeof config2.privateRegistry === "string") {
109
+ result.privateRegistry = config2.privateRegistry;
110
+ }
111
+ return result;
112
+ };
113
+ set_cli_config = async (option) => {
114
+ const [old_cli_config, cli_config_path] = await get_cli_config();
115
+ cli_config = {
116
+ ...old_cli_config,
117
+ ...option
118
+ };
119
+ privateSourceCache = null;
120
+ await fs.outputJson(cli_config_path, cli_config);
121
+ };
122
+ get_cli_config = async () => {
123
+ const cli_config_path = path.resolve(getPackagePath(), ".cli_store");
124
+ if (cli_config !== null) {
125
+ return [cli_config, cli_config_path];
126
+ }
127
+ const [err, res] = await to(fs.readJson(cli_config_path));
128
+ if (err || !res) {
129
+ cli_config = DEFAULT_CLI_CONFIG;
130
+ return [cli_config, cli_config_path];
131
+ }
132
+ cli_config = filterValidConfigFields(res);
133
+ return [cli_config, cli_config_path];
134
+ };
135
+ setUpdateCheckTime = async () => {
136
+ const currentTimestamp = Date.now();
137
+ await set_cli_config({ lastUpdateCheck: currentTimestamp });
138
+ };
139
+ shouldCheckUpdate = async () => {
140
+ const [config2] = await get_cli_config();
141
+ if (!config2.lastUpdateCheck) {
142
+ return true;
143
+ }
144
+ const ONE_DAY_MS = 24 * 60 * 60 * 1e3;
145
+ const timeSinceLastCheck = Date.now() - config2.lastUpdateCheck;
146
+ return timeSinceLastCheck > ONE_DAY_MS;
147
+ };
148
+ }
149
+ });
150
+
151
+ // node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js
152
+ var require_picocolors = __commonJS({
153
+ "node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js"(exports, module) {
154
+ var p2 = process || {};
155
+ var argv = p2.argv || [];
156
+ var env = p2.env || {};
157
+ var isColorSupported = !(!!env.NO_COLOR || argv.includes("--no-color")) && (!!env.FORCE_COLOR || argv.includes("--color") || p2.platform === "win32" || (p2.stdout || {}).isTTY && env.TERM !== "dumb" || !!env.CI);
158
+ var formatter = (open, close, replace = open) => (input) => {
159
+ let string = "" + input, index = string.indexOf(close, open.length);
160
+ return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close;
161
+ };
162
+ var replaceClose = (string, close, replace, index) => {
163
+ let result = "", cursor = 0;
164
+ do {
165
+ result += string.substring(cursor, index) + replace;
166
+ cursor = index + close.length;
167
+ index = string.indexOf(close, cursor);
168
+ } while (~index);
169
+ return result + string.substring(cursor);
170
+ };
171
+ var createColors = (enabled = isColorSupported) => {
172
+ let f = enabled ? formatter : () => String;
173
+ return {
174
+ isColorSupported: enabled,
175
+ reset: f("\x1B[0m", "\x1B[0m"),
176
+ bold: f("\x1B[1m", "\x1B[22m", "\x1B[22m\x1B[1m"),
177
+ dim: f("\x1B[2m", "\x1B[22m", "\x1B[22m\x1B[2m"),
178
+ italic: f("\x1B[3m", "\x1B[23m"),
179
+ underline: f("\x1B[4m", "\x1B[24m"),
180
+ inverse: f("\x1B[7m", "\x1B[27m"),
181
+ hidden: f("\x1B[8m", "\x1B[28m"),
182
+ strikethrough: f("\x1B[9m", "\x1B[29m"),
183
+ black: f("\x1B[30m", "\x1B[39m"),
184
+ red: f("\x1B[31m", "\x1B[39m"),
185
+ green: f("\x1B[32m", "\x1B[39m"),
186
+ yellow: f("\x1B[33m", "\x1B[39m"),
187
+ blue: f("\x1B[34m", "\x1B[39m"),
188
+ magenta: f("\x1B[35m", "\x1B[39m"),
189
+ cyan: f("\x1B[36m", "\x1B[39m"),
190
+ white: f("\x1B[37m", "\x1B[39m"),
191
+ gray: f("\x1B[90m", "\x1B[39m"),
192
+ bgBlack: f("\x1B[40m", "\x1B[49m"),
193
+ bgRed: f("\x1B[41m", "\x1B[49m"),
194
+ bgGreen: f("\x1B[42m", "\x1B[49m"),
195
+ bgYellow: f("\x1B[43m", "\x1B[49m"),
196
+ bgBlue: f("\x1B[44m", "\x1B[49m"),
197
+ bgMagenta: f("\x1B[45m", "\x1B[49m"),
198
+ bgCyan: f("\x1B[46m", "\x1B[49m"),
199
+ bgWhite: f("\x1B[47m", "\x1B[49m"),
200
+ blackBright: f("\x1B[90m", "\x1B[39m"),
201
+ redBright: f("\x1B[91m", "\x1B[39m"),
202
+ greenBright: f("\x1B[92m", "\x1B[39m"),
203
+ yellowBright: f("\x1B[93m", "\x1B[39m"),
204
+ blueBright: f("\x1B[94m", "\x1B[39m"),
205
+ magentaBright: f("\x1B[95m", "\x1B[39m"),
206
+ cyanBright: f("\x1B[96m", "\x1B[39m"),
207
+ whiteBright: f("\x1B[97m", "\x1B[39m"),
208
+ bgBlackBright: f("\x1B[100m", "\x1B[49m"),
209
+ bgRedBright: f("\x1B[101m", "\x1B[49m"),
210
+ bgGreenBright: f("\x1B[102m", "\x1B[49m"),
211
+ bgYellowBright: f("\x1B[103m", "\x1B[49m"),
212
+ bgBlueBright: f("\x1B[104m", "\x1B[49m"),
213
+ bgMagentaBright: f("\x1B[105m", "\x1B[49m"),
214
+ bgCyanBright: f("\x1B[106m", "\x1B[49m"),
215
+ bgWhiteBright: f("\x1B[107m", "\x1B[49m")
216
+ };
217
+ };
218
+ module.exports = createColors();
219
+ module.exports.createColors = createColors;
220
+ }
221
+ });
222
+
223
+ // src/utils/log.ts
224
+ var import_picocolors, log, exit;
225
+ var init_log = __esm({
226
+ "src/utils/log.ts"() {
227
+ "use strict";
228
+ import_picocolors = __toESM(require_picocolors(), 1);
229
+ log = {
230
+ /**
231
+ * 输出成功消息(绿色)
232
+ * @param message 消息文本
233
+ * @returns 无返回值
234
+ */
235
+ success(message) {
236
+ process.stdout.write(`${import_picocolors.default.green(message)}
237
+ `);
238
+ },
239
+ /**
240
+ * 输出错误消息(红色加粗,写入 stderr)
241
+ * @param message 消息文本
242
+ * @returns 无返回值
243
+ */
244
+ err(message) {
245
+ process.stderr.write(`${import_picocolors.default.bold(import_picocolors.default.red(message))}
246
+ `);
247
+ },
248
+ /**
249
+ * 输出提示消息(蓝色)
250
+ * @param message 消息文本
251
+ * @returns 无返回值
252
+ */
253
+ info(message) {
254
+ process.stdout.write(`${import_picocolors.default.blue(message)}
255
+ `);
256
+ },
257
+ /**
258
+ * 输出警告消息(黄色)
259
+ * @param message 消息文本
260
+ * @returns 无返回值
261
+ */
262
+ warn(message) {
263
+ process.stdout.write(`${import_picocolors.default.yellow(message)}
264
+ `);
265
+ },
266
+ /**
267
+ * 输出步骤消息(原色)
268
+ * @param message 消息文本
269
+ * @returns 无返回值
270
+ */
271
+ step(message) {
272
+ process.stdout.write(`${message}
273
+ `);
274
+ },
275
+ /**
276
+ * 输出普通消息(原色)
277
+ * @param message 消息文本
278
+ * @returns 无返回值
279
+ */
280
+ message(message) {
281
+ process.stdout.write(`${message}
282
+ `);
283
+ }
284
+ };
285
+ exit = (message) => {
286
+ if (message) {
287
+ log.message("");
288
+ log.err(message);
289
+ }
290
+ process.exit(1);
291
+ };
292
+ }
293
+ });
294
+
295
+ // src/utils/process.ts
296
+ var process_exports = {};
297
+ __export(process_exports, {
298
+ compareVersion: () => compareVersion,
299
+ detectPackageManager: () => detectPackageManager,
300
+ getCdRelativePath: () => getCdRelativePath,
301
+ getGitUser: () => getGitUser,
302
+ getPackageName: () => getPackageName,
303
+ get_plugin_latest_version: () => get_plugin_latest_version,
304
+ get_plugin_version: () => get_plugin_version,
305
+ runAsyncCmd: () => runAsyncCmd,
306
+ userInfo: () => userInfo,
307
+ wait: () => wait,
308
+ welcomeCli: () => welcomeCli
309
+ });
310
+ import path2 from "node:path";
311
+ import { promisify } from "node:util";
312
+ import { $ } from "execa";
313
+ import figlet from "figlet";
314
+ import _ from "lodash";
315
+ var camelCase, upperFirst, detectPackageManager, userInfo, getPackageName, wait, welcomeCli, compareVersion, getCdRelativePath, runAsyncCmd, getGitUser, get_plugin_version, get_plugin_latest_version;
316
+ var init_process = __esm({
317
+ "src/utils/process.ts"() {
318
+ "use strict";
319
+ init_log();
320
+ ({ camelCase, upperFirst } = _);
321
+ detectPackageManager = async () => {
322
+ try {
323
+ await $`nub --version`;
324
+ return "nub";
325
+ } catch {
326
+ }
327
+ try {
328
+ await $`pnpm --version`;
329
+ return "pnpm";
330
+ } catch {
331
+ }
332
+ return "npm";
333
+ };
334
+ userInfo = { user: "" };
335
+ getPackageName = (name) => upperFirst(camelCase(name));
336
+ wait = (seconds) => {
337
+ return new Promise((resolve) => setTimeout(resolve, seconds * 1e3));
338
+ };
339
+ welcomeCli = async () => {
340
+ const figletAsync = promisify(figlet);
341
+ const welcomeInfo = await figletAsync("Welcome to VisCli");
342
+ log.message("");
343
+ log.success(welcomeInfo || "Welcome to VisCli");
344
+ };
345
+ compareVersion = (v1, v2) => {
346
+ if (v1.startsWith("v")) v1 = v1.slice(1);
347
+ if (v2.startsWith("v")) v2 = v2.slice(1);
348
+ const arr1 = v1.split(".");
349
+ const arr2 = v2.split(".");
350
+ const len = Math.max(arr1.length, arr2.length);
351
+ while (arr1.length < len) arr1.push("0");
352
+ while (arr2.length < len) arr2.push("0");
353
+ for (let i = 0; i < len; i++) {
354
+ const num1 = parseInt(arr1[i] || "0", 10);
355
+ const num2 = parseInt(arr2[i] || "0", 10);
356
+ if (num1 > num2) return 1;
357
+ if (num1 < num2) return -1;
358
+ }
359
+ return 0;
360
+ };
361
+ getCdRelativePath = (currentPath, targetPath) => {
362
+ const absCurrent = path2.resolve(currentPath);
363
+ const absTarget = path2.resolve(targetPath);
364
+ const relativePath = path2.relative(absCurrent, absTarget);
365
+ return relativePath || "./";
366
+ };
367
+ runAsyncCmd = async (cmd, args = [], options = {}) => {
368
+ try {
369
+ const { cwd = process.cwd(), stdio = "inherit" } = options;
370
+ const result = await $({ cwd, stdio })`${cmd} ${args}`;
371
+ return {
372
+ success: true,
373
+ stdout: result.stdout || "",
374
+ stderr: result.stderr || "",
375
+ status: result.exitCode ?? null
376
+ };
377
+ } catch (err) {
378
+ const error = err;
379
+ log.err(`Command failed: ${error.message}`);
380
+ return {
381
+ success: false,
382
+ stdout: error.stdout || "",
383
+ stderr: error.stderr || error.message,
384
+ status: error.exitCode || null
385
+ };
386
+ }
387
+ };
388
+ getGitUser = async () => {
389
+ try {
390
+ const result = await $`git config user.name`;
391
+ userInfo.user = result.stdout.trim();
392
+ return userInfo.user;
393
+ } catch {
394
+ return "";
395
+ }
396
+ };
397
+ get_plugin_version = async (pluginName) => {
398
+ if (!pluginName) return "";
399
+ try {
400
+ const args = ["view", pluginName, "version"];
401
+ const result = await $`npm ${args}`;
402
+ return result.stdout.trim();
403
+ } catch {
404
+ return "";
405
+ }
406
+ };
407
+ get_plugin_latest_version = async (pluginName, defaultVersion = "") => {
408
+ if (!pluginName) return {};
409
+ const version2 = await get_plugin_version(pluginName) || defaultVersion;
410
+ return { [pluginName]: `^${version2}` };
411
+ };
412
+ }
413
+ });
414
+
415
+ // package.json
416
+ var package_exports = {};
417
+ __export(package_exports, {
418
+ default: () => package_default
419
+ });
420
+ var package_default;
421
+ var init_package = __esm({
422
+ "package.json"() {
423
+ package_default = {
424
+ name: "pangu-vis-cli",
425
+ version: "1.1.0",
426
+ description: "vis-cli",
427
+ keywords: [
428
+ "pangu-vis",
429
+ "pangu-vis-cli",
430
+ "pv",
431
+ "pvis"
432
+ ],
433
+ license: "MIT",
434
+ author: "Jaxon",
435
+ bin: {
436
+ pv: "dist/index.js",
437
+ pvis: "dist/index.js"
438
+ },
439
+ files: [
440
+ "dist"
441
+ ],
442
+ type: "module",
443
+ main: "./dist/index.js",
444
+ publishConfig: {
445
+ registry: "https://registry.npmjs.org/"
446
+ },
447
+ scripts: {
448
+ build: "node scripts/build.mjs",
449
+ typecheck: "tsc --noEmit",
450
+ test: "vitest",
451
+ "test:run": "vitest run",
452
+ "test:coverage": "vitest run --coverage",
453
+ lint: "oxlint .",
454
+ "lint:fix": "oxlint . --fix",
455
+ format: "oxfmt .",
456
+ "format:check": "oxfmt --check .",
457
+ check: "oxlint . && oxfmt --check .",
458
+ "check:fix": "oxlint . --fix && oxfmt .",
459
+ prepare: "node scripts/build.mjs",
460
+ release: "standard-version",
461
+ "release:patch": "standard-version --release-as patch",
462
+ "release:minor": "standard-version --release-as minor",
463
+ "release:major": "standard-version --release-as major",
464
+ "release:beta": "standard-version --prerelease beta"
465
+ },
466
+ dependencies: {
467
+ "@clack/prompts": "^0.10.1",
468
+ "await-to-js": "^3.0.0",
469
+ clear: "^0.1.0",
470
+ commander: "^10.0.1",
471
+ dayjs: "^1.11.21",
472
+ execa: "^9.6.1",
473
+ figlet: "^1.11.0",
474
+ "fs-extra": "^11.3.6",
475
+ lodash: "^4.18.1",
476
+ picocolors: "^1.1.1",
477
+ tar: "^6.2.1",
478
+ zod: "^4.4.3"
479
+ },
480
+ devDependencies: {
481
+ "@types/clear": "^0.1.4",
482
+ "@types/fs-extra": "^11.0.4",
483
+ "@types/lodash": "^4.17.24",
484
+ "@types/node": "^20",
485
+ "@types/tar": "^6.1.0",
486
+ "@vitest/coverage-v8": "^4.1.9",
487
+ esbuild: "^0.25.12",
488
+ oxfmt: "^0.66.0",
489
+ oxlint: "^1.81.0",
490
+ "standard-version": "^9.5.0",
491
+ typescript: "7.0.2",
492
+ vitest: "^4.1.9",
493
+ zx: "^8.8.5"
494
+ },
495
+ engines: {
496
+ node: ">=20.19.0"
497
+ }
498
+ };
499
+ }
500
+ });
501
+
502
+ // src/utils/api.ts
503
+ import { exec } from "node:child_process";
504
+ import { promisify as promisify2 } from "node:util";
505
+ import fs2 from "fs-extra";
506
+ async function getUserNpmRegistry() {
507
+ if (userNpmRegistryCache !== null) {
508
+ return userNpmRegistryCache;
509
+ }
510
+ try {
511
+ const { stdout } = await execAsync("npm config get registry", {
512
+ timeout: 5e3
513
+ });
514
+ const registry = stdout.trim();
515
+ if (registry?.startsWith("http")) {
516
+ userNpmRegistryCache = registry;
517
+ return userNpmRegistryCache;
518
+ }
519
+ userNpmRegistryCache = DEFAULT_NPM_REGISTRY;
520
+ return userNpmRegistryCache;
521
+ } catch (_error) {
522
+ userNpmRegistryCache = DEFAULT_NPM_REGISTRY;
523
+ return userNpmRegistryCache;
524
+ }
525
+ }
526
+ async function checkNpmConnection() {
527
+ const privateRegistry = await getPrivateSource();
528
+ try {
529
+ const response = await fetch(privateRegistry, {
530
+ method: "GET",
531
+ signal: AbortSignal.timeout(5e3)
532
+ });
533
+ return response.ok;
534
+ } catch (_error) {
535
+ return false;
536
+ }
537
+ }
538
+ async function checkNpmConnectionState(options = {}) {
539
+ if (npmConnectionStateCache !== null) {
540
+ return npmConnectionStateCache;
541
+ }
542
+ const showSpinner = options.showSpinner ?? true;
543
+ const s = showSpinner ? (await Promise.resolve().then(() => (init_utils(), utils_exports))).spinner("\u6B63\u5728\u68C0\u6D4Bnpm\u6E90\uFF0C\u8BF7\u7A0D\u5019...") : null;
544
+ s?.start();
545
+ const state = await checkNpmConnection();
546
+ if (!s) {
547
+ npmConnectionStateCache = state;
548
+ return npmConnectionStateCache;
549
+ }
550
+ if (state) {
551
+ s.succeed("npm\u6E90\u68C0\u6D4B\u5B8C\u6210");
552
+ } else {
553
+ s.fail("npm\u6E90\u68C0\u6D4B\u5931\u8D25");
554
+ }
555
+ const { wait: wait2 } = await Promise.resolve().then(() => (init_process(), process_exports));
556
+ await wait2(0.1);
557
+ npmConnectionStateCache = state;
558
+ return npmConnectionStateCache;
559
+ }
560
+ async function getLatestVersion(packageName, defaultValue) {
561
+ try {
562
+ if (!packageName) {
563
+ return defaultValue;
564
+ }
565
+ const cacheKey = `${packageName}\0${defaultValue ?? ""}`;
566
+ if (latestVersionCache.has(cacheKey)) {
567
+ return latestVersionCache.get(cacheKey);
568
+ }
569
+ const registry = packageName.startsWith("@pangu/") ? await getPrivateSource() : await getUserNpmRegistry();
570
+ const registryUrl = `${registry}/${packageName}`;
571
+ const response = await fetch(registryUrl, {
572
+ method: "GET",
573
+ signal: AbortSignal.timeout(5e3)
574
+ });
575
+ if (!response.ok) {
576
+ latestVersionCache.set(cacheKey, defaultValue);
577
+ return defaultValue;
578
+ }
579
+ const data = await response.json();
580
+ const latestVersion = data?.["dist-tags"]?.latest;
581
+ const result = latestVersion || defaultValue;
582
+ latestVersionCache.set(cacheKey, result);
583
+ return result;
584
+ } catch (_error) {
585
+ if (packageName) {
586
+ latestVersionCache.set(`${packageName}\0${defaultValue ?? ""}`, defaultValue);
587
+ }
588
+ return defaultValue;
589
+ }
590
+ }
591
+ async function get_plugin_latest_version2(packageName, defaultValue) {
592
+ if (!packageName) {
593
+ return {};
594
+ }
595
+ const latestVersion = await getLatestVersion(packageName, defaultValue);
596
+ if (!latestVersion) {
597
+ return {};
598
+ }
599
+ return {
600
+ [packageName]: `^${latestVersion}`
601
+ };
602
+ }
603
+ async function getCurrentVersion() {
604
+ try {
605
+ const { default: pkg } = await Promise.resolve().then(() => (init_package(), package_exports));
606
+ return pkg.version || "0.0.0";
607
+ } catch (_importError) {
608
+ try {
609
+ const packageJsonPath = new URL("../../package.json", import.meta.url).pathname;
610
+ const pkg = await fs2.readJson(packageJsonPath);
611
+ return pkg.version || "0.0.0";
612
+ } catch (_readError) {
613
+ return "0.0.0";
614
+ }
615
+ }
616
+ }
617
+ var execAsync, DEFAULT_NPM_REGISTRY, userNpmRegistryCache, npmConnectionStateCache, latestVersionCache;
618
+ var init_api = __esm({
619
+ "src/utils/api.ts"() {
620
+ "use strict";
621
+ init_config();
622
+ execAsync = promisify2(exec);
623
+ DEFAULT_NPM_REGISTRY = "https://registry.npmjs.org";
624
+ userNpmRegistryCache = null;
625
+ npmConnectionStateCache = null;
626
+ latestVersionCache = /* @__PURE__ */ new Map();
627
+ }
628
+ });
629
+
630
+ // src/utils/error.ts
631
+ function handleCliError(error, exitFn) {
632
+ const exitHandler = exitFn ?? ((message) => {
633
+ if (message) {
634
+ log.err(message);
635
+ }
636
+ process.exit(1);
637
+ });
638
+ if (error.isUserError()) {
639
+ exitHandler(error.message);
640
+ } else {
641
+ throw error;
642
+ }
643
+ }
644
+ async function wrapAsyncOperation(operation, errorMessage) {
645
+ try {
646
+ return await operation();
647
+ } catch (error) {
648
+ const originalError = error instanceof Error ? error : new Error(String(error));
649
+ throw CliError.operation(errorMessage, originalError);
650
+ }
651
+ }
652
+ function assertValidation(condition, message) {
653
+ if (!condition) {
654
+ throw CliError.validation(message);
655
+ }
656
+ }
657
+ var CliErrorType, CliError;
658
+ var init_error = __esm({
659
+ "src/utils/error.ts"() {
660
+ "use strict";
661
+ init_log();
662
+ CliErrorType = /* @__PURE__ */ ((CliErrorType2) => {
663
+ CliErrorType2["USER_INPUT"] = "USER_INPUT";
664
+ CliErrorType2["OPERATION"] = "OPERATION";
665
+ CliErrorType2["VALIDATION"] = "VALIDATION";
666
+ CliErrorType2["CANCEL"] = "CANCEL";
667
+ return CliErrorType2;
668
+ })(CliErrorType || {});
669
+ CliError = class _CliError extends Error {
670
+ /** 错误分类,决定后续处理策略 */
671
+ type;
672
+ /** 被包装的原始错误,未包装时为 undefined */
673
+ originalError;
674
+ /**
675
+ * 构造 CLI 错误
676
+ * @param type 错误分类
677
+ * @param message 错误消息
678
+ * @param originalError 被包装的原始错误
679
+ * @returns 无返回值
680
+ */
681
+ constructor(type, message, originalError) {
682
+ super(message);
683
+ this.name = "CliError";
684
+ this.type = type;
685
+ this.originalError = originalError;
686
+ Object.setPrototypeOf(this, _CliError.prototype);
687
+ }
688
+ /**
689
+ * 创建用户输入错误
690
+ * 用于用户提供的输入不符合要求的情况
691
+ * @param message 错误消息
692
+ * @returns 「CliError」实例
693
+ */
694
+ static userInput(message) {
695
+ return new _CliError("USER_INPUT" /* USER_INPUT */, message);
696
+ }
697
+ /**
698
+ * 创建验证错误
699
+ * 用于用户输入验证失败的情况
700
+ * @param message 错误消息
701
+ * @returns 「CliError」实例
702
+ */
703
+ static validation(message) {
704
+ return new _CliError("VALIDATION" /* VALIDATION */, message);
705
+ }
706
+ /**
707
+ * 创建操作失败错误
708
+ * 用于 CLI 操作执行失败的情况
709
+ * @param message 错误消息
710
+ * @param originalError 原始错误对象
711
+ * @returns 「CliError」实例
712
+ */
713
+ static operation(message, originalError) {
714
+ return new _CliError("OPERATION" /* OPERATION */, message, originalError);
715
+ }
716
+ /**
717
+ * 创建取消错误
718
+ * 用于用户主动取消操作的情况
719
+ * @param message 错误消息(默认为“操作已取消”)
720
+ * @returns 「CliError」实例
721
+ */
722
+ static cancel(message = "\u64CD\u4F5C\u5DF2\u53D6\u6D88") {
723
+ return new _CliError("CANCEL" /* CANCEL */, message);
724
+ }
725
+ /**
726
+ * 判断是否为用户输入类错误
727
+ * @returns 是否为用户输入类错误(含验证与取消)
728
+ */
729
+ isUserError() {
730
+ return this.type === "USER_INPUT" /* USER_INPUT */ || this.type === "VALIDATION" /* VALIDATION */ || this.type === "CANCEL" /* CANCEL */;
731
+ }
732
+ /**
733
+ * 判断是否为操作失败类错误
734
+ * @returns 是否为操作失败类错误
735
+ */
736
+ isOperationError() {
737
+ return this.type === "OPERATION" /* OPERATION */;
738
+ }
739
+ };
740
+ }
741
+ });
742
+
743
+ // src/utils/git.ts
744
+ import path3 from "node:path";
745
+ import { $ as $2 } from "execa";
746
+ import fs3 from "fs-extra";
747
+ var RAW_CHART_MODULE_REMOTES, normalizeGitRemoteUrl, CHART_MODULE_REMOTE_ALLOWLIST, isChartModuleRemoteUrl, hasChartModuleLayout, getGitRepoRoot, REMOTE_URL_PATTERN, getGitRemoteUrls, detectChartModuleByGit;
748
+ var init_git = __esm({
749
+ "src/utils/git.ts"() {
750
+ "use strict";
751
+ RAW_CHART_MODULE_REMOTES = [
752
+ "http://192.168.12.86:65535/pangu/thfea/ui/chart-module.git",
753
+ "https://gitlab.pangutech.dev/pangu/ui/pangu-roof-web/component/pangu-roof-chart.git"
754
+ ];
755
+ normalizeGitRemoteUrl = (url) => {
756
+ const trimmed = url.trim();
757
+ if (!trimmed) {
758
+ return "";
759
+ }
760
+ let body = trimmed;
761
+ let scheme = "";
762
+ const schemeMatch = /^(?<scheme>[a-zA-Z][a-zA-Z0-9+.-]*):\/\//.exec(trimmed);
763
+ if (schemeMatch?.groups?.scheme) {
764
+ scheme = schemeMatch.groups.scheme.toLowerCase();
765
+ body = trimmed.slice(schemeMatch[0].length);
766
+ }
767
+ let hostPort = "";
768
+ let pathPart = "";
769
+ if (scheme) {
770
+ const slashIndex = body.indexOf("/");
771
+ const authority = slashIndex === -1 ? body : body.slice(0, slashIndex);
772
+ hostPort = authority.includes("@") ? authority.slice(authority.lastIndexOf("@") + 1) : authority;
773
+ pathPart = slashIndex === -1 ? "" : body.slice(slashIndex);
774
+ } else {
775
+ const colonIndex = body.indexOf(":");
776
+ const slashIndex = body.indexOf("/");
777
+ if (colonIndex > 0 && (slashIndex === -1 || colonIndex < slashIndex)) {
778
+ const afterColon = body.slice(colonIndex + 1);
779
+ const hostSeg = body.slice(0, colonIndex);
780
+ const bareHost = hostSeg.includes("@") ? hostSeg.slice(hostSeg.lastIndexOf("@") + 1) : hostSeg;
781
+ const portForm = /^(?<port>\d+)\/(?<rest>.*)$/.exec(afterColon);
782
+ if (portForm?.groups?.port) {
783
+ hostPort = `${bareHost}:${portForm.groups.port}`;
784
+ pathPart = `/${portForm.groups.rest}`;
785
+ } else if (/^\d+$/.test(afterColon)) {
786
+ hostPort = `${bareHost}:${afterColon}`;
787
+ pathPart = "";
788
+ } else {
789
+ hostPort = bareHost;
790
+ pathPart = `/${afterColon}`;
791
+ }
792
+ } else {
793
+ hostPort = slashIndex === -1 ? body : body.slice(0, slashIndex);
794
+ if (hostPort.includes("@")) {
795
+ hostPort = hostPort.slice(hostPort.lastIndexOf("@") + 1);
796
+ }
797
+ pathPart = slashIndex === -1 ? "" : body.slice(slashIndex);
798
+ }
799
+ }
800
+ let port = "";
801
+ const hostColon = hostPort.lastIndexOf(":");
802
+ if (hostColon !== -1) {
803
+ const candidate = hostPort.slice(hostColon + 1);
804
+ if (/^\d+$/.test(candidate)) {
805
+ const defaultPorts = { http: "80", https: "443", ssh: "22" };
806
+ hostPort = hostPort.slice(0, hostColon);
807
+ if (candidate !== defaultPorts[scheme]) {
808
+ port = candidate;
809
+ }
810
+ }
811
+ }
812
+ let cleanPath = pathPart;
813
+ if (cleanPath.endsWith("/")) {
814
+ cleanPath = cleanPath.slice(0, -1);
815
+ }
816
+ if (cleanPath.toLowerCase().endsWith(".git")) {
817
+ cleanPath = cleanPath.slice(0, -4);
818
+ }
819
+ cleanPath = cleanPath.toLowerCase();
820
+ return `${hostPort.toLowerCase()}${port ? `:${port}` : ""}${cleanPath}`;
821
+ };
822
+ CHART_MODULE_REMOTE_ALLOWLIST = RAW_CHART_MODULE_REMOTES.map(normalizeGitRemoteUrl);
823
+ isChartModuleRemoteUrl = (url) => {
824
+ return CHART_MODULE_REMOTE_ALLOWLIST.includes(normalizeGitRemoteUrl(url));
825
+ };
826
+ hasChartModuleLayout = async (dir) => {
827
+ const [pkgExists, componentsExists, tailoredExists] = await Promise.all([
828
+ fs3.pathExists(path3.join(dir, "package.json")),
829
+ fs3.pathExists(path3.join(dir, "packages", "components")),
830
+ fs3.pathExists(path3.join(dir, "packages", "tailored"))
831
+ ]);
832
+ return pkgExists && componentsExists && tailoredExists;
833
+ };
834
+ getGitRepoRoot = async (cwd) => {
835
+ try {
836
+ const result = await $2({
837
+ cwd: cwd ?? process.cwd(),
838
+ reject: false,
839
+ timeout: 5e3
840
+ })`git rev-parse --show-toplevel`;
841
+ const root = (result.stdout ?? "").trim();
842
+ return root || null;
843
+ } catch {
844
+ return null;
845
+ }
846
+ };
847
+ REMOTE_URL_PATTERN = /^remote\..*\.url$/.source;
848
+ getGitRemoteUrls = async (cwd) => {
849
+ try {
850
+ const result = await $2({
851
+ cwd: cwd ?? process.cwd(),
852
+ reject: false,
853
+ timeout: 5e3
854
+ })`git config --get-regexp ${REMOTE_URL_PATTERN}`;
855
+ const stdout = (result.stdout ?? "").trim();
856
+ if (!stdout) {
857
+ return [];
858
+ }
859
+ return stdout.split("\n").map((line) => line.slice(line.indexOf(" ") + 1).trim()).filter(Boolean);
860
+ } catch {
861
+ return [];
862
+ }
863
+ };
864
+ detectChartModuleByGit = async () => {
865
+ const root = await getGitRepoRoot();
866
+ if (!root) {
867
+ return false;
868
+ }
869
+ const remotes = await getGitRemoteUrls();
870
+ if (!remotes.some(isChartModuleRemoteUrl)) {
871
+ return false;
872
+ }
873
+ if (!await hasChartModuleLayout(root)) {
874
+ if (process.env.DEBUG === "true") {
875
+ console.debug(
876
+ `[detectChartModuleByGit] remote \u547D\u4E2D\u767D\u540D\u5355\u4F46\u76EE\u5F55\u5E03\u5C40\u6821\u9A8C\u672A\u901A\u8FC7\uFF0C\u964D\u7EA7\u7ED3\u6784\u626B\u63CF: ${root}`
877
+ );
878
+ }
879
+ return false;
880
+ }
881
+ return { root };
882
+ };
883
+ }
884
+ });
885
+
886
+ // src/utils/fs.ts
887
+ import path4 from "node:path";
888
+ import { to as to2 } from "await-to-js";
889
+ import fs4 from "fs-extra";
890
+ import _2 from "lodash";
891
+ import tar from "tar";
892
+ var mergeWith, isArray, getPath, buildTarHandler, filterFile, scanDirHandle, updatePackageJson, outputVueName, isChartModuleRoot, scanFileFindChart, cachedScanResult, cachedScanRoot, scanAllDirectories, clearScanCache;
893
+ var init_fs = __esm({
894
+ "src/utils/fs.ts"() {
895
+ "use strict";
896
+ init_log();
897
+ init_git();
898
+ ({ mergeWith, isArray } = _2);
899
+ getPath = (targetPath) => {
900
+ const cwd = process.cwd();
901
+ if (targetPath.includes(cwd)) {
902
+ return targetPath;
903
+ }
904
+ return path4.resolve(cwd, targetPath);
905
+ };
906
+ buildTarHandler = async (targetPath, name, distPath = null, distName = null) => {
907
+ targetPath = getPath(targetPath);
908
+ if (distPath) {
909
+ distPath = getPath(distPath);
910
+ await fs4.ensureDir(distPath);
911
+ }
912
+ return new Promise((resolve, reject) => {
913
+ const options = {
914
+ gzip: true,
915
+ cwd: targetPath,
916
+ sync: true
917
+ };
918
+ const list = typeof name === "string" ? [name] : name;
919
+ const tarName = distName || (typeof name === "string" ? name : `tar_${Date.now()}`);
920
+ const writeStream = fs4.createWriteStream(`${distPath || targetPath}/${tarName}.tar.gz`);
921
+ const tarStream = tar.c(options, list);
922
+ tarStream.pipe(writeStream).on("finish", resolve).on("error", reject);
923
+ tarStream.on("error", reject);
924
+ writeStream.on("error", reject);
925
+ });
926
+ };
927
+ filterFile = async (dirPath, ignoreFiles = [".git", ".vscode", ".DS_Store", ".idea"]) => {
928
+ const dir = dirPath || process.cwd();
929
+ const res = await fs4.pathExists(dir);
930
+ if (res) {
931
+ const isDir = await fs4.stat(dir);
932
+ if (isDir.isDirectory()) {
933
+ const [err, resDir] = await to2(fs4.readdir(dir));
934
+ if (err) {
935
+ return exit(err.message);
936
+ }
937
+ await Promise.all(resDir.map((v) => filterFile(path4.resolve(dir, v), ignoreFiles)));
938
+ } else {
939
+ for (const ignoreFile of ignoreFiles) {
940
+ if (dir.includes(ignoreFile)) {
941
+ await fs4.remove(dir);
942
+ return;
943
+ }
944
+ }
945
+ }
946
+ }
947
+ };
948
+ scanDirHandle = async (dir, ignorePattern) => {
949
+ const list = [];
950
+ const exists = await fs4.pathExists(dir);
951
+ if (exists) {
952
+ const stats = await fs4.stat(dir);
953
+ if (stats.isDirectory()) {
954
+ const [err, resDir] = await to2(fs4.readdir(dir));
955
+ if (err) {
956
+ exit(err.message);
957
+ return list;
958
+ }
959
+ for (const item of resDir) {
960
+ const itemPath = path4.resolve(dir, item);
961
+ const itemStats = await fs4.stat(itemPath);
962
+ if (itemStats.isDirectory()) {
963
+ if (ignorePattern && ignorePattern.length > 0) {
964
+ const shouldIgnore = ignorePattern.some((pattern) => item.startsWith(pattern));
965
+ if (!shouldIgnore) {
966
+ list.push(item);
967
+ }
968
+ } else {
969
+ list.push(item);
970
+ }
971
+ }
972
+ }
973
+ }
974
+ }
975
+ return list;
976
+ };
977
+ updatePackageJson = async (fPath, option) => {
978
+ const p2 = path4.join(fPath, "package.json");
979
+ const [err, res] = await to2(fs4.readJson(p2));
980
+ if (err) {
981
+ exit(err?.message);
982
+ } else if (res) {
983
+ mergeWith(res, option, (objValue, srcValue) => {
984
+ if (isArray(objValue)) {
985
+ return objValue.concat(srcValue);
986
+ }
987
+ return void 0;
988
+ });
989
+ await fs4.outputJson(p2, res, { spaces: 2, EOL: "\n" });
990
+ }
991
+ };
992
+ outputVueName = async (p2, name) => {
993
+ const str = `
994
+ <script setup>
995
+ import { defineProps, defineEmits, defineOptions } from 'vue';
996
+ defineProps({
997
+ styled: Object,
998
+ data: Object,
999
+ width: Number,
1000
+ height: Number,
1001
+ events: Array,
1002
+ option: Object
1003
+ });
1004
+ defineEmits(['message']);
1005
+ defineOptions({
1006
+ name: '${name}'
1007
+ })
1008
+ </script>`;
1009
+ await fs4.appendFile(p2, str);
1010
+ return;
1011
+ };
1012
+ isChartModuleRoot = async (dir, packageName) => {
1013
+ if (typeof packageName !== "string" || !packageName.includes("pangu")) {
1014
+ return false;
1015
+ }
1016
+ const [componentsExists, tailoredExists] = await Promise.all([
1017
+ fs4.pathExists(path4.join(dir, "packages", "components")),
1018
+ fs4.pathExists(path4.join(dir, "packages", "tailored"))
1019
+ ]);
1020
+ return componentsExists && tailoredExists;
1021
+ };
1022
+ scanFileFindChart = async (maxDepth = 1) => {
1023
+ try {
1024
+ const gitHit = await detectChartModuleByGit();
1025
+ if (gitHit) {
1026
+ return gitHit;
1027
+ }
1028
+ } catch {
1029
+ }
1030
+ for (let i = 0; i < maxDepth; i++) {
1031
+ let relativePath = "./";
1032
+ if (i > 0) {
1033
+ relativePath += "../".repeat(i);
1034
+ }
1035
+ const cwd = path4.resolve(process.cwd(), relativePath);
1036
+ const packageJsonPath = path4.resolve(cwd, "package.json");
1037
+ if (await fs4.pathExists(packageJsonPath)) {
1038
+ try {
1039
+ const pkg = await fs4.readJson(packageJsonPath);
1040
+ if (await isChartModuleRoot(cwd, pkg.name)) {
1041
+ return { root: cwd };
1042
+ }
1043
+ } catch (error) {
1044
+ if (process.env.DEBUG === "true") {
1045
+ console.debug(
1046
+ `[scanFileFindChart] Failed to read package.json at ${packageJsonPath}:`,
1047
+ error
1048
+ );
1049
+ }
1050
+ }
1051
+ }
1052
+ }
1053
+ return false;
1054
+ };
1055
+ cachedScanResult = null;
1056
+ cachedScanRoot = null;
1057
+ scanAllDirectories = async (chartModuleRoot, ignorePattern) => {
1058
+ if (cachedScanResult && cachedScanRoot === chartModuleRoot) {
1059
+ return cachedScanResult;
1060
+ }
1061
+ const [rootList, packList, componentList, tailoredList] = await Promise.all([
1062
+ scanDirHandle(chartModuleRoot, ignorePattern),
1063
+ scanDirHandle(path4.join(chartModuleRoot, "packages"), ignorePattern),
1064
+ scanDirHandle(path4.join(chartModuleRoot, "packages", "components"), ignorePattern),
1065
+ scanDirHandle(path4.join(chartModuleRoot, "packages", "tailored"), ignorePattern)
1066
+ ]);
1067
+ cachedScanResult = {
1068
+ rootList,
1069
+ packList,
1070
+ componentList,
1071
+ tailoredList
1072
+ };
1073
+ cachedScanRoot = chartModuleRoot;
1074
+ return cachedScanResult;
1075
+ };
1076
+ clearScanCache = () => {
1077
+ cachedScanResult = null;
1078
+ cachedScanRoot = null;
1079
+ };
1080
+ }
1081
+ });
1082
+
1083
+ // src/utils/index.ts
1084
+ var utils_exports = {};
1085
+ __export(utils_exports, {
1086
+ CliError: () => CliError,
1087
+ CliErrorType: () => CliErrorType,
1088
+ assertValidation: () => assertValidation,
1089
+ buildTarHandler: () => buildTarHandler,
1090
+ checkNpmConnectionState: () => checkNpmConnectionState,
1091
+ checkUpdate: () => checkUpdate,
1092
+ clearScanCache: () => clearScanCache,
1093
+ compareVersion: () => compareVersion,
1094
+ confirmPrompt: () => confirmPrompt,
1095
+ detectPackageManager: () => detectPackageManager,
1096
+ exit: () => exit,
1097
+ filterFile: () => filterFile,
1098
+ getCdRelativePath: () => getCdRelativePath,
1099
+ getCurrentVersion: () => getCurrentVersion,
1100
+ getGitUser: () => getGitUser,
1101
+ getLatestVersion: () => getLatestVersion,
1102
+ getPackageName: () => getPackageName,
1103
+ getPath: () => getPath,
1104
+ getPrivateSource: () => getPrivateSource,
1105
+ get_cli_config: () => get_cli_config,
1106
+ get_plugin_latest_version: () => get_plugin_latest_version2,
1107
+ get_update_log: () => get_update_log,
1108
+ groupPrompts: () => groupPrompts,
1109
+ handleCancel: () => handleCancel,
1110
+ handleCliError: () => handleCliError,
1111
+ intro: () => intro2,
1112
+ log: () => log,
1113
+ multiselectPrompt: () => multiselectPrompt,
1114
+ note: () => note2,
1115
+ outputVueName: () => outputVueName,
1116
+ outro: () => outro2,
1117
+ packagePath: () => packagePath,
1118
+ passwordPrompt: () => passwordPrompt,
1119
+ progress: () => progress,
1120
+ prompt: () => prompt,
1121
+ runAsyncCmd: () => runAsyncCmd,
1122
+ scanAllDirectories: () => scanAllDirectories,
1123
+ scanDirHandle: () => scanDirHandle,
1124
+ scanFileFindChart: () => scanFileFindChart,
1125
+ selectPrompt: () => selectPrompt,
1126
+ setUpdateCheckTime: () => setUpdateCheckTime,
1127
+ set_cli_config: () => set_cli_config,
1128
+ set_update_log: () => set_update_log,
1129
+ shouldCheckUpdate: () => shouldCheckUpdate,
1130
+ spinner: () => spinner2,
1131
+ textPrompt: () => textPrompt,
1132
+ togglePrompt: () => togglePrompt,
1133
+ updatePackageJson: () => updatePackageJson,
1134
+ userInfo: () => userInfo,
1135
+ wait: () => wait,
1136
+ welcomeCli: () => welcomeCli,
1137
+ wrapAsyncOperation: () => wrapAsyncOperation
1138
+ });
1139
+ import * as p from "@clack/prompts";
1140
+ async function textPrompt(options) {
1141
+ return promptUntilValid("text", options);
1142
+ }
1143
+ async function passwordPrompt(options) {
1144
+ return promptUntilValid("password", options);
1145
+ }
1146
+ async function confirmPrompt(options) {
1147
+ const confirmOptions = {
1148
+ message: options.message,
1149
+ initialValue: options.initialValue ?? false
1150
+ };
1151
+ const result = await p.confirm(confirmOptions);
1152
+ return handleCancel(result);
1153
+ }
1154
+ async function selectPrompt(options) {
1155
+ const mappedOptions = options.options.map((o) => ({
1156
+ value: o.value,
1157
+ label: o.label ?? o.value,
1158
+ ...o.hint !== void 0 && { hint: o.hint }
1159
+ }));
1160
+ const result = await p.select({
1161
+ message: options.message,
1162
+ options: mappedOptions
1163
+ });
1164
+ return handleCancel(result);
1165
+ }
1166
+ async function multiselectPrompt(options) {
1167
+ const mappedOptions = options.options.map((o) => ({
1168
+ value: o.value,
1169
+ label: o.label ?? o.value,
1170
+ ...o.hint !== void 0 && { hint: o.hint }
1171
+ }));
1172
+ const result = await p.multiselect({
1173
+ message: options.message,
1174
+ options: mappedOptions,
1175
+ initialValues: options.initialValues ?? [],
1176
+ required: options.required ?? false
1177
+ });
1178
+ return handleCancel(result);
1179
+ }
1180
+ async function togglePrompt(options) {
1181
+ const result = await p.confirm({
1182
+ message: `${options.message} (${options.active}/${options.inactive})`,
1183
+ initialValue: options.initialValue ?? false
1184
+ });
1185
+ return handleCancel(result);
1186
+ }
1187
+ async function groupPrompts(prompts) {
1188
+ const results = await p.group(prompts, {
1189
+ onCancel: () => {
1190
+ exit("\u64CD\u4F5C\u5DF2\u53D6\u6D88");
1191
+ }
1192
+ });
1193
+ return results;
1194
+ }
1195
+ async function prompt(list) {
1196
+ const promptFunctions = {};
1197
+ for (const item of list) {
1198
+ promptFunctions[item.name] = async () => {
1199
+ const handler = promptHandlers[item.type];
1200
+ if (handler) {
1201
+ return handler(item);
1202
+ }
1203
+ return item.initial;
1204
+ };
1205
+ }
1206
+ return groupPrompts(promptFunctions);
1207
+ }
1208
+ async function progress(items, handler, options) {
1209
+ if (options?.showProgress && items.length > 0) {
1210
+ const s = spinner2(options?.title ?? "\u5904\u7406\u4E2D...");
1211
+ s.start();
1212
+ for (let i = 0; i < items.length; i++) {
1213
+ const item = items[i];
1214
+ if (item !== void 0) {
1215
+ await handler(item, i);
1216
+ }
1217
+ s.message(`\u5904\u7406 ${i + 1}/${items.length}`);
1218
+ }
1219
+ s.succeed("\u5904\u7406\u5B8C\u6210");
1220
+ } else {
1221
+ for (let i = 0; i < items.length; i++) {
1222
+ const item = items[i];
1223
+ if (item !== void 0) {
1224
+ await handler(item, i);
1225
+ }
1226
+ }
1227
+ }
1228
+ }
1229
+ var import_picocolors2, spinner2, intro2, outro2, note2, handleCancel, normalizeValidationResult, validatePromptValue, promptUntilValid, promptHandlers, checkUpdate;
1230
+ var init_utils = __esm({
1231
+ "src/utils/index.ts"() {
1232
+ "use strict";
1233
+ init_api();
1234
+ init_process();
1235
+ init_config();
1236
+ init_error();
1237
+ init_fs();
1238
+ init_log();
1239
+ import_picocolors2 = __toESM(require_picocolors(), 1);
1240
+ init_api();
1241
+ init_config();
1242
+ init_log();
1243
+ spinner2 = (message) => {
1244
+ const s = p.spinner();
1245
+ if (message) s.start(message);
1246
+ return {
1247
+ start: (msg) => s.start(msg),
1248
+ stop: (msg, code) => s.stop(msg, code),
1249
+ succeed: (msg) => s.stop(msg, 0),
1250
+ fail: (msg) => s.stop(msg, 1),
1251
+ warn: (msg) => s.stop(msg, 2),
1252
+ info: (msg) => s.stop(msg, 3),
1253
+ message: (msg) => s.message(msg)
1254
+ };
1255
+ };
1256
+ intro2 = (title) => p.intro(import_picocolors2.default.bgCyan(import_picocolors2.default.black(` ${title} `)));
1257
+ outro2 = (message) => {
1258
+ if (message) p.outro(import_picocolors2.default.green(message));
1259
+ else p.outro();
1260
+ };
1261
+ note2 = (message, title) => p.note(message, title);
1262
+ handleCancel = (result) => {
1263
+ if (typeof result === "symbol") {
1264
+ exit("\u64CD\u4F5C\u5DF2\u53D6\u6D88");
1265
+ }
1266
+ return result;
1267
+ };
1268
+ normalizeValidationResult = async (result) => {
1269
+ if (result === true) return void 0;
1270
+ if (result === false) return "\u9A8C\u8BC1\u5931\u8D25";
1271
+ return result;
1272
+ };
1273
+ validatePromptValue = async (value, validate) => {
1274
+ if (!validate) return void 0;
1275
+ return normalizeValidationResult(await validate(value));
1276
+ };
1277
+ promptUntilValid = async (type, options) => {
1278
+ while (true) {
1279
+ const promptOptions = {
1280
+ message: options.message
1281
+ };
1282
+ if (options.initialValue !== void 0) {
1283
+ promptOptions.initialValue = options.initialValue;
1284
+ }
1285
+ const result = type === "text" ? await p.text(promptOptions) : await p.password({ message: options.message });
1286
+ const value = handleCancel(result);
1287
+ const validationMessage = await validatePromptValue(value, options.validate);
1288
+ if (validationMessage === void 0) {
1289
+ return value;
1290
+ }
1291
+ log.warn(validationMessage);
1292
+ }
1293
+ };
1294
+ promptHandlers = {
1295
+ /** 处理 text 类型:适配旧字段后转调「textPrompt」 */
1296
+ text: async (item) => {
1297
+ const textOpts = {
1298
+ message: item.message
1299
+ };
1300
+ if (item.initial !== void 0) textOpts.initialValue = item.initial;
1301
+ if (item.validate !== void 0) {
1302
+ textOpts.validate = async (value) => {
1303
+ const result = await item.validate?.(value);
1304
+ return normalizeValidationResult(result);
1305
+ };
1306
+ }
1307
+ return textPrompt(textOpts);
1308
+ },
1309
+ /** 处理 password 类型:适配旧字段后转调「passwordPrompt」 */
1310
+ password: async (item) => {
1311
+ const pwdOpts = {
1312
+ message: item.message
1313
+ };
1314
+ if (item.validate !== void 0) {
1315
+ pwdOpts.validate = async (value) => {
1316
+ const result = await item.validate?.(value);
1317
+ return normalizeValidationResult(result);
1318
+ };
1319
+ }
1320
+ return passwordPrompt(pwdOpts);
1321
+ },
1322
+ /** 处理 select 类型:将旧 choices 映射为选项列表 */
1323
+ select: async (item) => {
1324
+ const selectOptions = {
1325
+ message: item.message,
1326
+ options: (item.choices ?? []).map((c) => ({
1327
+ value: c.value,
1328
+ label: c.title
1329
+ }))
1330
+ };
1331
+ if (typeof item.initial === "string") {
1332
+ selectOptions.initialValue = item.initial;
1333
+ }
1334
+ return selectPrompt(selectOptions);
1335
+ },
1336
+ /** 处理 toggle 类型:补齐两态文案的缺省值 */
1337
+ toggle: async (item) => {
1338
+ const toggleOptions = {
1339
+ message: item.message,
1340
+ active: item.active ?? "yes",
1341
+ inactive: item.inactive ?? "no"
1342
+ };
1343
+ if (typeof item.initial === "boolean") {
1344
+ toggleOptions.initialValue = item.initial;
1345
+ }
1346
+ return togglePrompt(toggleOptions);
1347
+ },
1348
+ /** 处理 confirm 类型:布尔初始值透传给确认提示 */
1349
+ confirm: async (item) => {
1350
+ const confirmOptions = {
1351
+ message: item.message
1352
+ };
1353
+ if (typeof item.initial === "boolean") {
1354
+ confirmOptions.initialValue = item.initial;
1355
+ }
1356
+ return confirmPrompt(confirmOptions);
1357
+ },
1358
+ /** 处理 multiselect 类型:旧 choices 映射为多选项列表 */
1359
+ multiselect: async (item) => {
1360
+ const multiselectOptions = {
1361
+ message: item.message,
1362
+ options: (item.choices ?? []).map((c) => ({
1363
+ value: c.value,
1364
+ label: c.title
1365
+ })),
1366
+ required: false
1367
+ };
1368
+ if (Array.isArray(item.initial)) {
1369
+ multiselectOptions.initialValues = item.initial;
1370
+ }
1371
+ return multiselectPrompt(multiselectOptions);
1372
+ }
1373
+ };
1374
+ checkUpdate = async (forceCheck = false) => {
1375
+ try {
1376
+ if (!forceCheck) {
1377
+ const shouldCheck = await shouldCheckUpdate();
1378
+ if (!shouldCheck) {
1379
+ return null;
1380
+ }
1381
+ }
1382
+ const latestVersion = await getLatestVersion("pangu-vis-cli");
1383
+ if (!latestVersion) {
1384
+ return null;
1385
+ }
1386
+ const currentVersion = await getCurrentVersion();
1387
+ await setUpdateCheckTime();
1388
+ const hasUpdate = latestVersion !== currentVersion;
1389
+ return {
1390
+ hasUpdate,
1391
+ currentVersion,
1392
+ latestVersion
1393
+ };
1394
+ } catch (_error) {
1395
+ return null;
1396
+ }
1397
+ };
1398
+ }
1399
+ });
1400
+
1401
+ // src/schemas/chart-type.ts
1402
+ import { z } from "zod";
1403
+ var chartTypeSchema, chartTypeLabels;
1404
+ var init_chart_type = __esm({
1405
+ "src/schemas/chart-type.ts"() {
1406
+ "use strict";
1407
+ chartTypeSchema = z.enum(
1408
+ [
1409
+ "line",
1410
+ // 折线图
1411
+ "bar",
1412
+ // 柱状图
1413
+ "pie",
1414
+ // 饼图
1415
+ "form",
1416
+ // 表格
1417
+ "other",
1418
+ // 其他
1419
+ "map",
1420
+ // 地图
1421
+ "text",
1422
+ // 文本
1423
+ "indicator",
1424
+ // 指标
1425
+ "interaction"
1426
+ // 交互
1427
+ ],
1428
+ {
1429
+ error: "\u56FE\u8868\u7C7B\u578B\u5FC5\u987B\u662F\u6709\u6548\u7684\u679A\u4E3E\u503C"
1430
+ }
1431
+ );
1432
+ chartTypeLabels = {
1433
+ line: "\u6298\u7EBF\u56FE",
1434
+ bar: "\u67F1\u72B6\u56FE",
1435
+ pie: "\u997C\u56FE",
1436
+ form: "\u8868\u683C",
1437
+ other: "\u5176\u4ED6",
1438
+ map: "\u5730\u56FE",
1439
+ text: "\u6587\u672C",
1440
+ indicator: "\u6307\u6807",
1441
+ interaction: "\u4EA4\u4E92"
1442
+ };
1443
+ }
1444
+ });
1445
+
1446
+ // src/schemas/config.ts
1447
+ import { z as z2 } from "zod";
1448
+ var cliConfigSchema, cliConfigUpdateSchema;
1449
+ var init_config2 = __esm({
1450
+ "src/schemas/config.ts"() {
1451
+ "use strict";
1452
+ cliConfigSchema = z2.object({
1453
+ // 自动删除打包目录
1454
+ autoRemove: z2.boolean({
1455
+ error: "autoRemove \u5FC5\u987B\u662F\u5E03\u5C14\u503C"
1456
+ }).default(true),
1457
+ // 自动移除 es 目录
1458
+ autoRemoveEs: z2.boolean({
1459
+ error: "autoRemoveEs \u5FC5\u987B\u662F\u5E03\u5C14\u503C"
1460
+ }).default(true),
1461
+ // 上次检查 CLI 版本更新的时间戳
1462
+ lastUpdateCheck: z2.number().optional(),
1463
+ // 私有 npm 源地址
1464
+ privateRegistry: z2.string().optional()
1465
+ });
1466
+ cliConfigUpdateSchema = cliConfigSchema.partial();
1467
+ }
1468
+ });
1469
+
1470
+ // src/schemas/project-name.ts
1471
+ import { z as z3 } from "zod";
1472
+ function formatProjectNameError(error) {
1473
+ const issues = error.issues;
1474
+ if (issues.length === 0) return "\u672A\u77E5\u9519\u8BEF";
1475
+ return issues.map((issue) => issue.message).join("; ");
1476
+ }
1477
+ function validateProjectName(name) {
1478
+ const result = projectNameSchema.safeParse(name);
1479
+ if (result.success) {
1480
+ return true;
1481
+ }
1482
+ return formatProjectNameError(result.error);
1483
+ }
1484
+ var projectNameSchema;
1485
+ var init_project_name = __esm({
1486
+ "src/schemas/project-name.ts"() {
1487
+ "use strict";
1488
+ projectNameSchema = z3.string({
1489
+ error: "\u9879\u76EE\u540D\u5FC5\u987B\u662F\u5B57\u7B26\u4E32"
1490
+ }).regex(/^[a-z][a-z0-9_]*$/, {
1491
+ message: "\u5305\u540D\u53EA\u5141\u8BB8\u4EE5\u5C0F\u5199\u82F1\u6587\u5B57\u6BCD\u5F00\u5934\uFF0C\u53EA\u5141\u8BB8\u4F7F\u7528\u5C0F\u5199\u82F1\u6587\u5B57\u6BCD\u3001\u6570\u5B57\u548C\u4E0B\u5212\u7EBF"
1492
+ }).min(1, {
1493
+ message: "\u9879\u76EE\u540D\u4E0D\u80FD\u4E3A\u7A7A"
1494
+ }).max(100, {
1495
+ message: "\u9879\u76EE\u540D\u957F\u5EA6\u4E0D\u80FD\u8D85\u8FC7100\u4E2A\u5B57\u7B26"
1496
+ });
1497
+ }
1498
+ });
1499
+
1500
+ // src/schemas/index.ts
1501
+ var init_schemas = __esm({
1502
+ "src/schemas/index.ts"() {
1503
+ "use strict";
1504
+ init_error();
1505
+ init_chart_type();
1506
+ init_config2();
1507
+ init_project_name();
1508
+ }
1509
+ });
1510
+
1511
+ // src/create/chart.ts
1512
+ import path5 from "node:path";
1513
+ import fs5 from "fs-extra";
1514
+ async function renameIfExists(from, to4) {
1515
+ if (await fs5.pathExists(from)) {
1516
+ await fs5.rename(from, to4);
1517
+ }
1518
+ }
1519
+ async function applyTypeScriptFileNames(projectPath) {
1520
+ const srcPath = path5.resolve(projectPath, "src");
1521
+ await renameIfExists(
1522
+ path5.resolve(projectPath, "render.js"),
1523
+ path5.resolve(projectPath, "render.ts")
1524
+ );
1525
+ await renameIfExists(path5.resolve(srcPath, "config.js"), path5.resolve(srcPath, "config.ts"));
1526
+ await renameIfExists(path5.resolve(srcPath, "data.js"), path5.resolve(srcPath, "data.ts"));
1527
+ await renameIfExists(path5.resolve(srcPath, "style.js"), path5.resolve(srcPath, "style.ts"));
1528
+ await fs5.remove(path5.resolve(projectPath, "jsconfig.json"));
1529
+ }
1530
+ async function getStandaloneDependencyVersion(packageName, defaultVersion, shouldCheckLatest) {
1531
+ if (!packageName) {
1532
+ return {};
1533
+ }
1534
+ if (!shouldCheckLatest) {
1535
+ return {
1536
+ [packageName]: `^${defaultVersion}`
1537
+ };
1538
+ }
1539
+ return get_plugin_latest_version2(packageName, defaultVersion);
1540
+ }
1541
+ async function handleChartTemplate(options) {
1542
+ const { projectName, projectPath, chartModule, author, chartType, chartId, isTs } = options;
1543
+ const isInner = await checkNpmConnectionState({ showSpinner: false });
1544
+ await fs5.outputJson(
1545
+ path5.resolve(projectPath, "public", "base.json"),
1546
+ {
1547
+ name: projectName,
1548
+ label: projectName,
1549
+ desc: "Custom Chart",
1550
+ version: "1.0.0",
1551
+ width: 480,
1552
+ height: 240,
1553
+ type: chartType || "other",
1554
+ author,
1555
+ id: chartId
1556
+ },
1557
+ { spaces: 2, EOL: "\n" }
1558
+ );
1559
+ await fs5.appendFile(
1560
+ path5.resolve(projectPath, "index.js"),
1561
+ `
1562
+ export const ${getPackageName(projectName)} = component`
1563
+ );
1564
+ await outputVueName(path5.resolve(projectPath, "src", "index.vue"), projectName);
1565
+ await updatePackageJson(projectPath, {
1566
+ name: projectName,
1567
+ author
1568
+ });
1569
+ if (chartModule) {
1570
+ await updatePackageJson(projectPath, {
1571
+ name: projectName,
1572
+ author,
1573
+ devDependencies: {
1574
+ "@chart/utils": "workspace:*"
1575
+ }
1576
+ });
1577
+ } else {
1578
+ const STANDALONE_DEV_DEPENDENCIES = async () => {
1579
+ return {
1580
+ ...await getStandaloneDependencyVersion("pangu-chart-cli", "1.0.2", isInner),
1581
+ ...await getStandaloneDependencyVersion(
1582
+ isInner ? "@pangu/vchart-config" : "",
1583
+ "1.1.0",
1584
+ isInner
1585
+ ),
1586
+ ...await getStandaloneDependencyVersion(
1587
+ isInner ? "" : "pangu-vchart-theme",
1588
+ "1.0.2",
1589
+ isInner
1590
+ ),
1591
+ "@vitejs/plugin-vue": "3.2.0",
1592
+ sass: "1.69.7",
1593
+ vite: "4.5.5",
1594
+ "vite-plugin-compression": "0.5.1",
1595
+ "vite-plugin-banner": "0.7.1"
1596
+ };
1597
+ };
1598
+ const STANDALONE_DEPENDENCIES = {
1599
+ vue: "~3.3.13",
1600
+ "yann-i18n": "1.0.7"
1601
+ };
1602
+ await updatePackageJson(projectPath, {
1603
+ name: projectName,
1604
+ author,
1605
+ devDependencies: await STANDALONE_DEV_DEPENDENCIES(),
1606
+ dependencies: STANDALONE_DEPENDENCIES
1607
+ });
1608
+ if (!isInner) {
1609
+ await fs5.writeFile(
1610
+ path5.resolve(projectPath, "example/App.vue"),
1611
+ `<script setup>
1612
+ import { computed } from 'vue'
1613
+ import ChartInfo from '../index'
1614
+ import base from '../public/base.json'
1615
+ import { createTheme } from 'pangu-vchart-theme'
1616
+ const { component: Chart, data, style } = ChartInfo
1617
+ const layerBoxStyle = computed(() => {
1618
+ return {
1619
+ width: base.width + 'px',
1620
+ height: base.height + 'px'
1621
+ }
1622
+ })
1623
+
1624
+ const chartData = computed(() => {
1625
+ return typeof data === 'function' ? data('zh') : data
1626
+ })
1627
+
1628
+ const chartStyle = computed(() => {
1629
+ return typeof style === 'function' ? style(createTheme()) : style
1630
+ })
1631
+ </script>
1632
+
1633
+ <template>
1634
+ <div class="box">
1635
+ <!-- \u56FE\u8868\u76D2\u5B50 -->
1636
+ <div class="layerBox" :style="layerBoxStyle">
1637
+ <!-- \u56FE\u8868\u5177\u4F53\u5185\u5BB9 -->
1638
+ <div class="layerMain">
1639
+ <!-- \u4E0A\u9762\u90A3\u4E9Bdiv\u4E0D\u7528\u53BB\u7BA1\uFF0C\u5E73\u53F0\u4F1A\u81EA\u52A8\u751F\u6210 -->
1640
+ <Chart
1641
+ :width="base.width"
1642
+ :height="base.height"
1643
+ :data="chartData"
1644
+ :styled="chartStyle"
1645
+ :events="events"
1646
+ />
1647
+ </div>
1648
+ </div>
1649
+ </div>
1650
+ </template>
1651
+ <style scoped lang="scss">
1652
+ .box {
1653
+ width: 100vw;
1654
+ height: 100vh;
1655
+ background-color: #242424;
1656
+ position: fixed;
1657
+ left: 0;
1658
+ top: 0;
1659
+ display: flex;
1660
+ align-items: center;
1661
+ flex-direction: column;
1662
+ justify-content: center;
1663
+ z-index: 10;
1664
+ .takeBtn {
1665
+ margin-top: 15px;
1666
+ }
1667
+ .layerBox {
1668
+ position: relative;
1669
+ display: flex;
1670
+ flex-direction: column;
1671
+ background: #2a2a34;
1672
+ border-radius: 12px;
1673
+ padding: 15px;
1674
+
1675
+ .layerMain {
1676
+ flex: 1;
1677
+ display: flex;
1678
+ align-items: center;
1679
+ justify-content: center;
1680
+ }
1681
+ }
1682
+ }
1683
+ </style>
1684
+ `
1685
+ );
1686
+ await fs5.writeFile(
1687
+ path5.resolve(projectPath, ".npmrc"),
1688
+ `registry=https://registry.npmmirror.com/
1689
+ strict-peer-dependencies=false`
1690
+ );
1691
+ }
1692
+ }
1693
+ if (isTs) {
1694
+ await applyTypeScriptFileNames(projectPath);
1695
+ }
1696
+ }
1697
+ var init_chart = __esm({
1698
+ "src/create/chart.ts"() {
1699
+ "use strict";
1700
+ init_utils();
1701
+ }
1702
+ });
1703
+
1704
+ // src/create/index.ts
1705
+ var create_exports = {};
1706
+ __export(create_exports, {
1707
+ default: () => create,
1708
+ resolveTemplatePath: () => resolveTemplatePath
1709
+ });
1710
+ import path6 from "node:path";
1711
+ import { fileURLToPath } from "node:url";
1712
+ import clear from "clear";
1713
+ import { $ as $3 } from "execa";
1714
+ import fs6 from "fs-extra";
1715
+ async function resolveTemplatePath(templateName, baseDir = __dirname) {
1716
+ const candidates = Array.from(new Set(getTemplatePathCandidates(templateName, baseDir)));
1717
+ for (const candidate of candidates) {
1718
+ if (await fs6.pathExists(candidate)) {
1719
+ return candidate;
1720
+ }
1721
+ }
1722
+ throw new Error(`\u6A21\u677F\u76EE\u5F55\u4E0D\u5B58\u5728: ${templateName}
1723
+ \u5DF2\u5C1D\u8BD5:
1724
+ ${candidates.join("\n")}`);
1725
+ }
1726
+ async function create(commandList = []) {
1727
+ intro2("\u521B\u5EFA\u56FE\u8868\u9879\u76EE");
1728
+ const templateType = "chart";
1729
+ const ChartModule = await scanFileFindChart();
1730
+ const answers = await groupPrompts({
1731
+ chartType: async () => selectPrompt({
1732
+ message: "\u8BF7\u9009\u62E9\u56FE\u8868\u7C7B\u578B:",
1733
+ options: CHART_TYPES,
1734
+ initialValue: "other"
1735
+ }),
1736
+ isTs: async () => togglePrompt({
1737
+ message: "\u662F\u5426\u4F7F\u7528 TypeScript?",
1738
+ active: "yes",
1739
+ inactive: "no",
1740
+ initialValue: false
1741
+ })
1742
+ });
1743
+ const { chartType, isTs } = answers;
1744
+ const chartTypeValidation = chartTypeSchema.safeParse(chartType);
1745
+ if (!chartTypeValidation.success) {
1746
+ exit(`\u65E0\u6548\u7684\u56FE\u8868\u7C7B\u578B: ${chartType}`);
1747
+ return;
1748
+ }
1749
+ const validatedChartType = chartTypeValidation.data;
1750
+ const checkRepeat = async (str) => {
1751
+ const ignorePattern = [".", "_"];
1752
+ if (ChartModule) {
1753
+ const { rootList, packList, componentList, tailoredList } = await scanAllDirectories(
1754
+ ChartModule.root,
1755
+ ignorePattern
1756
+ );
1757
+ if (rootList.includes(str) || packList.includes(str) || componentList.includes(str) || tailoredList.includes(str)) {
1758
+ return true;
1759
+ }
1760
+ } else {
1761
+ const list = await scanDirHandle(process.cwd(), ignorePattern);
1762
+ if (list.includes(str)) {
1763
+ return true;
1764
+ }
1765
+ }
1766
+ return false;
1767
+ };
1768
+ log.info("\u63A8\u8350\u6DFB\u52A0\u81EA\u5B9A\u4E49\u524D\u7F00\u4EE5\u9632\u6B62\u548C\u5176\u4ED6\u56FE\u8868\u540D\u91CD\u590D\u5E76\u4E14\u4FBF\u4E8E\u540E\u671F\u7EDF\u4E00\u7BA1\u7406");
1769
+ const projectName = await textPrompt({
1770
+ message: "\u8BF7\u8F93\u5165\u56FE\u8868\u540D:",
1771
+ placeholder: commandList[0] || "custom_chart",
1772
+ initialValue: commandList[0] || "custom_chart",
1773
+ validate: async (val) => {
1774
+ const validationResult = validateProjectName(val);
1775
+ if (validationResult !== true) {
1776
+ return validationResult;
1777
+ }
1778
+ const state = await checkRepeat(val);
1779
+ if (state) {
1780
+ return "\u5305\u540D\u91CD\u590D";
1781
+ }
1782
+ return void 0;
1783
+ }
1784
+ });
1785
+ let templatePath;
1786
+ let tsTemplatePath = null;
1787
+ try {
1788
+ templatePath = await resolveTemplatePath(templateType);
1789
+ tsTemplatePath = isTs ? await resolveTemplatePath("ts") : null;
1790
+ } catch (err) {
1791
+ exit(err instanceof Error ? err.message : String(err));
1792
+ return;
1793
+ }
1794
+ const createSpinner = spinner2();
1795
+ createSpinner.start("\u521B\u5EFA\u9879\u76EE...");
1796
+ const cwd = process.cwd();
1797
+ const projectPath = ChartModule ? cwd.includes("tailored") ? path6.join(ChartModule.root, "packages", "tailored", projectName) : path6.join(ChartModule.root, "packages", "components", projectName) : path6.join(cwd, projectName);
1798
+ await fs6.ensureDir(projectPath);
1799
+ await fs6.copy(templatePath, projectPath);
1800
+ if (tsTemplatePath) {
1801
+ await fs6.copy(tsTemplatePath, projectPath);
1802
+ }
1803
+ await handleChartTemplate({
1804
+ projectName,
1805
+ projectPath,
1806
+ chartModule: ChartModule,
1807
+ author: await getGitUser(),
1808
+ chartType: validatedChartType,
1809
+ chartId: Date.now(),
1810
+ isTs
1811
+ });
1812
+ createSpinner.succeed("\u9879\u76EE\u521B\u5EFA\u5B8C\u6210.");
1813
+ await wait(0.1);
1814
+ const installSpinner = spinner2();
1815
+ installSpinner.start("\u5B89\u88C5\u4F9D\u8D56...");
1816
+ try {
1817
+ await $3({ cwd: projectPath })`pnpm install`;
1818
+ installSpinner.succeed("\u4F9D\u8D56\u5B89\u88C5\u5B8C\u6210.");
1819
+ } catch (err) {
1820
+ installSpinner.fail("\u4F9D\u8D56\u5B89\u88C5\u5931\u8D25\uFF0C\u8BF7\u624B\u52A8\u8FD0\u884C pnpm install");
1821
+ log.err(String(err));
1822
+ }
1823
+ await wait(0.1);
1824
+ installSpinner.stop();
1825
+ clear();
1826
+ await welcomeCli();
1827
+ log.message(import_picocolors3.default.cyan("\n\u5B8C\u6210. \u73B0\u5728\u53EF\u4EE5\u6267\u884C:\n"));
1828
+ const cdPath = getCdRelativePath(process.cwd(), projectPath);
1829
+ log.success(` cd ${cdPath}`);
1830
+ log.success(` pnpm dev`);
1831
+ log.message("");
1832
+ clearScanCache();
1833
+ outro2(import_picocolors3.default.green(`\u56FE\u8868 "${projectName}" \u521B\u5EFA\u6210\u529F!`));
1834
+ }
1835
+ var import_picocolors3, __filename, __dirname, getTemplatePathCandidates, CHART_TYPES;
1836
+ var init_create = __esm({
1837
+ "src/create/index.ts"() {
1838
+ "use strict";
1839
+ import_picocolors3 = __toESM(require_picocolors(), 1);
1840
+ init_schemas();
1841
+ init_utils();
1842
+ init_chart();
1843
+ __filename = fileURLToPath(import.meta.url);
1844
+ __dirname = path6.dirname(__filename);
1845
+ getTemplatePathCandidates = (templateName, baseDir) => [
1846
+ path6.resolve(baseDir, "../../template", templateName),
1847
+ path6.resolve(baseDir, "../template", templateName),
1848
+ path6.resolve(baseDir, "template", templateName)
1849
+ ];
1850
+ CHART_TYPES = Object.entries(chartTypeLabels).map(([value, label]) => ({
1851
+ value,
1852
+ label,
1853
+ ...value === "other" ? { hint: "\u63A8\u8350" } : {}
1854
+ }));
1855
+ }
1856
+ });
1857
+
1858
+ // src/utils/cli.ts
1859
+ var cli_exports = {};
1860
+ __export(cli_exports, {
1861
+ getCommandArgs: () => getCommandArgs
1862
+ });
1863
+ var getCommandArgs;
1864
+ var init_cli2 = __esm({
1865
+ "src/utils/cli.ts"() {
1866
+ "use strict";
1867
+ getCommandArgs = () => process.argv.slice(3);
1868
+ }
1869
+ });
1870
+
1871
+ // src/dev/index.ts
1872
+ var dev_exports = {};
1873
+ __export(dev_exports, {
1874
+ default: () => dev
1875
+ });
1876
+ import { $ as $4 } from "execa";
1877
+ import fs7 from "fs-extra";
1878
+ import { join } from "node:path";
1879
+ async function dev() {
1880
+ const cwd = process.cwd();
1881
+ const packageJsonPath = join(cwd, "package.json");
1882
+ if (!await fs7.pathExists(packageJsonPath)) {
1883
+ exit("\u672A\u627E\u5230 package.json \u6587\u4EF6\uFF0C\u8BF7\u786E\u4FDD\u5728\u9879\u76EE\u6839\u76EE\u5F55\u6267\u884C\u6B64\u547D\u4EE4");
1884
+ return;
1885
+ }
1886
+ let packageJson;
1887
+ try {
1888
+ packageJson = await fs7.readJson(packageJsonPath);
1889
+ } catch (_error) {
1890
+ exit("package.json \u6587\u4EF6\u683C\u5F0F\u9519\u8BEF\uFF0C\u65E0\u6CD5\u89E3\u6790");
1891
+ return;
1892
+ }
1893
+ if (!packageJson.scripts?.dev) {
1894
+ log.info('\u793A\u4F8B\uFF1A{"scripts": {"dev": "vite"}}');
1895
+ exit("package.json \u4E2D\u672A\u5B9A\u4E49 dev \u811A\u672C\uFF0C\u8BF7\u5148\u6DFB\u52A0 dev \u811A\u672C");
1896
+ return;
1897
+ }
1898
+ log.info(`\u6B63\u5728\u6267\u884C dev \u811A\u672C\uFF1A${packageJson.scripts.dev}`);
1899
+ let interrupted = false;
1900
+ const onSigint = () => {
1901
+ interrupted = true;
1902
+ };
1903
+ process.on("SIGINT", onSigint);
1904
+ try {
1905
+ const pm = await detectPackageManager();
1906
+ await $4({ cwd, stdio: "inherit" })`${pm} run dev`;
1907
+ process.removeListener("SIGINT", onSigint);
1908
+ if (interrupted) {
1909
+ log.info("\u5DF2\u4E2D\u65AD");
1910
+ process.exit(0);
1911
+ }
1912
+ } catch (error) {
1913
+ process.removeListener("SIGINT", onSigint);
1914
+ if (interrupted) {
1915
+ log.info("\u5DF2\u4E2D\u65AD");
1916
+ process.exit(0);
1917
+ }
1918
+ const commandError = error;
1919
+ if (commandError.stderr || commandError.message) {
1920
+ exit(`dev \u811A\u672C\u6267\u884C\u5931\u8D25\uFF1A${commandError.stderr || commandError.message}`);
1921
+ } else {
1922
+ exit(`dev \u811A\u672C\u6267\u884C\u5931\u8D25\uFF0C\u9000\u51FA\u7801\uFF1A${commandError.exitCode}`);
1923
+ }
1924
+ }
1925
+ }
1926
+ var init_dev = __esm({
1927
+ "src/dev/index.ts"() {
1928
+ "use strict";
1929
+ init_utils();
1930
+ }
1931
+ });
1932
+
1933
+ // src/build/index.ts
1934
+ var build_exports = {};
1935
+ __export(build_exports, {
1936
+ buildPathHandler: () => buildPathHandler,
1937
+ default: () => build,
1938
+ versionHandle: () => versionHandle
1939
+ });
1940
+ import path7 from "node:path";
1941
+ import fs8 from "fs-extra";
1942
+ import { to as to3 } from "await-to-js";
1943
+ async function build(commandList = []) {
1944
+ intro2("\u5355\u4E2A\u56FE\u8868\u6253\u5305");
1945
+ const targetArg = commandList[0]?.trim();
1946
+ if (targetArg) {
1947
+ await buildPack(getPath(targetArg));
1948
+ } else {
1949
+ await buildPack(process.cwd());
1950
+ }
1951
+ outro2("\u56FE\u8868\u6253\u5305\u5B8C\u6210");
1952
+ }
1953
+ var versionHandle, buildPathHandler, buildPack;
1954
+ var init_build = __esm({
1955
+ "src/build/index.ts"() {
1956
+ "use strict";
1957
+ init_utils();
1958
+ versionHandle = async (dir) => {
1959
+ const basePath = path7.resolve(dir, "public", "base.json");
1960
+ const packagePath2 = path7.resolve(dir, "package.json");
1961
+ const [baseErr, baseJson] = await to3(fs8.readJson(basePath));
1962
+ if (baseErr || !baseJson) {
1963
+ exit("\u627E\u4E0D\u5230 base.json \u6587\u4EF6\u6216\u5185\u5BB9\u65E0\u6548");
1964
+ }
1965
+ const [pkgErr, pkgJson] = await to3(fs8.readJson(packagePath2));
1966
+ if (pkgErr || !pkgJson) {
1967
+ exit("\u627E\u4E0D\u5230 package.json \u6587\u4EF6\u6216\u5185\u5BB9\u65E0\u6548");
1968
+ }
1969
+ const state = compareVersion(baseJson.version ?? "0.0.0", pkgJson.version ?? "0.0.0");
1970
+ let version2 = baseJson.version ?? "0.0.0";
1971
+ if (state === 1) {
1972
+ pkgJson.version = baseJson.version;
1973
+ await fs8.outputJson(packagePath2, pkgJson, { spaces: 2, EOL: "\n" });
1974
+ } else if (state === -1) {
1975
+ version2 = pkgJson.version;
1976
+ baseJson.version = pkgJson.version;
1977
+ await fs8.outputJson(basePath, baseJson, { spaces: 2, EOL: "\n" });
1978
+ }
1979
+ return { name: baseJson.name, version: version2 };
1980
+ };
1981
+ buildPathHandler = async (dir) => {
1982
+ const result = await runAsyncCmd("pnpm", ["build"], {
1983
+ cwd: dir,
1984
+ stdio: "inherit"
1985
+ });
1986
+ if (!result.success) {
1987
+ exit("pnpm build \u6267\u884C\u5931\u8D25");
1988
+ }
1989
+ };
1990
+ buildPack = async (dir) => {
1991
+ if (!await fs8.pathExists(path7.resolve(dir, "package.json"))) {
1992
+ exit("\u627E\u4E0D\u5230\u76EE\u5F55");
1993
+ }
1994
+ const { name, version: version2 } = await versionHandle(dir);
1995
+ log.info("\u5F00\u59CB\u6267\u884C\u56FE\u8868\u6784\u5EFA...");
1996
+ await buildPathHandler(dir);
1997
+ const packageName = name.split("/").at(-1) ?? name;
1998
+ const packName = `${packageName}_v${version2}`;
1999
+ const targetPath = path7.resolve(dir, packName);
2000
+ const [config2] = await get_cli_config();
2001
+ if (config2.autoRemoveEs) {
2002
+ await fs8.remove(path7.resolve(targetPath, "es"));
2003
+ }
2004
+ await filterFile(targetPath);
2005
+ const packTarPath = `${targetPath}.tar.gz`;
2006
+ await fs8.remove(packTarPath);
2007
+ log.info("\u6B63\u5728\u538B\u7F29 tar \u5305...");
2008
+ const [tarErr] = await to3(buildTarHandler(dir, packName));
2009
+ if (tarErr) {
2010
+ exit(`tar \u6253\u5305\u5931\u8D25: ${tarErr.message}`);
2011
+ }
2012
+ if (config2.autoRemove) {
2013
+ await fs8.remove(targetPath);
2014
+ }
2015
+ log.success(`\u6253\u5305\u5B8C\u6210: ${packTarPath}`);
2016
+ };
2017
+ }
2018
+ });
2019
+
2020
+ // src/config/index.ts
2021
+ var config_exports = {};
2022
+ __export(config_exports, {
2023
+ default: () => config
2024
+ });
2025
+ async function config(_commandList = []) {
2026
+ intro2("CLI \u914D\u7F6E");
2027
+ const [cli_config_info] = await get_cli_config();
2028
+ const getValue = (key, defaultValue) => {
2029
+ return cli_config_info[key] ?? defaultValue;
2030
+ };
2031
+ const s = spinner2();
2032
+ s.start("\u52A0\u8F7D\u914D\u7F6E");
2033
+ const autoRemove = await togglePrompt({
2034
+ message: "\u6253\u5305\u540E\u662F\u5426\u81EA\u52A8\u5220\u9664\u6253\u5305\u76EE\u5F55?",
2035
+ active: "yes",
2036
+ inactive: "no",
2037
+ initialValue: getValue("autoRemove", true)
2038
+ });
2039
+ const autoRemoveEs = await togglePrompt({
2040
+ message: "\u6253\u5305\u540E\u662F\u5426\u79FB\u9664es\u76EE\u5F55?",
2041
+ active: "yes",
2042
+ inactive: "no",
2043
+ initialValue: getValue("autoRemoveEs", true)
2044
+ });
2045
+ s.stop();
2046
+ const saveSpinner = spinner2();
2047
+ saveSpinner.start("\u6B63\u5728\u4FDD\u5B58\u914D\u7F6E...");
2048
+ await set_cli_config({
2049
+ autoRemove,
2050
+ autoRemoveEs
2051
+ });
2052
+ saveSpinner.succeed("\u914D\u7F6E\u4FDD\u5B58\u6210\u529F!");
2053
+ log.step("\u5F53\u524D\u914D\u7F6E:");
2054
+ log.message(` \u81EA\u52A8\u5220\u9664\u6253\u5305\u76EE\u5F55: ${autoRemove ? "\u662F" : "\u5426"}`);
2055
+ log.message(` \u79FB\u9664es\u76EE\u5F55: ${autoRemoveEs ? "\u662F" : "\u5426"}`);
2056
+ outro2("\u914D\u7F6E\u5B8C\u6210!");
2057
+ }
2058
+ var init_config3 = __esm({
2059
+ "src/config/index.ts"() {
2060
+ "use strict";
2061
+ init_utils();
2062
+ }
2063
+ });
2064
+
2065
+ // src/update/index.ts
2066
+ var update_exports = {};
2067
+ __export(update_exports, {
2068
+ default: () => update
2069
+ });
2070
+ import { execa } from "execa";
2071
+ async function update() {
2072
+ intro2("\u66F4\u65B0 CLI");
2073
+ const checkSpinner = spinner2();
2074
+ checkSpinner.start("\u68C0\u67E5\u66F4\u65B0...");
2075
+ const result = await checkUpdate(true);
2076
+ if (result === null) {
2077
+ checkSpinner.fail("\u68C0\u67E5\u66F4\u65B0\u5931\u8D25\uFF0C\u8BF7\u68C0\u67E5\u7F51\u7EDC\u8FDE\u63A5");
2078
+ } else if (!result.hasUpdate) {
2079
+ checkSpinner.succeed(`\u5F53\u524D\u5DF2\u662F\u6700\u65B0\u7248\u672C ${result.currentVersion}`);
2080
+ } else {
2081
+ checkSpinner.stop();
2082
+ log.info(`\u53D1\u73B0\u65B0\u7248\u672C ${result.latestVersion}\uFF0C\u5F53\u524D\u7248\u672C ${result.currentVersion}`);
2083
+ const confirmed = await togglePrompt({
2084
+ message: `\u662F\u5426\u5B89\u88C5 ${result.latestVersion}\uFF1F`,
2085
+ active: "yes",
2086
+ inactive: "no",
2087
+ initialValue: true
2088
+ });
2089
+ if (!confirmed) {
2090
+ log.info("\u5DF2\u8DF3\u8FC7\u66F4\u65B0\uFF0C\u53EF\u7A0D\u540E\u8FD0\u884C 'pvis update' \u518D\u8BD5");
2091
+ outro2("\u5B8C\u6210");
2092
+ return;
2093
+ }
2094
+ const installSpinner = spinner2();
2095
+ installSpinner.start("\u6B63\u5728\u5B89\u88C5\u66F4\u65B0...");
2096
+ const pm = await detectPackageManager();
2097
+ try {
2098
+ await execa(pm, ["install", "-g", "pangu-vis-cli@latest"]);
2099
+ installSpinner.succeed("\u66F4\u65B0\u6210\u529F\uFF01");
2100
+ } catch (_error) {
2101
+ installSpinner.fail("\u81EA\u52A8\u66F4\u65B0\u5931\u8D25");
2102
+ log.warn(`\u8BF7\u624B\u52A8\u6267\u884C: ${pm} install -g pangu-vis-cli@latest`);
2103
+ }
2104
+ }
2105
+ outro2("\u5B8C\u6210");
2106
+ }
2107
+ var init_update = __esm({
2108
+ "src/update/index.ts"() {
2109
+ "use strict";
2110
+ init_utils();
2111
+ }
2112
+ });
2113
+
2114
+ // src/index.ts
2115
+ import { readFileSync } from "node:fs";
2116
+ import { program } from "commander";
2117
+
2118
+ // src/commands/definitions.ts
2119
+ init_utils();
2120
+ var commandDefinitions = [
2121
+ {
2122
+ name: "create",
2123
+ alias: "c",
2124
+ description: "\u521B\u5EFA\u56FE\u8868\u5305",
2125
+ action: async () => {
2126
+ const { default: createCommand } = await Promise.resolve().then(() => (init_create(), create_exports));
2127
+ const { getCommandArgs: getCommandArgs2 } = await Promise.resolve().then(() => (init_cli2(), cli_exports));
2128
+ await createCommand(getCommandArgs2());
2129
+ }
2130
+ },
2131
+ {
2132
+ name: "dev",
2133
+ alias: "d",
2134
+ description: "\u542F\u52A8\u5F00\u53D1\u670D\u52A1\u5668",
2135
+ action: async () => {
2136
+ const { default: devCommand } = await Promise.resolve().then(() => (init_dev(), dev_exports));
2137
+ await devCommand();
2138
+ }
2139
+ },
2140
+ {
2141
+ name: "build",
2142
+ alias: "b",
2143
+ description: "\u5355\u4E2A\u56FE\u8868\u6253\u5305",
2144
+ action: async () => {
2145
+ const { default: buildCommand } = await Promise.resolve().then(() => (init_build(), build_exports));
2146
+ const { getCommandArgs: getCommandArgs2 } = await Promise.resolve().then(() => (init_cli2(), cli_exports));
2147
+ await buildCommand(getCommandArgs2());
2148
+ }
2149
+ },
2150
+ {
2151
+ name: "config",
2152
+ alias: "set",
2153
+ description: "CLI\u914D\u7F6E",
2154
+ action: async () => {
2155
+ const { default: configCommand } = await Promise.resolve().then(() => (init_config3(), config_exports));
2156
+ const { getCommandArgs: getCommandArgs2 } = await Promise.resolve().then(() => (init_cli2(), cli_exports));
2157
+ await configCommand(getCommandArgs2());
2158
+ }
2159
+ },
2160
+ {
2161
+ name: "update",
2162
+ alias: "up",
2163
+ description: "\u66F4\u65B0CLI",
2164
+ skipUpdateCheck: true,
2165
+ action: async () => {
2166
+ const { default: updateCommand } = await Promise.resolve().then(() => (init_update(), update_exports));
2167
+ await updateCommand();
2168
+ }
2169
+ }
2170
+ ];
2171
+ function registerCommands(program2, checkUpdateFn) {
2172
+ for (const cmdDef of commandDefinitions) {
2173
+ const cmd = program2.command(cmdDef.name);
2174
+ if (cmdDef.alias) {
2175
+ cmd.alias(cmdDef.alias);
2176
+ }
2177
+ cmd.description(cmdDef.description);
2178
+ if (cmdDef.options) {
2179
+ for (const opt of cmdDef.options) {
2180
+ if (opt.description) {
2181
+ cmd.option(opt.flags, opt.description);
2182
+ } else {
2183
+ cmd.option(opt.flags);
2184
+ }
2185
+ }
2186
+ }
2187
+ cmd.action(async () => {
2188
+ if (!cmdDef.skipUpdateCheck) {
2189
+ await checkUpdateFn();
2190
+ }
2191
+ await cmdDef.action();
2192
+ });
2193
+ }
2194
+ program2.command("*").description("command not found").action(() => {
2195
+ log.err("command not found");
2196
+ });
2197
+ }
2198
+
2199
+ // src/index.ts
2200
+ init_utils();
2201
+ var { version } = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf-8"));
2202
+ async function checkAndNotifyUpdate() {
2203
+ try {
2204
+ const result = await checkUpdate(false);
2205
+ if (result?.hasUpdate) {
2206
+ log.warn(`\u53D1\u73B0\u65B0\u7248\u672C ${result.latestVersion}\uFF0C\u8FD0\u884C 'pvis update' \u66F4\u65B0`);
2207
+ }
2208
+ } catch {
2209
+ }
2210
+ }
2211
+ registerCommands(program, checkAndNotifyUpdate);
2212
+ if (process.argv[2] === "-v") {
2213
+ console.log(version);
2214
+ process.exit(0);
2215
+ }
2216
+ program.version(version).parse(process.argv);
2217
+ process.on("uncaughtException", (err) => {
2218
+ log.err(`\u9519\u8BEF\uFF1A${err?.message || "\u5F02\u5E38\u9519\u8BEF\uFF01"}`);
2219
+ exit();
2220
+ });