@hangox/mg-cli 1.1.6 → 1.3.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.
- package/dist/cli.js +138 -40
- package/dist/cli.js.map +1 -1
- package/dist/daemon-runner.js.map +1 -1
- package/dist/{index-DorC5U6y.d.ts → index-AVsoGQ0e.d.ts} +105 -1
- package/dist/index.d.ts +16 -3
- package/dist/index.js +10 -1
- package/dist/index.js.map +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// src/cli/index.ts
|
|
4
|
-
import { Command as
|
|
4
|
+
import { Command as Command14 } from "commander";
|
|
5
5
|
|
|
6
6
|
// src/cli/version-check.ts
|
|
7
7
|
import { existsSync as existsSync2, mkdirSync, readFileSync as readFileSync2, writeFileSync } from "fs";
|
|
@@ -221,6 +221,21 @@ function killProcess(pid) {
|
|
|
221
221
|
return false;
|
|
222
222
|
}
|
|
223
223
|
}
|
|
224
|
+
function normalizePageUrl(url) {
|
|
225
|
+
try {
|
|
226
|
+
if (!url.includes("://") && !url.startsWith("//")) {
|
|
227
|
+
return url.split("?")[0].split("#")[0];
|
|
228
|
+
}
|
|
229
|
+
const urlObj = new URL(url);
|
|
230
|
+
return urlObj.host + urlObj.pathname;
|
|
231
|
+
} catch {
|
|
232
|
+
return url;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
function buildPageUrl(domain, fileId, pageType = "file") {
|
|
236
|
+
const normalizedDomain = domain.replace(/\/$/, "");
|
|
237
|
+
return `${normalizedDomain}/${pageType}/${fileId}`;
|
|
238
|
+
}
|
|
224
239
|
function parseMgpLink(link) {
|
|
225
240
|
if (!link.startsWith("mgp://")) {
|
|
226
241
|
return null;
|
|
@@ -1117,7 +1132,7 @@ var MGServer = class {
|
|
|
1117
1132
|
throw new MGError("E016" /* SERVER_ALREADY_RUNNING */, "Server \u5DF2\u5728\u8FD0\u884C\u4E2D");
|
|
1118
1133
|
}
|
|
1119
1134
|
const port = await this.findAvailablePort();
|
|
1120
|
-
return new Promise((
|
|
1135
|
+
return new Promise((resolve10, reject) => {
|
|
1121
1136
|
this.wss = new WebSocketServer({ port });
|
|
1122
1137
|
this.wss.on("listening", () => {
|
|
1123
1138
|
this.port = port;
|
|
@@ -1126,7 +1141,7 @@ var MGServer = class {
|
|
|
1126
1141
|
this.logger.info(`Server \u542F\u52A8\u6210\u529F\uFF0C\u76D1\u542C\u7AEF\u53E3: ${port}`);
|
|
1127
1142
|
this.connectionManager.startHeartbeatCheck(HEARTBEAT_INTERVAL);
|
|
1128
1143
|
initServerAnalytics(this.logger);
|
|
1129
|
-
|
|
1144
|
+
resolve10(port);
|
|
1130
1145
|
});
|
|
1131
1146
|
this.wss.on("error", (error) => {
|
|
1132
1147
|
this.logger.error("Server \u9519\u8BEF:", error);
|
|
@@ -1157,14 +1172,14 @@ var MGServer = class {
|
|
|
1157
1172
|
* 检查端口是否可用
|
|
1158
1173
|
*/
|
|
1159
1174
|
isPortAvailable(port) {
|
|
1160
|
-
return new Promise((
|
|
1175
|
+
return new Promise((resolve10) => {
|
|
1161
1176
|
const testServer = new WebSocketServer({ port });
|
|
1162
1177
|
testServer.on("listening", () => {
|
|
1163
1178
|
testServer.close();
|
|
1164
|
-
|
|
1179
|
+
resolve10(true);
|
|
1165
1180
|
});
|
|
1166
1181
|
testServer.on("error", () => {
|
|
1167
|
-
|
|
1182
|
+
resolve10(false);
|
|
1168
1183
|
});
|
|
1169
1184
|
});
|
|
1170
1185
|
}
|
|
@@ -1499,12 +1514,12 @@ var MGServer = class {
|
|
|
1499
1514
|
await shutdownServerAnalytics();
|
|
1500
1515
|
this.requestHandler.cleanupAll();
|
|
1501
1516
|
this.connectionManager.closeAll();
|
|
1502
|
-
return new Promise((
|
|
1517
|
+
return new Promise((resolve10) => {
|
|
1503
1518
|
this.wss.close(() => {
|
|
1504
1519
|
this.isRunning = false;
|
|
1505
1520
|
this.wss = null;
|
|
1506
1521
|
this.logger.info("Server \u5DF2\u505C\u6B62");
|
|
1507
|
-
|
|
1522
|
+
resolve10();
|
|
1508
1523
|
});
|
|
1509
1524
|
});
|
|
1510
1525
|
}
|
|
@@ -1621,7 +1636,7 @@ async function startServerDaemon(port) {
|
|
|
1621
1636
|
child.unref();
|
|
1622
1637
|
const startTime = Date.now();
|
|
1623
1638
|
while (Date.now() - startTime < SERVER_START_TIMEOUT) {
|
|
1624
|
-
await new Promise((
|
|
1639
|
+
await new Promise((resolve10) => setTimeout(resolve10, 200));
|
|
1625
1640
|
const { running: running2, info: info2 } = isServerRunning();
|
|
1626
1641
|
if (running2 && info2) {
|
|
1627
1642
|
return info2;
|
|
@@ -1642,7 +1657,7 @@ function stopServer() {
|
|
|
1642
1657
|
}
|
|
1643
1658
|
async function restartServer(port) {
|
|
1644
1659
|
const { info: oldInfo } = stopServer();
|
|
1645
|
-
await new Promise((
|
|
1660
|
+
await new Promise((resolve10) => setTimeout(resolve10, 500));
|
|
1646
1661
|
return startServerDaemon(port || oldInfo?.port);
|
|
1647
1662
|
}
|
|
1648
1663
|
function getServerStatus() {
|
|
@@ -1715,7 +1730,7 @@ var MGClient = class {
|
|
|
1715
1730
|
* 尝试连接指定端口
|
|
1716
1731
|
*/
|
|
1717
1732
|
tryConnect(port) {
|
|
1718
|
-
return new Promise((
|
|
1733
|
+
return new Promise((resolve10, reject) => {
|
|
1719
1734
|
const ws = new WebSocket2(`ws://localhost:${port}`);
|
|
1720
1735
|
const timer = setTimeout(() => {
|
|
1721
1736
|
ws.close();
|
|
@@ -1725,7 +1740,7 @@ var MGClient = class {
|
|
|
1725
1740
|
clearTimeout(timer);
|
|
1726
1741
|
this.ws = ws;
|
|
1727
1742
|
this.register();
|
|
1728
|
-
|
|
1743
|
+
resolve10();
|
|
1729
1744
|
});
|
|
1730
1745
|
ws.on("error", (error) => {
|
|
1731
1746
|
clearTimeout(timer);
|
|
@@ -1778,7 +1793,7 @@ var MGClient = class {
|
|
|
1778
1793
|
pageUrl,
|
|
1779
1794
|
timestamp: Date.now()
|
|
1780
1795
|
};
|
|
1781
|
-
return new Promise((
|
|
1796
|
+
return new Promise((resolve10, reject) => {
|
|
1782
1797
|
const timer = setTimeout(() => {
|
|
1783
1798
|
reject(new MGError("E012" /* REQUEST_TIMEOUT */, ErrorMessages["E012" /* REQUEST_TIMEOUT */]));
|
|
1784
1799
|
}, REQUEST_TIMEOUT);
|
|
@@ -1789,7 +1804,7 @@ var MGClient = class {
|
|
|
1789
1804
|
clearTimeout(timer);
|
|
1790
1805
|
this.ws?.off("message", messageHandler);
|
|
1791
1806
|
if (response.success) {
|
|
1792
|
-
|
|
1807
|
+
resolve10(response.data);
|
|
1793
1808
|
} else {
|
|
1794
1809
|
const error = response.error;
|
|
1795
1810
|
reject(
|
|
@@ -2084,7 +2099,7 @@ import { writeFileSync as writeFileSync3 } from "fs";
|
|
|
2084
2099
|
import { resolve as resolve2, dirname as dirname5 } from "path";
|
|
2085
2100
|
import { mkdirSync as mkdirSync4 } from "fs";
|
|
2086
2101
|
function createGetNodeByIdCommand() {
|
|
2087
|
-
return new Command2("get_node_by_id").description("\u6839\u636E\u8282\u70B9 ID \u83B7\u53D6\u8282\u70B9\u8BE6\u7EC6\u4FE1\u606F\u3002\u6570\u636E\u4FDD\u5B58\u5230\u6307\u5B9A JSON \u6587\u4EF6\uFF0C\u8FD4\u56DE\u6587\u4EF6\u8DEF\u5F84\u548C\u5927\u5C0F\u4FE1\u606F\u3002\u5982\u9700\u901A\u8FC7\u94FE\u63A5\u83B7\u53D6\uFF0C\u8BF7\u4F7F\u7528 get_node_by_link \u547D\u4EE4").requiredOption("--nodeId <id>", "\u8282\u70B9 ID\uFF0C\u683C\u5F0F\u5982 123:456\u3002\u53EF\u4ECE MasterGo \u6D6E\u7A97\u94FE\u63A5\u4E2D\u83B7\u53D6").requiredOption("--output <path>", "\u8F93\u51FA JSON \u6587\u4EF6\u8DEF\u5F84\u3002\u652F\u6301\u7EDD\u5BF9\u8DEF\u5F84\u6216\u76F8\u5BF9\u8DEF\u5F84").option("--domain <domain>", "MasterGo \u57DF\u540D\uFF0C\u9ED8\u8BA4 mastergo.netease.com\u3002\u4E0E --fileId \u914D\u5408\u4F7F\u7528", "mastergo.netease.com").option("--fileId <id>", "\u6587\u4EF6 ID\uFF08\u7EAF\u6570\u5B57\uFF09\uFF0C\u4E0E --domain \u914D\u5408\u6307\u5B9A\u76EE\u6807\u9875\u9762").option("--maxDepth <number>", "\u904D\u5386\u6DF1\u5EA6\uFF0C\u9ED8\u8BA4 1\u3002\u589E\u52A0\u6DF1\u5EA6\u4F1A\u663E\u8457\u589E\u52A0\u6570\u636E\u91CF", "1").option("--includeInvisible", "\u5305\u542B\u4E0D\u53EF\u89C1\u8282\u70B9\uFF08visible: false\uFF09\uFF0C\u9ED8\u8BA4\u4E0D\u5305\u542B", false).option("--raw", "\u4FDD\u7559\u539F\u59CB\u6570\u636E\uFF0C\u4E0D\u7CBE\u7B80\u9ED8\u8BA4\u503C\u5B57\u6BB5", false).option("--pretty", "\u683C\u5F0F\u5316\u8F93\u51FA JSON\uFF08\u9ED8\u8BA4\u538B\u7F29\uFF09", false).option("--no-auto-start", "\u7981\u7528\u81EA\u52A8\u542F\u52A8 Server").option("--no-retry", "\u7981\u7528\u81EA\u52A8\u91CD\u8BD5").action(async (options) => {
|
|
2102
|
+
return new Command2("get_node_by_id").description("\u6839\u636E\u8282\u70B9 ID \u83B7\u53D6\u8282\u70B9\u8BE6\u7EC6\u4FE1\u606F\u3002\u6570\u636E\u4FDD\u5B58\u5230\u6307\u5B9A JSON \u6587\u4EF6\uFF0C\u8FD4\u56DE\u6587\u4EF6\u8DEF\u5F84\u548C\u5927\u5C0F\u4FE1\u606F\u3002\u5982\u9700\u901A\u8FC7\u94FE\u63A5\u83B7\u53D6\uFF0C\u8BF7\u4F7F\u7528 get_node_by_link \u547D\u4EE4").requiredOption("--nodeId <id>", "\u8282\u70B9 ID\uFF0C\u683C\u5F0F\u5982 123:456\u3002\u53EF\u4ECE MasterGo \u6D6E\u7A97\u94FE\u63A5\u4E2D\u83B7\u53D6").requiredOption("--output <path>", "\u8F93\u51FA JSON \u6587\u4EF6\u8DEF\u5F84\u3002\u652F\u6301\u7EDD\u5BF9\u8DEF\u5F84\u6216\u76F8\u5BF9\u8DEF\u5F84").option("--domain <domain>", "MasterGo \u57DF\u540D\uFF0C\u9ED8\u8BA4 mastergo.netease.com\u3002\u4E0E --fileId \u914D\u5408\u4F7F\u7528", "mastergo.netease.com").option("--fileId <id>", "\u6587\u4EF6 ID\uFF08\u7EAF\u6570\u5B57\uFF09\uFF0C\u4E0E --domain \u914D\u5408\u6307\u5B9A\u76EE\u6807\u9875\u9762").option("--pageType <type>", "\u9875\u9762\u7C7B\u578B: file(\u9ED8\u8BA4) \u6216 prototyping", "file").option("--maxDepth <number>", "\u904D\u5386\u6DF1\u5EA6\uFF0C\u9ED8\u8BA4 1\u3002\u589E\u52A0\u6DF1\u5EA6\u4F1A\u663E\u8457\u589E\u52A0\u6570\u636E\u91CF", "1").option("--includeInvisible", "\u5305\u542B\u4E0D\u53EF\u89C1\u8282\u70B9\uFF08visible: false\uFF09\uFF0C\u9ED8\u8BA4\u4E0D\u5305\u542B", false).option("--raw", "\u4FDD\u7559\u539F\u59CB\u6570\u636E\uFF0C\u4E0D\u7CBE\u7B80\u9ED8\u8BA4\u503C\u5B57\u6BB5", false).option("--pretty", "\u683C\u5F0F\u5316\u8F93\u51FA JSON\uFF08\u9ED8\u8BA4\u538B\u7F29\uFF09", false).option("--no-auto-start", "\u7981\u7528\u81EA\u52A8\u542F\u52A8 Server").option("--no-retry", "\u7981\u7528\u81EA\u52A8\u91CD\u8BD5").action(async (options) => {
|
|
2088
2103
|
await handleGetNodeById(options);
|
|
2089
2104
|
});
|
|
2090
2105
|
}
|
|
@@ -2099,7 +2114,7 @@ async function handleGetNodeById(options) {
|
|
|
2099
2114
|
let pageUrl;
|
|
2100
2115
|
if (options.fileId) {
|
|
2101
2116
|
const domain = options.domain || "mastergo.netease.com";
|
|
2102
|
-
pageUrl =
|
|
2117
|
+
pageUrl = buildPageUrl(domain, options.fileId, options.pageType);
|
|
2103
2118
|
}
|
|
2104
2119
|
const params = {
|
|
2105
2120
|
nodeId: options.nodeId,
|
|
@@ -2289,7 +2304,7 @@ import { mkdirSync as mkdirSync7 } from "fs";
|
|
|
2289
2304
|
import { tmpdir } from "os";
|
|
2290
2305
|
import { vdConvert } from "vd-tool";
|
|
2291
2306
|
function createExportImageCommand() {
|
|
2292
|
-
return new Command5("export_image").description("\u5BFC\u51FA MasterGo \u8282\u70B9\u4E3A\u56FE\u7247\u6587\u4EF6\u3002\u5F3A\u70C8\u5EFA\u8BAE\u6307\u5B9A --output\uFF0C\u5426\u5219\u4FDD\u5B58\u5230\u4E34\u65F6\u76EE\u5F55\u53EF\u80FD\u88AB\u7CFB\u7EDF\u6E05\u7406").option("--output <path>", "\u8F93\u51FA\u6587\u4EF6\u8DEF\u5F84\u3002\u5F3A\u70C8\u5EFA\u8BAE\u6307\u5B9A\uFF0C\u5426\u5219\u4FDD\u5B58\u5230\u7CFB\u7EDF\u4E34\u65F6\u76EE\u5F55\u53EF\u80FD\u88AB\u6E05\u7406").option("--link <mgp-link>", "mgp:// \u534F\u8BAE\u94FE\u63A5\u3002\u4E0E --nodeId/--domain/--fileId \u4E8C\u9009\u4E00").option("--nodeId <id>", "\u8282\u70B9 ID\uFF0C\u683C\u5F0F\u5982 123:456\u3002\u4E0E --domain/--fileId \u914D\u5408\u4F7F\u7528").option("--domain <domain>", "MasterGo \u57DF\u540D\uFF0C\u9ED8\u8BA4 mastergo.netease.com", "mastergo.netease.com").option("--fileId <id>", "\u6587\u4EF6 ID\uFF08\u7EAF\u6570\u5B57\uFF09\uFF0C\u4E0E --domain \u914D\u5408\u6307\u5B9A\u76EE\u6807\u9875\u9762").option("--format <type>", "\u5BFC\u51FA\u683C\u5F0F\uFF1APNG\uFF08\u65E0\u635F\u900F\u660E\uFF09\u3001JPG\uFF08\u6709\u635F\uFF09\u3001SVG\uFF08\u77E2\u91CF\uFF09\u3001PDF\u3001WEBP\u3001VECTOR\uFF08Android VectorDrawable\uFF09", "PNG").option("--scale <number>", "\u7F29\u653E\u500D\u7387\uFF08\u5982 1\u30012\u30013\uFF09\u3002\u4E0E width/height \u4E92\u65A5").option("--width <number>", "\u56FA\u5B9A\u5BBD\u5EA6\uFF08\u50CF\u7D20\uFF09\u3002\u4E0E scale/height \u4E92\u65A5").option("--height <number>", "\u56FA\u5B9A\u9AD8\u5EA6\uFF08\u50CF\u7D20\uFF09\u3002\u4E0E scale/width \u4E92\u65A5").option("--useAbsoluteBounds", "\u4F7F\u7528\u5B8C\u6574\u5C3A\u5BF8\u3002true: \u5305\u542B\u88AB\u88C1\u526A\u90E8\u5206\uFF0Cfalse: \u53EA\u5BFC\u51FA\u53EF\u89C1\u533A\u57DF", false).option("--no-use-render-bounds", "\u4E0D\u5305\u542B\u7279\u6548\u548C\u5916\u63CF\u8FB9\u3002\u9ED8\u8BA4\u5305\u542B\u9634\u5F71\u3001\u5916\u63CF\u8FB9\u7B49").option("--no-auto-start", "\u7981\u7528\u81EA\u52A8\u542F\u52A8 Server").option("--no-retry", "\u7981\u7528\u81EA\u52A8\u91CD\u8BD5").action(async (options) => {
|
|
2307
|
+
return new Command5("export_image").description("\u5BFC\u51FA MasterGo \u8282\u70B9\u4E3A\u56FE\u7247\u6587\u4EF6\u3002\u5F3A\u70C8\u5EFA\u8BAE\u6307\u5B9A --output\uFF0C\u5426\u5219\u4FDD\u5B58\u5230\u4E34\u65F6\u76EE\u5F55\u53EF\u80FD\u88AB\u7CFB\u7EDF\u6E05\u7406").option("--output <path>", "\u8F93\u51FA\u6587\u4EF6\u8DEF\u5F84\u3002\u5F3A\u70C8\u5EFA\u8BAE\u6307\u5B9A\uFF0C\u5426\u5219\u4FDD\u5B58\u5230\u7CFB\u7EDF\u4E34\u65F6\u76EE\u5F55\u53EF\u80FD\u88AB\u6E05\u7406").option("--link <mgp-link>", "mgp:// \u534F\u8BAE\u94FE\u63A5\u3002\u4E0E --nodeId/--domain/--fileId \u4E8C\u9009\u4E00").option("--nodeId <id>", "\u8282\u70B9 ID\uFF0C\u683C\u5F0F\u5982 123:456\u3002\u4E0E --domain/--fileId \u914D\u5408\u4F7F\u7528").option("--domain <domain>", "MasterGo \u57DF\u540D\uFF0C\u9ED8\u8BA4 mastergo.netease.com", "mastergo.netease.com").option("--fileId <id>", "\u6587\u4EF6 ID\uFF08\u7EAF\u6570\u5B57\uFF09\uFF0C\u4E0E --domain \u914D\u5408\u6307\u5B9A\u76EE\u6807\u9875\u9762").option("--pageType <type>", "\u9875\u9762\u7C7B\u578B: file(\u9ED8\u8BA4) \u6216 prototyping", "file").option("--format <type>", "\u5BFC\u51FA\u683C\u5F0F\uFF1APNG\uFF08\u65E0\u635F\u900F\u660E\uFF09\u3001JPG\uFF08\u6709\u635F\uFF09\u3001SVG\uFF08\u77E2\u91CF\uFF09\u3001PDF\u3001WEBP\u3001VECTOR\uFF08Android VectorDrawable\uFF09", "PNG").option("--scale <number>", "\u7F29\u653E\u500D\u7387\uFF08\u5982 1\u30012\u30013\uFF09\u3002\u4E0E width/height \u4E92\u65A5").option("--width <number>", "\u56FA\u5B9A\u5BBD\u5EA6\uFF08\u50CF\u7D20\uFF09\u3002\u4E0E scale/height \u4E92\u65A5").option("--height <number>", "\u56FA\u5B9A\u9AD8\u5EA6\uFF08\u50CF\u7D20\uFF09\u3002\u4E0E scale/width \u4E92\u65A5").option("--useAbsoluteBounds", "\u4F7F\u7528\u5B8C\u6574\u5C3A\u5BF8\u3002true: \u5305\u542B\u88AB\u88C1\u526A\u90E8\u5206\uFF0Cfalse: \u53EA\u5BFC\u51FA\u53EF\u89C1\u533A\u57DF", false).option("--no-use-render-bounds", "\u4E0D\u5305\u542B\u7279\u6548\u548C\u5916\u63CF\u8FB9\u3002\u9ED8\u8BA4\u5305\u542B\u9634\u5F71\u3001\u5916\u63CF\u8FB9\u7B49").option("--no-auto-start", "\u7981\u7528\u81EA\u52A8\u542F\u52A8 Server").option("--no-retry", "\u7981\u7528\u81EA\u52A8\u91CD\u8BD5").action(async (options) => {
|
|
2293
2308
|
await handleExportImage(options);
|
|
2294
2309
|
});
|
|
2295
2310
|
}
|
|
@@ -2329,7 +2344,7 @@ async function handleExportImage(options) {
|
|
|
2329
2344
|
}
|
|
2330
2345
|
if (options.fileId) {
|
|
2331
2346
|
const domain = options.domain || "mastergo.netease.com";
|
|
2332
|
-
pageUrl =
|
|
2347
|
+
pageUrl = buildPageUrl(domain, options.fileId, options.pageType);
|
|
2333
2348
|
}
|
|
2334
2349
|
}
|
|
2335
2350
|
const client = new MGClient({
|
|
@@ -2469,7 +2484,7 @@ async function convertSvgToVector(svgPath, outputDir) {
|
|
|
2469
2484
|
// src/cli/commands/execute-code.ts
|
|
2470
2485
|
import { Command as Command6 } from "commander";
|
|
2471
2486
|
function createExecuteCodeCommand() {
|
|
2472
|
-
return new Command6("execute_code").description("\u5728 MasterGo \u9875\u9762\u6267\u884C\u81EA\u5B9A\u4E49 JavaScript \u4EE3\u7801\u3002\u901A\u8FC7 mg \u53D8\u91CF\u8BBF\u95EE MasterGo API\uFF0C\u7ED3\u679C\u4F1A\u88AB JSON \u5E8F\u5217\u5316\u8FD4\u56DE").argument("<code>", "\u8981\u6267\u884C\u7684\u4EE3\u7801\u3002\u53EF\u4F7F\u7528 mg \u53D8\u91CF\uFF0C\u5982 mg.currentPage.name\u3001mg.currentPage.selection").option("--link <url>", "mgp:// \u534F\u8BAE\u94FE\u63A5\uFF0C\u7528\u4E8E\u6307\u5B9A\u76EE\u6807\u9875\u9762\u3002\u4E0E --domain/--fileId \u4E8C\u9009\u4E00").option("--domain <domain>", "MasterGo \u57DF\u540D\uFF0C\u9ED8\u8BA4 mastergo.netease.com", "mastergo.netease.com").option("--fileId <id>", "\u6587\u4EF6 ID\uFF08\u7EAF\u6570\u5B57\uFF09\uFF0C\u4E0E --domain \u914D\u5408\u6307\u5B9A\u76EE\u6807\u9875\u9762").option("--pretty", "\u683C\u5F0F\u5316\u8F93\u51FA JSON\uFF08\u9ED8\u8BA4\u538B\u7F29\uFF09", false).option("--no-auto-start", "\u7981\u7528\u81EA\u52A8\u542F\u52A8 Server").option("--no-retry", "\u7981\u7528\u81EA\u52A8\u91CD\u8BD5").action(async (code, options) => {
|
|
2487
|
+
return new Command6("execute_code").description("\u5728 MasterGo \u9875\u9762\u6267\u884C\u81EA\u5B9A\u4E49 JavaScript \u4EE3\u7801\u3002\u901A\u8FC7 mg \u53D8\u91CF\u8BBF\u95EE MasterGo API\uFF0C\u7ED3\u679C\u4F1A\u88AB JSON \u5E8F\u5217\u5316\u8FD4\u56DE").argument("<code>", "\u8981\u6267\u884C\u7684\u4EE3\u7801\u3002\u53EF\u4F7F\u7528 mg \u53D8\u91CF\uFF0C\u5982 mg.currentPage.name\u3001mg.currentPage.selection").option("--link <url>", "mgp:// \u534F\u8BAE\u94FE\u63A5\uFF0C\u7528\u4E8E\u6307\u5B9A\u76EE\u6807\u9875\u9762\u3002\u4E0E --domain/--fileId \u4E8C\u9009\u4E00").option("--domain <domain>", "MasterGo \u57DF\u540D\uFF0C\u9ED8\u8BA4 mastergo.netease.com", "mastergo.netease.com").option("--fileId <id>", "\u6587\u4EF6 ID\uFF08\u7EAF\u6570\u5B57\uFF09\uFF0C\u4E0E --domain \u914D\u5408\u6307\u5B9A\u76EE\u6807\u9875\u9762").option("--pageType <type>", "\u9875\u9762\u7C7B\u578B: file(\u9ED8\u8BA4) \u6216 prototyping", "file").option("--pretty", "\u683C\u5F0F\u5316\u8F93\u51FA JSON\uFF08\u9ED8\u8BA4\u538B\u7F29\uFF09", false).option("--no-auto-start", "\u7981\u7528\u81EA\u52A8\u542F\u52A8 Server").option("--no-retry", "\u7981\u7528\u81EA\u52A8\u91CD\u8BD5").action(async (code, options) => {
|
|
2473
2488
|
await handleExecuteCode(code, options);
|
|
2474
2489
|
});
|
|
2475
2490
|
}
|
|
@@ -2490,7 +2505,7 @@ async function handleExecuteCode(code, options) {
|
|
|
2490
2505
|
pageUrl = parsed.pageUrl;
|
|
2491
2506
|
} else if (options.fileId) {
|
|
2492
2507
|
const domain = options.domain || "mastergo.netease.com";
|
|
2493
|
-
pageUrl =
|
|
2508
|
+
pageUrl = buildPageUrl(domain, options.fileId, options.pageType);
|
|
2494
2509
|
}
|
|
2495
2510
|
const client = new MGClient({
|
|
2496
2511
|
noAutoStart: options.noAutoStart,
|
|
@@ -2521,7 +2536,7 @@ import { resolve as resolve6, dirname as dirname9 } from "path";
|
|
|
2521
2536
|
import { mkdirSync as mkdirSync8 } from "fs";
|
|
2522
2537
|
import { tmpdir as tmpdir2 } from "os";
|
|
2523
2538
|
function createGetAllPagesCommand() {
|
|
2524
|
-
return new Command7("get_all_pages").description("\u83B7\u53D6 MasterGo \u6587\u6863\u7684\u6240\u6709\u9875\u9762\u4FE1\u606F\u3002\u4E0D\u6307\u5B9A --output \u65F6\u4FDD\u5B58\u5230\u7CFB\u7EDF\u4E34\u65F6\u76EE\u5F55").option("--link <url>", "\u9875\u9762\u94FE\u63A5\u3002\u652F\u6301\u5B8C\u6574 URL \u6216 mgp:// \u534F\u8BAE").option("--fileId <id>", "\u6587\u4EF6 ID\uFF08\u7EAF\u6570\u5B57\uFF09\u3002\u4ECE URL \u4E2D /file/ \u540E\u9762\u7684\u6570\u5B57").option("--domain <domain>", "MasterGo \u57DF\u540D\uFF0C\u9ED8\u8BA4 mastergo.netease.com\u3002\u4E0E --fileId \u914D\u5408\u4F7F\u7528", "mastergo.netease.com").option("--output <path>", "\u8F93\u51FA JSON \u6587\u4EF6\u8DEF\u5F84\u3002\u4E0D\u6307\u5B9A\u5219\u4FDD\u5B58\u5230\u7CFB\u7EDF\u4E34\u65F6\u76EE\u5F55").option("--pretty", "\u683C\u5F0F\u5316\u8F93\u51FA JSON\uFF08\u9ED8\u8BA4\u538B\u7F29\uFF09", false).option("--no-auto-start", "\u7981\u7528\u81EA\u52A8\u542F\u52A8 Server").option("--no-retry", "\u7981\u7528\u81EA\u52A8\u91CD\u8BD5").action(async (options) => {
|
|
2539
|
+
return new Command7("get_all_pages").description("\u83B7\u53D6 MasterGo \u6587\u6863\u7684\u6240\u6709\u9875\u9762\u4FE1\u606F\u3002\u4E0D\u6307\u5B9A --output \u65F6\u4FDD\u5B58\u5230\u7CFB\u7EDF\u4E34\u65F6\u76EE\u5F55").option("--link <url>", "\u9875\u9762\u94FE\u63A5\u3002\u652F\u6301\u5B8C\u6574 URL \u6216 mgp:// \u534F\u8BAE").option("--fileId <id>", "\u6587\u4EF6 ID\uFF08\u7EAF\u6570\u5B57\uFF09\u3002\u4ECE URL \u4E2D /file/ \u540E\u9762\u7684\u6570\u5B57").option("--domain <domain>", "MasterGo \u57DF\u540D\uFF0C\u9ED8\u8BA4 mastergo.netease.com\u3002\u4E0E --fileId \u914D\u5408\u4F7F\u7528", "mastergo.netease.com").option("--pageType <type>", "\u9875\u9762\u7C7B\u578B: file(\u9ED8\u8BA4) \u6216 prototyping", "file").option("--output <path>", "\u8F93\u51FA JSON \u6587\u4EF6\u8DEF\u5F84\u3002\u4E0D\u6307\u5B9A\u5219\u4FDD\u5B58\u5230\u7CFB\u7EDF\u4E34\u65F6\u76EE\u5F55").option("--pretty", "\u683C\u5F0F\u5316\u8F93\u51FA JSON\uFF08\u9ED8\u8BA4\u538B\u7F29\uFF09", false).option("--no-auto-start", "\u7981\u7528\u81EA\u52A8\u542F\u52A8 Server").option("--no-retry", "\u7981\u7528\u81EA\u52A8\u91CD\u8BD5").action(async (options) => {
|
|
2525
2540
|
await handleGetAllPages(options);
|
|
2526
2541
|
});
|
|
2527
2542
|
}
|
|
@@ -2551,7 +2566,7 @@ async function handleGetAllPages(options) {
|
|
|
2551
2566
|
let pageUrl;
|
|
2552
2567
|
if (fileId) {
|
|
2553
2568
|
const domain = options.domain || "mastergo.netease.com";
|
|
2554
|
-
pageUrl =
|
|
2569
|
+
pageUrl = buildPageUrl(domain, fileId, options.pageType);
|
|
2555
2570
|
}
|
|
2556
2571
|
const data = await client.requestWithRetry(
|
|
2557
2572
|
"get_all_pages" /* GET_ALL_PAGES */,
|
|
@@ -2590,7 +2605,7 @@ import { writeFileSync as writeFileSync8 } from "fs";
|
|
|
2590
2605
|
import { resolve as resolve7, dirname as dirname10 } from "path";
|
|
2591
2606
|
import { mkdirSync as mkdirSync9 } from "fs";
|
|
2592
2607
|
function createGetNodeForSpaceCommand() {
|
|
2593
|
-
return new Command8("get_node_for_space").description("\u83B7\u53D6\u8282\u70B9\u6216\u9875\u9762\u7684\u7A7A\u95F4\u4F4D\u7F6E\u4FE1\u606F\uFF08id\u3001name\u3001x\u3001y\u3001width\u3001height\uFF09\uFF0C\u7528\u4E8E AI \u7406\u89E3\u5143\u7D20\u5E03\u5C40\u3002\u9ED8\u8BA4\u83B7\u53D6\u6700\u6DF1\u5C42\u7EA7\u3002\u652F\u6301 nodeId \u548C pageId \u94FE\u63A5").option("--nodeId <id>", "\u8282\u70B9 ID\uFF0C\u683C\u5F0F\u5982 123:456\u3002\u4E0E --link \u4E8C\u9009\u4E00").option("--link <url>", "mgp:// \u534F\u8BAE\u94FE\u63A5\uFF08\u652F\u6301 nodeId \u548C pageId\uFF09\u3002\u4E0E --nodeId \u4E8C\u9009\u4E00").requiredOption("--output <path>", "\u8F93\u51FA JSON \u6587\u4EF6\u8DEF\u5F84").option("--domain <domain>", "MasterGo \u57DF\u540D\uFF0C\u9ED8\u8BA4 mastergo.netease.com\u3002\u4E0E --nodeId \u914D\u5408\u4F7F\u7528", "mastergo.netease.com").option("--fileId <id>", "\u6587\u4EF6 ID\uFF08\u7EAF\u6570\u5B57\uFF09\uFF0C\u4E0E --domain \u548C --nodeId \u914D\u5408\u4F7F\u7528").option("--maxDepth <number>", "\u904D\u5386\u6DF1\u5EA6\uFF0C\u9ED8\u8BA4 99\uFF08\u83B7\u53D6\u6700\u6DF1\u5C42\u7EA7\uFF09", "99").option("--includeInvisible", "\u5305\u542B\u4E0D\u53EF\u89C1\u8282\u70B9", false).option("--pretty", "\u683C\u5F0F\u5316\u8F93\u51FA JSON\uFF08\u9ED8\u8BA4\u538B\u7F29\uFF09", false).option("--no-auto-start", "\u7981\u7528\u81EA\u52A8\u542F\u52A8 Server").option("--no-retry", "\u7981\u7528\u81EA\u52A8\u91CD\u8BD5").action(async (options) => {
|
|
2608
|
+
return new Command8("get_node_for_space").description("\u83B7\u53D6\u8282\u70B9\u6216\u9875\u9762\u7684\u7A7A\u95F4\u4F4D\u7F6E\u4FE1\u606F\uFF08id\u3001name\u3001x\u3001y\u3001width\u3001height\uFF09\uFF0C\u7528\u4E8E AI \u7406\u89E3\u5143\u7D20\u5E03\u5C40\u3002\u9ED8\u8BA4\u83B7\u53D6\u6700\u6DF1\u5C42\u7EA7\u3002\u652F\u6301 nodeId \u548C pageId \u94FE\u63A5").option("--nodeId <id>", "\u8282\u70B9 ID\uFF0C\u683C\u5F0F\u5982 123:456\u3002\u4E0E --link \u4E8C\u9009\u4E00").option("--link <url>", "mgp:// \u534F\u8BAE\u94FE\u63A5\uFF08\u652F\u6301 nodeId \u548C pageId\uFF09\u3002\u4E0E --nodeId \u4E8C\u9009\u4E00").requiredOption("--output <path>", "\u8F93\u51FA JSON \u6587\u4EF6\u8DEF\u5F84").option("--domain <domain>", "MasterGo \u57DF\u540D\uFF0C\u9ED8\u8BA4 mastergo.netease.com\u3002\u4E0E --nodeId \u914D\u5408\u4F7F\u7528", "mastergo.netease.com").option("--fileId <id>", "\u6587\u4EF6 ID\uFF08\u7EAF\u6570\u5B57\uFF09\uFF0C\u4E0E --domain \u548C --nodeId \u914D\u5408\u4F7F\u7528").option("--pageType <type>", "\u9875\u9762\u7C7B\u578B: file(\u9ED8\u8BA4) \u6216 prototyping", "file").option("--maxDepth <number>", "\u904D\u5386\u6DF1\u5EA6\uFF0C\u9ED8\u8BA4 99\uFF08\u83B7\u53D6\u6700\u6DF1\u5C42\u7EA7\uFF09", "99").option("--includeInvisible", "\u5305\u542B\u4E0D\u53EF\u89C1\u8282\u70B9", false).option("--pretty", "\u683C\u5F0F\u5316\u8F93\u51FA JSON\uFF08\u9ED8\u8BA4\u538B\u7F29\uFF09", false).option("--no-auto-start", "\u7981\u7528\u81EA\u52A8\u542F\u52A8 Server").option("--no-retry", "\u7981\u7528\u81EA\u52A8\u91CD\u8BD5").action(async (options) => {
|
|
2594
2609
|
await handleGetNodeForSpace(options);
|
|
2595
2610
|
});
|
|
2596
2611
|
}
|
|
@@ -2632,7 +2647,7 @@ async function handleGetNodeForSpace(options) {
|
|
|
2632
2647
|
nodeId = options.nodeId;
|
|
2633
2648
|
if (options.fileId) {
|
|
2634
2649
|
const domain = options.domain || "mastergo.netease.com";
|
|
2635
|
-
pageUrl =
|
|
2650
|
+
pageUrl = buildPageUrl(domain, options.fileId, options.pageType);
|
|
2636
2651
|
}
|
|
2637
2652
|
}
|
|
2638
2653
|
const client = new MGClient({
|
|
@@ -2706,10 +2721,92 @@ async function handleGetNodeForSpace(options) {
|
|
|
2706
2721
|
}
|
|
2707
2722
|
}
|
|
2708
2723
|
|
|
2709
|
-
// src/cli/commands/
|
|
2724
|
+
// src/cli/commands/get-comments.ts
|
|
2710
2725
|
import { Command as Command9 } from "commander";
|
|
2726
|
+
import { mkdirSync as mkdirSync10, writeFileSync as writeFileSync9 } from "fs";
|
|
2727
|
+
import { dirname as dirname11, resolve as resolve8 } from "path";
|
|
2728
|
+
function createGetCommentsCommand() {
|
|
2729
|
+
return new Command9("get_comments").description("\u83B7\u53D6 MasterGo \u8BC4\u8BBA\u533A\u5185\u5BB9").option("--link <url>", "mgp:// \u534F\u8BAE\u94FE\u63A5\u6216\u9875\u9762 URL\uFF08\u53EF\u9009\uFF0C\u4E0D\u63D0\u4F9B\u5219\u83B7\u53D6\u5F53\u524D\u9875\u9762\uFF09").requiredOption("--output <path>", "\u8F93\u51FA JSON \u6587\u4EF6\u8DEF\u5F84").option("--include-deleted", "\u5305\u542B\u5DF2\u5220\u9664\u7684\u8BC4\u8BBA", false).option("--no-include-nearby", "\u4E0D\u8BA1\u7B97\u9644\u8FD1\u8282\u70B9").option("--nearby-limit <number>", "\u9644\u8FD1\u8282\u70B9\u6570\u91CF\uFF08\u9ED8\u8BA4 5\uFF09", "5").option("--nearby-depth <number>", "\u9644\u8FD1\u8282\u70B9\u641C\u7D22\u6DF1\u5EA6\uFF08\u9ED8\u8BA4 3\uFF09", "3").option("--pretty", "\u683C\u5F0F\u5316\u8F93\u51FA JSON\uFF08\u9ED8\u8BA4\u538B\u7F29\uFF09", false).option("--no-auto-start", "\u7981\u7528\u81EA\u52A8\u542F\u52A8 Server").option("--no-retry", "\u7981\u7528\u81EA\u52A8\u91CD\u8BD5").action(async (options) => {
|
|
2730
|
+
await handleGetComments(options);
|
|
2731
|
+
});
|
|
2732
|
+
}
|
|
2733
|
+
async function handleGetComments(options) {
|
|
2734
|
+
const tracker = createCommandTracker("get_comments");
|
|
2735
|
+
const client = new MGClient({
|
|
2736
|
+
noAutoStart: options.noAutoStart,
|
|
2737
|
+
noRetry: options.noRetry
|
|
2738
|
+
});
|
|
2739
|
+
try {
|
|
2740
|
+
let pageUrl;
|
|
2741
|
+
if (options.link) {
|
|
2742
|
+
if (options.link.startsWith("mgp://")) {
|
|
2743
|
+
const parsed = parseMgpLink(options.link);
|
|
2744
|
+
if (!parsed) {
|
|
2745
|
+
console.error(`\u9519\u8BEF [${"E010" /* INVALID_LINK */}]: \u65E0\u6548\u7684 mgp:// \u94FE\u63A5\u683C\u5F0F`);
|
|
2746
|
+
console.error(`\u63D0\u4F9B\u7684\u94FE\u63A5: ${options.link}`);
|
|
2747
|
+
tracker.failure({ code: "E010" /* INVALID_LINK */, message: "\u65E0\u6548\u7684 mgp:// \u94FE\u63A5\u683C\u5F0F" });
|
|
2748
|
+
process.exit(1);
|
|
2749
|
+
}
|
|
2750
|
+
pageUrl = normalizePageUrl(parsed.pageUrl);
|
|
2751
|
+
} else {
|
|
2752
|
+
pageUrl = normalizePageUrl(options.link);
|
|
2753
|
+
}
|
|
2754
|
+
}
|
|
2755
|
+
await client.connect();
|
|
2756
|
+
const params = {
|
|
2757
|
+
includeDeleted: options.includeDeleted ?? false,
|
|
2758
|
+
includeNearby: options.includeNearby,
|
|
2759
|
+
nearbyLimit: parseNumberOption(options.nearbyLimit, 5),
|
|
2760
|
+
nearbyDepth: parseNumberOption(options.nearbyDepth, 3)
|
|
2761
|
+
};
|
|
2762
|
+
console.log("\u6B63\u5728\u83B7\u53D6\u8BC4\u8BBA\u533A\u5185\u5BB9...");
|
|
2763
|
+
const result = await client.requestWithRetry(
|
|
2764
|
+
"get_comments" /* GET_COMMENTS */,
|
|
2765
|
+
params,
|
|
2766
|
+
pageUrl
|
|
2767
|
+
);
|
|
2768
|
+
const outputPath = resolve8(options.output);
|
|
2769
|
+
mkdirSync10(dirname11(outputPath), { recursive: true });
|
|
2770
|
+
const outputData = {
|
|
2771
|
+
extractedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2772
|
+
...result
|
|
2773
|
+
};
|
|
2774
|
+
const jsonContent = JSON.stringify(outputData, null, options.pretty ? 2 : 0);
|
|
2775
|
+
writeFileSync9(outputPath, jsonContent, "utf-8");
|
|
2776
|
+
console.log(`\u6587\u4EF6\u8DEF\u5F84: ${outputPath}`);
|
|
2777
|
+
const displayPageUrl = pageUrl || result.pageUrl;
|
|
2778
|
+
if (displayPageUrl) {
|
|
2779
|
+
console.log(`\u9875\u9762 URL: ${displayPageUrl}`);
|
|
2780
|
+
}
|
|
2781
|
+
console.log(`\u8BC4\u8BBA\u6570\u91CF: ${result.total}`);
|
|
2782
|
+
console.log(`\u8F93\u51FA\u683C\u5F0F: ${options.pretty ? "\u683C\u5F0F\u5316" : "\u538B\u7F29"}`);
|
|
2783
|
+
tracker.success();
|
|
2784
|
+
} catch (error) {
|
|
2785
|
+
if (error instanceof MGError) {
|
|
2786
|
+
console.error(`\u9519\u8BEF [${error.code}]: ${error.message}`);
|
|
2787
|
+
tracker.failure(error);
|
|
2788
|
+
} else {
|
|
2789
|
+
console.error(`\u9519\u8BEF: ${error instanceof Error ? error.message : error}`);
|
|
2790
|
+
tracker.failure(error instanceof Error ? error : void 0);
|
|
2791
|
+
}
|
|
2792
|
+
process.exit(1);
|
|
2793
|
+
} finally {
|
|
2794
|
+
client.close();
|
|
2795
|
+
}
|
|
2796
|
+
}
|
|
2797
|
+
function parseNumberOption(value, fallback) {
|
|
2798
|
+
if (typeof value === "number") return value;
|
|
2799
|
+
if (typeof value === "string") {
|
|
2800
|
+
const parsed = Number.parseInt(value, 10);
|
|
2801
|
+
return Number.isNaN(parsed) ? fallback : parsed;
|
|
2802
|
+
}
|
|
2803
|
+
return fallback;
|
|
2804
|
+
}
|
|
2805
|
+
|
|
2806
|
+
// src/cli/commands/list-extensions.ts
|
|
2807
|
+
import { Command as Command10 } from "commander";
|
|
2711
2808
|
function createListExtensionsCommand() {
|
|
2712
|
-
return new
|
|
2809
|
+
return new Command10("list_extensions").description("\u5217\u51FA\u6240\u6709\u5DF2\u8FDE\u63A5\u7684 Chrome \u6269\u5C55\u5B9E\u4F8B").option("--no-auto-start", "\u7981\u7528\u81EA\u52A8\u542F\u52A8 Server").option("--no-retry", "\u7981\u7528\u81EA\u52A8\u91CD\u8BD5").action(async (options) => {
|
|
2713
2810
|
await handleListExtensions(options);
|
|
2714
2811
|
});
|
|
2715
2812
|
}
|
|
@@ -2749,9 +2846,9 @@ async function handleListExtensions(options) {
|
|
|
2749
2846
|
}
|
|
2750
2847
|
|
|
2751
2848
|
// src/cli/commands/open-page.ts
|
|
2752
|
-
import { Command as
|
|
2849
|
+
import { Command as Command11 } from "commander";
|
|
2753
2850
|
function createOpenPageCommand() {
|
|
2754
|
-
return new
|
|
2851
|
+
return new Command11("open_page").description("\u901A\u8FC7 Chrome \u6269\u5C55\u6253\u5F00\u6307\u5B9A\u7684\u9875\u9762").requiredOption("--link <link>", "\u9875\u9762\u94FE\u63A5\uFF08\u652F\u6301 https:// \u6216 mgp:// \u683C\u5F0F\uFF09").option("--ext <index>", "\u6269\u5C55\u5B9E\u4F8B\u5E8F\u53F7\uFF081, 2, 3...\uFF09\uFF0C\u9ED8\u8BA4\u81EA\u52A8\u9009\u62E9\u7B2C\u4E00\u4E2A\u53EF\u7528\u6269\u5C55").option("--no-auto-start", "\u7981\u7528\u81EA\u52A8\u542F\u52A8 Server").option("--no-retry", "\u7981\u7528\u81EA\u52A8\u91CD\u8BD5").action(async (options) => {
|
|
2755
2852
|
await handleOpenPage(options);
|
|
2756
2853
|
});
|
|
2757
2854
|
}
|
|
@@ -2846,9 +2943,9 @@ async function handleOpenPage(options) {
|
|
|
2846
2943
|
}
|
|
2847
2944
|
|
|
2848
2945
|
// src/cli/commands/navigate-to-node.ts
|
|
2849
|
-
import { Command as
|
|
2946
|
+
import { Command as Command12 } from "commander";
|
|
2850
2947
|
function createNavigateToNodeCommand() {
|
|
2851
|
-
return new
|
|
2948
|
+
return new Command12("navigate_to_node").description("\u5BFC\u822A\u5230 mgp:// \u94FE\u63A5\u6307\u5B9A\u7684\u8282\u70B9\uFF08\u81EA\u52A8\u5207\u6362\u6216\u6253\u5F00\u9875\u9762\uFF09").requiredOption("--link <url>", "mgp:// \u534F\u8BAE\u94FE\u63A5").option("--ext <index>", "\u6269\u5C55\u5B9E\u4F8B\u5E8F\u53F7\uFF081, 2, 3...\uFF09\uFF0C\u9ED8\u8BA4\u81EA\u52A8\u9009\u62E9\u7B2C\u4E00\u4E2A\u53EF\u7528\u6269\u5C55").option("--no-auto-start", "\u7981\u7528\u81EA\u52A8\u542F\u52A8 Server").option("--no-retry", "\u7981\u7528\u81EA\u52A8\u91CD\u8BD5").action(async (options) => {
|
|
2852
2949
|
await handleNavigateToNode(options);
|
|
2853
2950
|
});
|
|
2854
2951
|
}
|
|
@@ -2943,10 +3040,10 @@ async function handleNavigateToNode(options) {
|
|
|
2943
3040
|
}
|
|
2944
3041
|
|
|
2945
3042
|
// src/cli/commands/visualize.ts
|
|
2946
|
-
import { Command as
|
|
2947
|
-
import { writeFileSync as
|
|
2948
|
-
import { resolve as
|
|
2949
|
-
import { mkdirSync as
|
|
3043
|
+
import { Command as Command13 } from "commander";
|
|
3044
|
+
import { writeFileSync as writeFileSync10 } from "fs";
|
|
3045
|
+
import { resolve as resolve9, dirname as dirname12 } from "path";
|
|
3046
|
+
import { mkdirSync as mkdirSync11 } from "fs";
|
|
2950
3047
|
|
|
2951
3048
|
// src/shared/ascii-renderer.ts
|
|
2952
3049
|
var defaultRenderOptions = {
|
|
@@ -3236,7 +3333,7 @@ function renderAscii(node, options = {}) {
|
|
|
3236
3333
|
|
|
3237
3334
|
// src/cli/commands/visualize.ts
|
|
3238
3335
|
function createVisualizeCommand() {
|
|
3239
|
-
return new
|
|
3336
|
+
return new Command13("visualize").description("\u5C06 MasterGo \u8BBE\u8BA1\u7A3F\u8282\u70B9\u6E32\u67D3\u4E3A ASCII \u793A\u610F\u56FE").requiredOption("--link <url>", "mgp:// \u534F\u8BAE\u94FE\u63A5").option("--output <path>", "\u8F93\u51FA\u6587\u4EF6\u8DEF\u5F84\uFF08\u4E0D\u6307\u5B9A\u5219\u8F93\u51FA\u5230\u7EC8\u7AEF\uFF09").option("--maxDepth <number>", "\u904D\u5386\u6DF1\u5EA6", "3").option("--no-show-id", "\u9690\u85CF\u8282\u70B9 ID").option("--no-show-size", "\u9690\u85CF\u5C3A\u5BF8").option("--no-show-padding", "\u9690\u85CF padding").option("--no-show-radius", "\u9690\u85CF\u5706\u89D2").option("--no-show-layout", "\u9690\u85CF\u5E03\u5C40\u65B9\u5411").option("--no-show-gap", "\u9690\u85CF gap \u53EF\u89C6\u5316").option("--no-compact", "\u4F7F\u7528\u6846\u56FE\u6A21\u5F0F\uFF08\u4EBA\u7C7B\u9605\u8BFB\u4F18\u5316\uFF09").option("--no-auto-start", "\u7981\u7528\u81EA\u52A8\u542F\u52A8 Server").option("--no-retry", "\u7981\u7528\u81EA\u52A8\u91CD\u8BD5").action(async (options) => {
|
|
3240
3337
|
await handleVisualize(options);
|
|
3241
3338
|
});
|
|
3242
3339
|
}
|
|
@@ -3288,10 +3385,10 @@ async function handleVisualize(options) {
|
|
|
3288
3385
|
};
|
|
3289
3386
|
const asciiOutput = renderAscii(data, renderOptions);
|
|
3290
3387
|
if (options.output) {
|
|
3291
|
-
const outputPath =
|
|
3292
|
-
const outputDir =
|
|
3293
|
-
|
|
3294
|
-
|
|
3388
|
+
const outputPath = resolve9(options.output);
|
|
3389
|
+
const outputDir = dirname12(outputPath);
|
|
3390
|
+
mkdirSync11(outputDir, { recursive: true });
|
|
3391
|
+
writeFileSync10(outputPath, asciiOutput, "utf-8");
|
|
3295
3392
|
console.log(`ASCII \u793A\u610F\u56FE\u5DF2\u4FDD\u5B58\u5230: ${outputPath}`);
|
|
3296
3393
|
console.log(`Link: ${options.link}`);
|
|
3297
3394
|
console.log(`\u6A21\u5F0F: ${options.compact ? "\u7D27\u51D1" : "\u6807\u51C6"}`);
|
|
@@ -3312,7 +3409,7 @@ async function handleVisualize(options) {
|
|
|
3312
3409
|
}
|
|
3313
3410
|
|
|
3314
3411
|
// src/cli/index.ts
|
|
3315
|
-
var program = new
|
|
3412
|
+
var program = new Command14();
|
|
3316
3413
|
program.name("mg-cli").description("MasterGo CLI \u5DE5\u5177 - \u7528\u4E8E Claude Code \u4E0E MasterGo \u901A\u4FE1").version(getVersion());
|
|
3317
3414
|
program.addCommand(createServerCommand());
|
|
3318
3415
|
program.addCommand(createGetNodeByIdCommand());
|
|
@@ -3322,6 +3419,7 @@ program.addCommand(createExportImageCommand());
|
|
|
3322
3419
|
program.addCommand(createExecuteCodeCommand());
|
|
3323
3420
|
program.addCommand(createGetAllPagesCommand());
|
|
3324
3421
|
program.addCommand(createGetNodeForSpaceCommand());
|
|
3422
|
+
program.addCommand(createGetCommentsCommand());
|
|
3325
3423
|
program.addCommand(createListExtensionsCommand());
|
|
3326
3424
|
program.addCommand(createOpenPageCommand());
|
|
3327
3425
|
program.addCommand(createNavigateToNodeCommand());
|