@skillbuilder/minitool-cli 0.0.0-beta-20261027053041051

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 (79) hide show
  1. package/README.md +185 -0
  2. package/bin/redminitool.js +176 -0
  3. package/lib/bootstrap.js +69 -0
  4. package/lib/commands/auth/identity.js +98 -0
  5. package/lib/commands/auth/index.js +20 -0
  6. package/lib/commands/auth/login.js +148 -0
  7. package/lib/commands/auth/logout.js +52 -0
  8. package/lib/commands/auth/storage.js +105 -0
  9. package/lib/commands/dev/dev.test.js +108 -0
  10. package/lib/commands/dev.js +119 -0
  11. package/lib/commands/index.js +19 -0
  12. package/lib/commands/minitool/cli.test.js +222 -0
  13. package/lib/commands/minitool/commands.test.js +119 -0
  14. package/lib/commands/minitool/common.js +103 -0
  15. package/lib/commands/minitool/config.js +51 -0
  16. package/lib/commands/minitool/edit.js +55 -0
  17. package/lib/commands/minitool/history.js +56 -0
  18. package/lib/commands/minitool/index.js +24 -0
  19. package/lib/commands/minitool/list.js +65 -0
  20. package/lib/commands/minitool/preview.js +115 -0
  21. package/lib/commands/minitool/status.js +55 -0
  22. package/lib/commands/minitool/submit.js +58 -0
  23. package/lib/commands/minitool/upload.js +80 -0
  24. package/lib/core/base.js +133 -0
  25. package/lib/decorators/auth.js +26 -0
  26. package/lib/decorators/captureError.js +32 -0
  27. package/lib/decorators/constants.js +11 -0
  28. package/lib/decorators/decorators.test.js +94 -0
  29. package/lib/decorators/index.js +21 -0
  30. package/lib/decorators/injectParams.js +30 -0
  31. package/lib/decorators/json-output.js +18 -0
  32. package/lib/decorators/params/common.js +21 -0
  33. package/lib/decorators/params/index.js +24 -0
  34. package/lib/index.js +18 -0
  35. package/lib/main.js +26 -0
  36. package/lib/mcp.js +197 -0
  37. package/lib/output.js +7 -0
  38. package/lib/ui.js +39 -0
  39. package/lib/utils/agent-check.js +157 -0
  40. package/lib/utils/templates.js +75 -0
  41. package/package.json +48 -0
  42. package/types/bootstrap.d.ts +14 -0
  43. package/types/commands/auth/identity.d.ts +9 -0
  44. package/types/commands/auth/index.d.ts +4 -0
  45. package/types/commands/auth/login.d.ts +13 -0
  46. package/types/commands/auth/logout.d.ts +7 -0
  47. package/types/commands/auth/storage.d.ts +14 -0
  48. package/types/commands/dev/dev.test.d.ts +1 -0
  49. package/types/commands/dev.d.ts +8 -0
  50. package/types/commands/index.d.ts +3 -0
  51. package/types/commands/minitool/cli.test.d.ts +1 -0
  52. package/types/commands/minitool/commands.test.d.ts +1 -0
  53. package/types/commands/minitool/common.d.ts +12 -0
  54. package/types/commands/minitool/config.d.ts +5 -0
  55. package/types/commands/minitool/edit.d.ts +20 -0
  56. package/types/commands/minitool/history.d.ts +5 -0
  57. package/types/commands/minitool/index.d.ts +8 -0
  58. package/types/commands/minitool/list.d.ts +5 -0
  59. package/types/commands/minitool/preview.d.ts +23 -0
  60. package/types/commands/minitool/status.d.ts +5 -0
  61. package/types/commands/minitool/submit.d.ts +25 -0
  62. package/types/commands/minitool/upload.d.ts +20 -0
  63. package/types/core/base.d.ts +37 -0
  64. package/types/decorators/auth.d.ts +1 -0
  65. package/types/decorators/captureError.d.ts +1 -0
  66. package/types/decorators/constants.d.ts +7 -0
  67. package/types/decorators/decorators.test.d.ts +1 -0
  68. package/types/decorators/index.d.ts +5 -0
  69. package/types/decorators/injectParams.d.ts +1 -0
  70. package/types/decorators/json-output.d.ts +2 -0
  71. package/types/decorators/params/common.d.ts +10 -0
  72. package/types/decorators/params/index.d.ts +5 -0
  73. package/types/index.d.ts +2 -0
  74. package/types/main.d.ts +5 -0
  75. package/types/mcp.d.ts +9 -0
  76. package/types/output.d.ts +4 -0
  77. package/types/ui.d.ts +4 -0
  78. package/types/utils/agent-check.d.ts +16 -0
  79. package/types/utils/templates.d.ts +17 -0
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
9
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
10
+ return new (P || (P = Promise))(function (resolve, reject) {
11
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
12
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
13
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
14
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
15
+ });
16
+ };
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.MiniToolListCommand = void 0;
19
+ const base_1 = require("../../core/base");
20
+ const ui_1 = require("../../ui");
21
+ const common_1 = require("./common");
22
+ let MiniToolListCommand = class MiniToolListCommand extends base_1.Command {
23
+ execute(ctx) {
24
+ return __awaiter(this, void 0, void 0, function* () {
25
+ var _a, _b, _c;
26
+ const result = yield this.services.miniTools.list({
27
+ source: (0, common_1.source)(ctx),
28
+ pageNum: Number((_b = (_a = ctx.options.pageNum) !== null && _a !== void 0 ? _a : ctx.options.page) !== null && _b !== void 0 ? _b : 1),
29
+ pageSize: Number((_c = ctx.options.pageSize) !== null && _c !== void 0 ? _c : 20),
30
+ });
31
+ if (!this.isJson(ctx)) {
32
+ (0, ui_1.printHeading)("我的小工具", "当前创作者账号");
33
+ (0, ui_1.printTable)(["名称", "小工具 ID", "状态", "版本"], result.apps.map((item) => {
34
+ var _a, _b, _c;
35
+ return [
36
+ (_a = item.appName) !== null && _a !== void 0 ? _a : "—",
37
+ item.appId,
38
+ (_b = item.statusText) !== null && _b !== void 0 ? _b : "—",
39
+ (_c = item.version) !== null && _c !== void 0 ? _c : "—",
40
+ ];
41
+ }));
42
+ (0, ui_1.printHint)(`第 ${result.pageNum} 页 · 共 ${result.total} 个 · 每页 ${result.pageSize} 个`);
43
+ }
44
+ return result;
45
+ });
46
+ }
47
+ get options() {
48
+ return {
49
+ cmd: "minitool",
50
+ rootAlias: true,
51
+ childCmd: { cmd: "list", desc: "查看当前创作者的小工具" },
52
+ desc: "查看小工具",
53
+ options: [
54
+ common_1.sourceOption,
55
+ { flags: "--page-num <number>", desc: "页码,默认 1" },
56
+ { flags: "--page <number>", desc: "页码(兼容旧参数)", hideHelp: true },
57
+ { flags: "--page-size <number>", desc: "每页条数,默认 20,最多 100" },
58
+ ],
59
+ };
60
+ }
61
+ };
62
+ exports.MiniToolListCommand = MiniToolListCommand;
63
+ exports.MiniToolListCommand = MiniToolListCommand = __decorate([
64
+ (0, base_1.ICommand)()
65
+ ], MiniToolListCommand);
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
19
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
22
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
23
+ };
24
+ var __importStar = (this && this.__importStar) || (function () {
25
+ var ownKeys = function(o) {
26
+ ownKeys = Object.getOwnPropertyNames || function (o) {
27
+ var ar = [];
28
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
29
+ return ar;
30
+ };
31
+ return ownKeys(o);
32
+ };
33
+ return function (mod) {
34
+ if (mod && mod.__esModule) return mod;
35
+ var result = {};
36
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
37
+ __setModuleDefault(result, mod);
38
+ return result;
39
+ };
40
+ })();
41
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
42
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
43
+ return new (P || (P = Promise))(function (resolve, reject) {
44
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
45
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
46
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
47
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
48
+ });
49
+ };
50
+ Object.defineProperty(exports, "__esModule", { value: true });
51
+ exports.MiniToolPreviewCommand = void 0;
52
+ const fs = __importStar(require("fs"));
53
+ const path = __importStar(require("path"));
54
+ const minitool_core_1 = require("@skillbuilder/minitool-core");
55
+ const base_1 = require("../../core/base");
56
+ const ui_1 = require("../../ui");
57
+ const common_1 = require("./common");
58
+ let MiniToolPreviewCommand = class MiniToolPreviewCommand extends base_1.Command {
59
+ execute(ctx) {
60
+ return __awaiter(this, void 0, void 0, function* () {
61
+ const input = (0, minitool_core_1.parseMiniToolInput)(minitool_core_1.miniToolPreviewSchema, (0, common_1.payloadFile)(ctx));
62
+ if (ctx.options.dryRun) {
63
+ if (!this.isJson(ctx))
64
+ (0, ui_1.printDetails)([["预览参数", JSON.stringify(input, null, 2)]]);
65
+ return { dryRun: true, input };
66
+ }
67
+ const qrOut = ctx.options.qrOut;
68
+ if (qrOut && typeof qrOut !== "string")
69
+ throw new Error("--qr-out 必须是文件路径");
70
+ if (qrOut && fs.existsSync(qrOut))
71
+ throw new Error("二维码目标文件已存在,请选择新路径");
72
+ if (!(yield (0, common_1.confirmWrite)(ctx, "确认使用此代码包创建手机预览?")))
73
+ return { cancelled: true };
74
+ const result = yield this.services.miniTools.createPreview(input);
75
+ const output = Object.assign({}, result);
76
+ if (qrOut) {
77
+ try {
78
+ fs.writeFileSync(qrOut, yield require("qrcode").toBuffer(result.previewUrl), {
79
+ flag: "wx",
80
+ });
81
+ output.qrCodePath = path.resolve(qrOut);
82
+ }
83
+ catch (_a) {
84
+ output.qrError = "预览已创建,但本地二维码写入失败;请使用 previewUrl,无需重复创建预览";
85
+ }
86
+ }
87
+ if (!this.isJson(ctx)) {
88
+ (0, ui_1.printHeading)("手机预览已生成", "请使用小红书客户端扫码预览");
89
+ process.stdout.write(yield require("qrcode").toString(result.previewUrl, { type: "terminal", small: true }));
90
+ (0, ui_1.printDetails)([
91
+ ["预览链接", result.previewUrl],
92
+ ["二维码文件", output.qrCodePath],
93
+ ]);
94
+ }
95
+ return output;
96
+ });
97
+ }
98
+ get options() {
99
+ return {
100
+ cmd: "minitool",
101
+ rootAlias: true,
102
+ childCmd: { cmd: "preview", desc: "为已上传代码包创建手机预览" },
103
+ desc: "手机预览",
104
+ options: [
105
+ common_1.sourceOption,
106
+ ...common_1.writeOptions,
107
+ { flags: "--qr-out <path>", desc: "另存 PNG 二维码,不覆盖已有文件" },
108
+ ],
109
+ };
110
+ }
111
+ };
112
+ exports.MiniToolPreviewCommand = MiniToolPreviewCommand;
113
+ exports.MiniToolPreviewCommand = MiniToolPreviewCommand = __decorate([
114
+ (0, base_1.ICommand)()
115
+ ], MiniToolPreviewCommand);
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
9
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
10
+ return new (P || (P = Promise))(function (resolve, reject) {
11
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
12
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
13
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
14
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
15
+ });
16
+ };
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.MiniToolStatusCommand = void 0;
19
+ const base_1 = require("../../core/base");
20
+ const ui_1 = require("../../ui");
21
+ const common_1 = require("./common");
22
+ let MiniToolStatusCommand = class MiniToolStatusCommand extends base_1.Command {
23
+ execute(ctx) {
24
+ return __awaiter(this, void 0, void 0, function* () {
25
+ const result = yield this.services.miniTools.getStatus({
26
+ source: (0, common_1.source)(ctx),
27
+ appId: ctx.options.appId,
28
+ });
29
+ if (!this.isJson(ctx)) {
30
+ (0, ui_1.printHeading)("小工具状态", result.appName);
31
+ (0, ui_1.printDetails)([
32
+ ["小工具 ID", result.appId],
33
+ ["名称", result.appName],
34
+ ["版本", result.version],
35
+ ["状态", result.statusText],
36
+ ["驳回原因", typeof result.rejectReason === "string" ? result.rejectReason : undefined],
37
+ ]);
38
+ }
39
+ return result;
40
+ });
41
+ }
42
+ get options() {
43
+ return {
44
+ cmd: "minitool",
45
+ rootAlias: true,
46
+ childCmd: { cmd: "status", desc: "查看小工具当前版本与审核状态" },
47
+ desc: "查看状态",
48
+ options: [common_1.sourceOption, { flags: "--app-id <id>", desc: "目标小工具 ID" }],
49
+ };
50
+ }
51
+ };
52
+ exports.MiniToolStatusCommand = MiniToolStatusCommand;
53
+ exports.MiniToolStatusCommand = MiniToolStatusCommand = __decorate([
54
+ (0, base_1.ICommand)()
55
+ ], MiniToolStatusCommand);
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
9
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
10
+ return new (P || (P = Promise))(function (resolve, reject) {
11
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
12
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
13
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
14
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
15
+ });
16
+ };
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.MiniToolSubmitCommand = void 0;
19
+ const minitool_core_1 = require("@skillbuilder/minitool-core");
20
+ const base_1 = require("../../core/base");
21
+ const ui_1 = require("../../ui");
22
+ const common_1 = require("./common");
23
+ let MiniToolSubmitCommand = class MiniToolSubmitCommand extends base_1.Command {
24
+ execute(ctx) {
25
+ return __awaiter(this, void 0, void 0, function* () {
26
+ const input = (0, minitool_core_1.parseMiniToolInput)(minitool_core_1.miniToolReviewSchema, (0, common_1.payloadFile)(ctx));
27
+ if (ctx.options.dryRun) {
28
+ if (!this.isJson(ctx))
29
+ (0, ui_1.printDetails)([["提审参数", JSON.stringify(input, null, 2)]]);
30
+ return { dryRun: true, input };
31
+ }
32
+ if (!(yield (0, common_1.confirmWrite)(ctx, `确认提交 ${input.appName} 的 ${input.version} 版本审核?`)))
33
+ return { cancelled: true };
34
+ const result = yield this.services.miniTools.submitReview(input);
35
+ if (!this.isJson(ctx)) {
36
+ (0, ui_1.printHeading)("已提交审核", "审核结果以平台为准");
37
+ (0, ui_1.printDetails)([
38
+ ["小工具 ID", result.appId],
39
+ ["响应", JSON.stringify(result)],
40
+ ]);
41
+ }
42
+ return result;
43
+ });
44
+ }
45
+ get options() {
46
+ return {
47
+ cmd: "minitool",
48
+ rootAlias: true,
49
+ childCmd: { cmd: "submit", desc: "提交新小工具或新版本审核" },
50
+ desc: "提交审核",
51
+ options: [common_1.sourceOption, ...common_1.writeOptions],
52
+ };
53
+ }
54
+ };
55
+ exports.MiniToolSubmitCommand = MiniToolSubmitCommand;
56
+ exports.MiniToolSubmitCommand = MiniToolSubmitCommand = __decorate([
57
+ (0, base_1.ICommand)()
58
+ ], MiniToolSubmitCommand);
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
9
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
10
+ return new (P || (P = Promise))(function (resolve, reject) {
11
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
12
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
13
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
14
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
15
+ });
16
+ };
17
+ var __rest = (this && this.__rest) || function (s, e) {
18
+ var t = {};
19
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
20
+ t[p] = s[p];
21
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
22
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
23
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
24
+ t[p[i]] = s[p[i]];
25
+ }
26
+ return t;
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.MiniToolUploadCommand = void 0;
30
+ const minitool_core_1 = require("@skillbuilder/minitool-core");
31
+ const base_1 = require("../../core/base");
32
+ const ui_1 = require("../../ui");
33
+ const common_1 = require("./common");
34
+ let MiniToolUploadCommand = class MiniToolUploadCommand extends base_1.Command {
35
+ execute(ctx) {
36
+ return __awaiter(this, void 0, void 0, function* () {
37
+ var _a;
38
+ const input = (0, minitool_core_1.parseMiniToolInput)(minitool_core_1.miniToolUploadSchema, {
39
+ filePath: ctx.options.file,
40
+ type: (_a = ctx.options.type) !== null && _a !== void 0 ? _a : "pkg",
41
+ });
42
+ const _b = yield (0, minitool_core_1.inspectMiniToolFile)(input.filePath, input.type), { bytes: _bytes } = _b, file = __rest(_b, ["bytes"]);
43
+ if (ctx.options.dryRun) {
44
+ if (!this.isJson(ctx))
45
+ (0, ui_1.printDetails)([["上传参数", JSON.stringify(file, null, 2)]]);
46
+ return { dryRun: true, file };
47
+ }
48
+ if (!(yield (0, common_1.confirmWrite)(ctx, `确认上传 ${file.filePath}?`)))
49
+ return { cancelled: true };
50
+ const result = yield this.services.miniTools.upload(Object.assign(Object.assign({}, input), { expectedSha256: file.sha256 }));
51
+ if (!this.isJson(ctx)) {
52
+ (0, ui_1.printHeading)("上传完成");
53
+ (0, ui_1.printDetails)([
54
+ ["fileId", result.fileId],
55
+ ["md5", result.md5],
56
+ ["类型", result.type],
57
+ ]);
58
+ }
59
+ return result;
60
+ });
61
+ }
62
+ get options() {
63
+ return {
64
+ cmd: "minitool",
65
+ rootAlias: true,
66
+ childCmd: { cmd: "upload", desc: "上传 ZIP 代码包或图片并返回 fileId" },
67
+ desc: "上传文件",
68
+ options: [
69
+ { flags: "--file <path>", desc: "本地 ZIP 或图片路径" },
70
+ { flags: "--type <type>", desc: "pkg(默认)或 image" },
71
+ { flags: "--dry-run", desc: "仅校验文件,不上传" },
72
+ { flags: "--yes", desc: "确认上传;非交互环境必填" },
73
+ ],
74
+ };
75
+ }
76
+ };
77
+ exports.MiniToolUploadCommand = MiniToolUploadCommand;
78
+ exports.MiniToolUploadCommand = MiniToolUploadCommand = __decorate([
79
+ (0, base_1.ICommand)()
80
+ ], MiniToolUploadCommand);
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
12
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
13
+ return new (P || (P = Promise))(function (resolve, reject) {
14
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
15
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
16
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
17
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
18
+ });
19
+ };
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.Command = exports.registrableCommands = void 0;
22
+ exports.ICommand = ICommand;
23
+ const minitool_core_1 = require("@skillbuilder/minitool-core");
24
+ const commander_1 = require("commander");
25
+ const json_output_1 = require("../decorators/json-output");
26
+ exports.registrableCommands = [];
27
+ function ICommand() {
28
+ return (target) => {
29
+ exports.registrableCommands.push({ Command: target });
30
+ };
31
+ }
32
+ function writeJson(value) {
33
+ process.stdout.write(`${JSON.stringify(value, null, 2)}\n`);
34
+ }
35
+ function jsonError(error) {
36
+ if (!(error instanceof Error))
37
+ return { code: "COMMAND_FAILED", message: "命令执行失败" };
38
+ const code = error.code;
39
+ return {
40
+ code: typeof code === "string" && code ? code : "COMMAND_FAILED",
41
+ message: error.message || "命令执行失败",
42
+ };
43
+ }
44
+ let Command = class Command {
45
+ constructor(services) {
46
+ this.services = services;
47
+ }
48
+ init(root = commander_1.program) {
49
+ const { cmd, childCmd, desc, options, rootAlias } = this.options;
50
+ const supportsJson = (0, json_output_1.isJsonOutputEnabled)(this);
51
+ let command;
52
+ if (childCmd) {
53
+ let group = root.commands.find((entry) => entry.name() === cmd);
54
+ if (!group) {
55
+ group = root.command(cmd);
56
+ group.addOption(new commander_1.Option("--env <environment>", "服务环境:prod(默认)或 beta"));
57
+ group.addOption(new commander_1.Option("--json", "以稳定 JSON 协议输出"));
58
+ group.description(cmd === "auth" ? "查看小红书小工具认证状态" : "管理当前创作者的小工具");
59
+ }
60
+ command = group.command(childCmd.cmd);
61
+ command.description(childCmd.desc);
62
+ }
63
+ else {
64
+ command = root.command(cmd);
65
+ command.description(desc);
66
+ }
67
+ const entries = [{ command, path: childCmd ? `${cmd} ${childCmd.cmd}` : cmd }];
68
+ if (childCmd && rootAlias) {
69
+ entries.push({
70
+ command: root.command(childCmd.cmd).description(childCmd.desc),
71
+ path: childCmd.cmd,
72
+ });
73
+ }
74
+ for (const entry of entries) {
75
+ this.configure(entry.command, entry.path, options, supportsJson);
76
+ }
77
+ }
78
+ configure(command, commandPath, options, supportsJson) {
79
+ command.storeOptionsAsProperties(false);
80
+ command.addOption(new commander_1.Option("--env <environment>", "服务环境:prod(默认)或 beta"));
81
+ for (const option of options) {
82
+ const entry = new commander_1.Option(option.flags, option.desc);
83
+ command.addOption(option.hideHelp ? entry.hideHelp() : entry);
84
+ }
85
+ if (supportsJson && !options.some((option) => option.flags.includes("--json"))) {
86
+ command.addOption(new commander_1.Option("--json", "以稳定 JSON 协议输出,供 AI 与自动化调用"));
87
+ }
88
+ command.action((...args) => __awaiter(this, void 0, void 0, function* () {
89
+ const invoked = args[args.length - 1];
90
+ const commandOptions = Object.assign({}, invoked.opts());
91
+ for (let current = invoked; current; current = current.parent) {
92
+ if (current.opts().json === true)
93
+ commandOptions.json = true;
94
+ }
95
+ const params = args.slice(0, -1);
96
+ const tracker = (0, minitool_core_1.createCliCommandTracker)({
97
+ cmd_path: commandPath,
98
+ cmd_root: commandPath.split(" ")[0],
99
+ params_count: params.length,
100
+ options_keys: Object.keys(commandOptions).filter((key) => commandOptions[key] !== undefined),
101
+ });
102
+ const startedAt = Date.now();
103
+ try {
104
+ const result = yield this.execute({
105
+ options: commandOptions,
106
+ params,
107
+ services: this.services,
108
+ });
109
+ tracker.reportSuccess(Date.now() - startedAt);
110
+ if (supportsJson && commandOptions.json === true) {
111
+ writeJson({ ok: true, data: result !== null && result !== void 0 ? result : null });
112
+ }
113
+ }
114
+ catch (error) {
115
+ tracker.reportFail(Date.now() - startedAt, error);
116
+ if (supportsJson && commandOptions.json === true) {
117
+ writeJson({ ok: false, error: jsonError(error) });
118
+ process.exitCode = 1;
119
+ return;
120
+ }
121
+ throw error;
122
+ }
123
+ }));
124
+ }
125
+ isJson(ctx) {
126
+ return ctx.options.json === true;
127
+ }
128
+ };
129
+ exports.Command = Command;
130
+ exports.Command = Command = __decorate([
131
+ (0, json_output_1.JsonOutput)(),
132
+ __metadata("design:paramtypes", [Object])
133
+ ], Command);
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.AuthGuard = AuthGuard;
13
+ const minitool_cli_auth_1 = require("@skillbuilder/minitool-cli-auth");
14
+ function AuthGuard() {
15
+ return (target) => {
16
+ const prototype = target.prototype;
17
+ const original = prototype.execute;
18
+ prototype.execute = function (context) {
19
+ return __awaiter(this, void 0, void 0, function* () {
20
+ const state = yield context.services.auth.getAuthState();
21
+ (0, minitool_cli_auth_1.requireAuthenticatedAuthState)(state);
22
+ return original.call(this, context);
23
+ });
24
+ };
25
+ };
26
+ }
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.CaptureError = CaptureError;
13
+ function CaptureError() {
14
+ return (_target, _key, descriptor) => {
15
+ const original = descriptor.value;
16
+ if (typeof original !== "function")
17
+ return descriptor;
18
+ descriptor.value = function (...args) {
19
+ return __awaiter(this, void 0, void 0, function* () {
20
+ try {
21
+ return yield original.apply(this, args);
22
+ }
23
+ catch (error) {
24
+ if (error instanceof Error)
25
+ throw error;
26
+ throw new Error("命令执行失败");
27
+ }
28
+ });
29
+ };
30
+ return descriptor;
31
+ };
32
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ParamTypes = void 0;
4
+ var ParamTypes;
5
+ (function (ParamTypes) {
6
+ ParamTypes["Credential"] = "Credential";
7
+ ParamTypes["Log"] = "Log";
8
+ ParamTypes["CmdContext"] = "CmdContext";
9
+ ParamTypes["ArgsOptions"] = "ArgsOptions";
10
+ ParamTypes["ArgsParams"] = "ArgsParams";
11
+ })(ParamTypes || (exports.ParamTypes = ParamTypes = {}));