@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,222 @@
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 __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
+ return new (P || (P = Promise))(function (resolve, reject) {
38
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
42
+ });
43
+ };
44
+ Object.defineProperty(exports, "__esModule", { value: true });
45
+ const assert_1 = require("assert");
46
+ const child_process_1 = require("child_process");
47
+ const fs = __importStar(require("fs"));
48
+ const os = __importStar(require("os"));
49
+ const path = __importStar(require("path"));
50
+ const util_1 = require("util");
51
+ const commander_1 = require("commander");
52
+ const main_1 = require("../../main");
53
+ const test = require("node:test");
54
+ const exec = (0, util_1.promisify)(child_process_1.execFile);
55
+ const packageRoot = path.resolve(__dirname, "../../..");
56
+ const binary = path.join(packageRoot, "bin/redminitool.js");
57
+ const business = ["config", "list", "status", "history", "upload", "preview", "submit", "edit"];
58
+ test("CLI 入口:顶层与分组帮助、JSON 参数错误和离线 dry-run", (t) => __awaiter(void 0, void 0, void 0, function* () {
59
+ const home = fs.mkdtempSync(path.join(os.tmpdir(), "minitool-cli-entry-"));
60
+ t.after(() => require("fs").rmSync(home, { recursive: true, force: true }));
61
+ const run = (args) => __awaiter(void 0, void 0, void 0, function* () {
62
+ try {
63
+ return Object.assign(Object.assign({}, (yield exec(process.execPath, [binary, ...args], {
64
+ env: Object.assign(Object.assign({}, process.env), { CI: "1", REDMINITOOL_HOME: home, REDMINITOOL_ENV: "prod" }),
65
+ timeout: 15000,
66
+ }))), { code: 0 });
67
+ }
68
+ catch (error) {
69
+ return error;
70
+ }
71
+ });
72
+ const help = yield run(["--help"]);
73
+ assert_1.strict.equal(help.code, 0);
74
+ for (const name of ["login", "whoami", "logout", "dev", ...business]) {
75
+ assert_1.strict.ok(new RegExp(`\\n ${name}\\s`).test(help.stdout), name);
76
+ assert_1.strict.equal((yield run([name, "--help"])).code, 0);
77
+ }
78
+ for (const name of business) {
79
+ const direct = yield run([name, "--help"]);
80
+ const grouped = yield run(["minitool", name, "--help"]);
81
+ assert_1.strict.equal(grouped.code, 0);
82
+ assert_1.strict.equal(direct.stdout.replace(`redminitool ${name}`, `redminitool minitool ${name}`), grouped.stdout);
83
+ }
84
+ for (const args of [
85
+ ["--json", "--wrong"],
86
+ ["--json", "lst"],
87
+ ["list", "--wrong", "--json"],
88
+ ["minitool", "list", "--page-num", "--json"],
89
+ ["--json", "minitool", "unknown"],
90
+ ["whoami", "--env", "invalid", "--json"],
91
+ ]) {
92
+ const result = yield run(args);
93
+ assert_1.strict.equal(result.code, 1);
94
+ assert_1.strict.equal(result.stderr, "");
95
+ assert_1.strict.equal(JSON.parse(result.stdout).ok, false);
96
+ }
97
+ const file = path.join(home, "edit.json");
98
+ fs.writeFileSync(file, JSON.stringify({ appId: "id", appName: "工具", slogan: "简介", iconFileId: "icon" }));
99
+ for (const args of [
100
+ ["--json", "edit"],
101
+ ["minitool", "--json", "edit"],
102
+ ["minitool", "edit", "--json"],
103
+ ]) {
104
+ const result = yield run([...args, "--source", "assigned", "--file", file, "--dry-run"]);
105
+ assert_1.strict.equal(result.code, 0);
106
+ assert_1.strict.equal(result.stderr, "");
107
+ assert_1.strict.equal(JSON.parse(result.stdout).data.dryRun, true);
108
+ }
109
+ for (const args of [["login", "--cancel"], ["logout"]]) {
110
+ assert_1.strict.equal(JSON.parse((yield run([...args, "--json"])).stdout).ok, true);
111
+ }
112
+ }));
113
+ test("命令解析 → DI Core → 本地 HTTP 平台:登录、8 个业务服务、确认与退出", (t) => __awaiter(void 0, void 0, void 0, function* () {
114
+ const { createSession } = require(path.resolve(packageRoot, "../minitool-core/playground/server.cjs"));
115
+ const session = yield createSession();
116
+ t.after(() => session.close());
117
+ const services = Object.assign(Object.assign({}, session.core), { auth: session.auth, credentialStorage: session.credentials, environment: "beta" });
118
+ let authPrompt;
119
+ const outputs = [];
120
+ function run(args) {
121
+ return __awaiter(this, void 0, void 0, function* () {
122
+ const root = new commander_1.Command().option("--json").option("--env <environment>").exitOverride();
123
+ yield (0, main_1.registerCommands)(services, root);
124
+ const previousOutput = process.stdout.write;
125
+ const previousError = process.stderr.write;
126
+ const previousExit = process.exitCode;
127
+ let stdout = "";
128
+ process.stdout.write = ((chunk) => {
129
+ stdout += String(chunk);
130
+ return true;
131
+ });
132
+ process.stderr.write = ((chunk) => {
133
+ const line = String(chunk);
134
+ if (line.startsWith("AUTH_PROMPT:")) {
135
+ authPrompt = JSON.parse(line.slice("AUTH_PROMPT:".length));
136
+ assert_1.strict.ok(fs.existsSync(authPrompt.qrCodePath));
137
+ session.demo.approve();
138
+ }
139
+ else
140
+ assert_1.strict.fail(`出现非预期 stderr: ${line}`);
141
+ return true;
142
+ });
143
+ process.exitCode = 0;
144
+ try {
145
+ yield root.parseAsync(args.includes("--json") ? args : ["--json", ...args], { from: "user" });
146
+ const result = JSON.parse(stdout);
147
+ assert_1.strict.equal(process.exitCode, result.ok ? 0 : 1);
148
+ outputs.push(stdout);
149
+ return result;
150
+ }
151
+ finally {
152
+ process.stdout.write = previousOutput;
153
+ process.stderr.write = previousError;
154
+ process.exitCode = previousExit;
155
+ }
156
+ });
157
+ }
158
+ const success = (args) => __awaiter(void 0, void 0, void 0, function* () {
159
+ const result = yield run(args);
160
+ assert_1.strict.equal(result.ok, true, JSON.stringify(result));
161
+ return result.data;
162
+ });
163
+ assert_1.strict.equal((yield success(["login"])).authenticated, true);
164
+ assert_1.strict.equal(fs.existsSync(authPrompt.qrCodePath), false);
165
+ const credential = session.credentials.get();
166
+ assert_1.strict.equal((yield success(["whoami"])).creatorId, "demo-creator");
167
+ assert_1.strict.equal((yield success(["auth", "status"])).status, "authenticated");
168
+ const source = ["--source", "demo-source"];
169
+ for (const name of ["config", "list", "status", "history"]) {
170
+ const args = [
171
+ ...source,
172
+ ...(["status", "history"].includes(name) ? ["--app-id", "demo-focus"] : []),
173
+ ];
174
+ assert_1.strict.deepEqual(yield success([name, ...args]), yield success(["minitool", "--json", name, ...args]));
175
+ }
176
+ assert_1.strict.equal((yield success(["list", ...source, "--page-num", "2", "--page-size", "1"])).pageNum, 2);
177
+ const upload = ["upload", "--file", session.fixtures.get("sample.zip").filePath, "--type", "pkg"];
178
+ const before = session.demo.traces.length;
179
+ assert_1.strict.equal((yield success([...upload, "--dry-run"])).dryRun, true);
180
+ assert_1.strict.equal((yield run(upload)).ok, false);
181
+ assert_1.strict.equal(session.demo.traces.length, before);
182
+ const pkg = yield success([...upload, "--yes"]);
183
+ const image = yield success([
184
+ "minitool",
185
+ "upload",
186
+ "--file",
187
+ session.fixtures.get("icon.png").filePath,
188
+ "--type",
189
+ "image",
190
+ "--yes",
191
+ ]);
192
+ const file = path.join(session.directory, "payload.json");
193
+ fs.writeFileSync(file, JSON.stringify({ pkgFileId: pkg.fileId, md5: pkg.md5, appName: "命令测试", version: "1.0.0" }));
194
+ const qr = path.join(session.directory, "preview.png");
195
+ assert_1.strict.equal((yield success(["preview", ...source, "--file", file, "--yes", "--qr-out", qr])).qrCodePath, qr);
196
+ assert_1.strict.ok(fs.statSync(qr).size > 0);
197
+ fs.writeFileSync(file, JSON.stringify({
198
+ appName: "命令测试",
199
+ slogan: "简介",
200
+ iconFileId: image.fileId,
201
+ coverFileId: image.fileId,
202
+ pkgFileId: pkg.fileId,
203
+ md5: pkg.md5,
204
+ version: "1.0.0",
205
+ categories: ["tools"],
206
+ }));
207
+ const app = yield success(["submit", ...source, "--file", file, "--yes"]);
208
+ fs.writeFileSync(file, JSON.stringify({
209
+ appId: app.appId,
210
+ appName: "修改后名称",
211
+ slogan: "修改后简介",
212
+ iconFileId: image.fileId,
213
+ }));
214
+ yield success(["edit", ...source, "--file", file, "--yes"]);
215
+ assert_1.strict.equal((yield success(["status", ...source, "--app-id", app.appId])).appName, "修改后名称");
216
+ assert_1.strict.equal((yield success(["history", ...source, "--app-id", app.appId])).versions.length, 1);
217
+ assert_1.strict.equal((yield success(["logout"])).loggedOut, true);
218
+ assert_1.strict.equal((yield run(["list", ...source])).ok, false);
219
+ assert_1.strict.equal(session.credentials.get(), null);
220
+ assert_1.strict.equal(outputs.join("").includes(credential.accessToken), false);
221
+ assert_1.strict.equal(outputs.join("").includes(credential.refreshToken), false);
222
+ }));
@@ -0,0 +1,119 @@
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 __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
+ return new (P || (P = Promise))(function (resolve, reject) {
38
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
42
+ });
43
+ };
44
+ Object.defineProperty(exports, "__esModule", { value: true });
45
+ const assert_1 = require("assert");
46
+ const fs = __importStar(require("fs"));
47
+ const os = __importStar(require("os"));
48
+ const path = __importStar(require("path"));
49
+ const edit_1 = require("./edit");
50
+ const submit_1 = require("./submit");
51
+ const test = require("node:test");
52
+ test("离线 dry-run 校验真实字段,非法输入不调用远端服务", () => __awaiter(void 0, void 0, void 0, function* () {
53
+ const home = fs.mkdtempSync(path.join(os.tmpdir(), "minitool-cli-command-"));
54
+ const file = path.join(home, "submit.json");
55
+ let calls = 0;
56
+ const services = {
57
+ miniTools: {
58
+ submitReview(input) {
59
+ return __awaiter(this, void 0, void 0, function* () {
60
+ var _a;
61
+ calls++;
62
+ return { appId: (_a = input.appId) !== null && _a !== void 0 ? _a : "created" };
63
+ });
64
+ },
65
+ edit() {
66
+ return __awaiter(this, void 0, void 0, function* () {
67
+ calls++;
68
+ return { appId: "id" };
69
+ });
70
+ },
71
+ },
72
+ };
73
+ const context = (options) => ({
74
+ services,
75
+ params: [],
76
+ options: Object.assign({ json: true, source: "assigned", file }, options),
77
+ });
78
+ const input = {
79
+ appName: "测试",
80
+ slogan: "简介",
81
+ iconFileId: "icon",
82
+ coverFileId: "cover",
83
+ pkgFileId: "pkg",
84
+ md5: "a".repeat(32),
85
+ version: "1.0.0",
86
+ categories: ["tools"],
87
+ };
88
+ try {
89
+ fs.writeFileSync(file, JSON.stringify(input));
90
+ const command = new submit_1.MiniToolSubmitCommand(services);
91
+ const result = yield command.execute(context({ dryRun: true }));
92
+ assert_1.strict.equal("dryRun" in result && result.dryRun, true);
93
+ assert_1.strict.equal(calls, 0);
94
+ assert_1.strict.deepEqual(yield command.execute(context({ yes: true })), { appId: "created" });
95
+ assert_1.strict.equal(calls, 1);
96
+ fs.writeFileSync(file, JSON.stringify({ appId: "id", slogan: "只改简介" }));
97
+ const edit = new edit_1.MiniToolEditCommand(services);
98
+ yield assert_1.strict.rejects(edit.execute(context({ dryRun: true })), { code: "INVALID_ARGS" });
99
+ fs.writeFileSync(file, JSON.stringify({
100
+ appId: "id",
101
+ appName: "现有名称",
102
+ slogan: "新简介",
103
+ iconFileId: "existing-icon",
104
+ }));
105
+ const editPlan = yield edit.execute(context({ dryRun: true }));
106
+ assert_1.strict.equal("dryRun" in editPlan && editPlan.dryRun, true);
107
+ assert_1.strict.equal(calls, 1);
108
+ fs.writeFileSync(file, JSON.stringify(Object.assign(Object.assign({}, input), { userId: "spoof" })));
109
+ yield assert_1.strict.rejects(command.execute(context({ yes: true })), { code: "INVALID_ARGS" });
110
+ fs.writeFileSync(file, JSON.stringify({ appId: "id" }));
111
+ yield assert_1.strict.rejects(new edit_1.MiniToolEditCommand(services).execute(context({ dryRun: true })), {
112
+ code: "INVALID_ARGS",
113
+ });
114
+ assert_1.strict.equal(calls, 1);
115
+ }
116
+ finally {
117
+ require("fs").rmSync(home, { recursive: true, force: true });
118
+ }
119
+ }));
@@ -0,0 +1,103 @@
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 __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
+ return new (P || (P = Promise))(function (resolve, reject) {
38
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
42
+ });
43
+ };
44
+ Object.defineProperty(exports, "__esModule", { value: true });
45
+ exports.writeOptions = exports.sourceOption = void 0;
46
+ exports.source = source;
47
+ exports.payloadFile = payloadFile;
48
+ exports.confirmWrite = confirmWrite;
49
+ const fs = __importStar(require("fs"));
50
+ const ui_1 = require("../../ui");
51
+ exports.sourceOption = {
52
+ flags: "--source <source>",
53
+ desc: "平台分配的来源;也可设置 REDMINITOOL_SOURCE",
54
+ };
55
+ exports.writeOptions = [
56
+ { flags: "--file <path>", desc: "本地 JSON 参数文件" },
57
+ { flags: "--dry-run", desc: "仅校验并展示参数,不请求服务端" },
58
+ { flags: "--yes", desc: "确认执行;非交互环境必填" },
59
+ ];
60
+ function source(ctx) {
61
+ var _a;
62
+ const value = (_a = ctx.options.source) !== null && _a !== void 0 ? _a : process.env.REDMINITOOL_SOURCE;
63
+ if (typeof value !== "string" || !value.trim())
64
+ throw new Error("请提供 --source 或设置 REDMINITOOL_SOURCE,值须为平台分配的来源");
65
+ return value.trim();
66
+ }
67
+ function payloadFile(ctx) {
68
+ if (typeof ctx.options.file !== "string" || !ctx.options.file)
69
+ throw new Error("请提供 --file <JSON 路径>");
70
+ const file = ctx.options.file;
71
+ const stat = fs.statSync(file);
72
+ if (!stat.isFile() || stat.size > 1024 * 1024)
73
+ throw new Error("JSON 参数文件须为不超过 1 MiB 的普通文件");
74
+ let value;
75
+ try {
76
+ value = JSON.parse(fs.readFileSync(file, "utf8").replace(/^\uFEFF/, ""));
77
+ }
78
+ catch (_a) {
79
+ throw new Error("参数文件不是有效 JSON");
80
+ }
81
+ if (!value || typeof value !== "object" || Array.isArray(value))
82
+ throw new Error("参数文件须包含 JSON 对象");
83
+ if ("source" in value)
84
+ throw new Error("source 请通过 --source 或 REDMINITOOL_SOURCE 指定");
85
+ return Object.assign(Object.assign({}, value), { source: source(ctx) });
86
+ }
87
+ function confirmWrite(ctx, message) {
88
+ return __awaiter(this, void 0, void 0, function* () {
89
+ if (ctx.options.yes === true)
90
+ return true;
91
+ if (!process.stdin.isTTY)
92
+ throw new Error("非交互执行需要显式添加 --yes;可先使用 --dry-run 校验参数");
93
+ const { confirmed } = yield require("inquirer").prompt({
94
+ type: "confirm",
95
+ name: "confirmed",
96
+ message,
97
+ default: false,
98
+ });
99
+ if (!confirmed && !ctx.options.json)
100
+ (0, ui_1.printHint)("已取消");
101
+ return confirmed;
102
+ });
103
+ }
@@ -0,0 +1,51 @@
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.MiniToolConfigCommand = void 0;
19
+ const base_1 = require("../../core/base");
20
+ const ui_1 = require("../../ui");
21
+ const common_1 = require("./common");
22
+ let MiniToolConfigCommand = class MiniToolConfigCommand extends base_1.Command {
23
+ execute(ctx) {
24
+ return __awaiter(this, void 0, void 0, function* () {
25
+ const result = yield this.services.miniTools.getConfig({ source: (0, common_1.source)(ctx) });
26
+ if (!this.isJson(ctx)) {
27
+ for (const [label, values] of [
28
+ ["类目", result.categories],
29
+ ["权限", result.authorizations],
30
+ ]) {
31
+ (0, ui_1.printHeading)(label);
32
+ (0, ui_1.printTable)(["编码", "名称"], values.map((item) => { var _a; return [item.code, (_a = item.name) !== null && _a !== void 0 ? _a : "—"]; }));
33
+ }
34
+ }
35
+ return result;
36
+ });
37
+ }
38
+ get options() {
39
+ return {
40
+ cmd: "minitool",
41
+ rootAlias: true,
42
+ childCmd: { cmd: "config", desc: "查询平台类目与权限配置" },
43
+ desc: "查询配置",
44
+ options: [common_1.sourceOption],
45
+ };
46
+ }
47
+ };
48
+ exports.MiniToolConfigCommand = MiniToolConfigCommand;
49
+ exports.MiniToolConfigCommand = MiniToolConfigCommand = __decorate([
50
+ (0, base_1.ICommand)()
51
+ ], MiniToolConfigCommand);
@@ -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.MiniToolEditCommand = 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 MiniToolEditCommand = class MiniToolEditCommand 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.miniToolEditSchema, (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.appId} 的基础信息?`)))
33
+ return { cancelled: true };
34
+ const result = yield this.services.miniTools.edit(input);
35
+ if (!this.isJson(ctx)) {
36
+ (0, ui_1.printHeading)("基础信息已更新");
37
+ (0, ui_1.printDetails)([["小工具 ID", result.appId]]);
38
+ }
39
+ return result;
40
+ });
41
+ }
42
+ get options() {
43
+ return {
44
+ cmd: "minitool",
45
+ rootAlias: true,
46
+ childCmd: { cmd: "edit", desc: "更新完整基础资料,封面可选" },
47
+ desc: "修改基础信息",
48
+ options: [common_1.sourceOption, ...common_1.writeOptions],
49
+ };
50
+ }
51
+ };
52
+ exports.MiniToolEditCommand = MiniToolEditCommand;
53
+ exports.MiniToolEditCommand = MiniToolEditCommand = __decorate([
54
+ (0, base_1.ICommand)()
55
+ ], MiniToolEditCommand);
@@ -0,0 +1,56 @@
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.MiniToolHistoryCommand = void 0;
19
+ const base_1 = require("../../core/base");
20
+ const ui_1 = require("../../ui");
21
+ const common_1 = require("./common");
22
+ let MiniToolHistoryCommand = class MiniToolHistoryCommand extends base_1.Command {
23
+ execute(ctx) {
24
+ return __awaiter(this, void 0, void 0, function* () {
25
+ const result = yield this.services.miniTools.getHistory({
26
+ source: (0, common_1.source)(ctx),
27
+ appId: ctx.options.appId,
28
+ });
29
+ if (!this.isJson(ctx)) {
30
+ (0, ui_1.printHeading)("历史版本");
31
+ (0, ui_1.printTable)(["版本", "审核状态", "驳回原因"], result.versions.map((item) => {
32
+ var _a, _b, _c;
33
+ return [
34
+ String((_a = item.version) !== null && _a !== void 0 ? _a : "—"),
35
+ String((_b = item.auditStatusText) !== null && _b !== void 0 ? _b : "—"),
36
+ String((_c = item.rejectReason) !== null && _c !== void 0 ? _c : "—"),
37
+ ];
38
+ }));
39
+ }
40
+ return result;
41
+ });
42
+ }
43
+ get options() {
44
+ return {
45
+ cmd: "minitool",
46
+ rootAlias: true,
47
+ childCmd: { cmd: "history", desc: "查询小工具历史版本" },
48
+ desc: "查询历史版本",
49
+ options: [common_1.sourceOption, { flags: "--app-id <id>", desc: "目标小工具 ID" }],
50
+ };
51
+ }
52
+ };
53
+ exports.MiniToolHistoryCommand = MiniToolHistoryCommand;
54
+ exports.MiniToolHistoryCommand = MiniToolHistoryCommand = __decorate([
55
+ (0, base_1.ICommand)()
56
+ ], MiniToolHistoryCommand);
@@ -0,0 +1,24 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./list"), exports);
18
+ __exportStar(require("./preview"), exports);
19
+ __exportStar(require("./status"), exports);
20
+ __exportStar(require("./submit"), exports);
21
+ __exportStar(require("./upload"), exports);
22
+ __exportStar(require("./config"), exports);
23
+ __exportStar(require("./history"), exports);
24
+ __exportStar(require("./edit"), exports);