weapp-ide-cli 5.1.2 → 5.1.4
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-g8B8r0xg.js → cli-BkQJ3Aww.js} +175 -353
- package/dist/cli.js +2 -2
- package/dist/{commands-BwCMEmX-.js → commands-CSbpftLN.js} +350 -97
- package/dist/index.d.ts +71 -43
- package/dist/index.js +3 -3
- package/package.json +4 -3
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import process, { stdin, stdout } from "node:process";
|
|
1
|
+
import { A as createLocaleConfig, B as operatingSystemName, E as resolveCliPath, F as defaultCustomConfigFilePath, H as logger_default, I as resolvePath, M as readCustomConfig, N as removeCustomConfigKey, O as getConfiguredLocale, V as colors, _ as connectMiniProgram, a as navigateBack, b as i18nText, c as pageStack, d as remote, f as scrollTo, g as tap, i as input, j as overwriteCustomConfig, k as createCustomConfig, l as reLaunch, m as systemInfo, o as navigateTo, p as switchTab, r as currentPage, s as pageData, t as audit, u as redirectTo, x as validateLocaleOption, y as configureLocaleFromArgv, z as isOperatingSystemSupported } from "./commands-CSbpftLN.js";
|
|
3
2
|
import fs from "fs-extra";
|
|
4
|
-
import
|
|
5
|
-
import os from "node:os";
|
|
3
|
+
import process, { stdin, stdout } from "node:process";
|
|
6
4
|
import { createInterface } from "node:readline/promises";
|
|
7
5
|
import { inspect } from "node:util";
|
|
8
6
|
import { emitKeypressEvents } from "node:readline";
|
|
7
|
+
import { cac } from "cac";
|
|
9
8
|
//#region src/cli/automator-argv.ts
|
|
10
9
|
/**
|
|
11
10
|
* @description 解析 automator 命令通用参数与位置参数。
|
|
@@ -183,7 +182,7 @@ async function runScreenshot(argv) {
|
|
|
183
182
|
}
|
|
184
183
|
const options = parseScreenshotArgs(argv);
|
|
185
184
|
const isJsonOutput = argv.includes("--json");
|
|
186
|
-
const { takeScreenshot } = await import("./commands-
|
|
185
|
+
const { takeScreenshot } = await import("./commands-CSbpftLN.js").then((n) => n.n);
|
|
187
186
|
const result = await takeScreenshot(options);
|
|
188
187
|
if (isJsonOutput) {
|
|
189
188
|
console.log(JSON.stringify(result, null, 2));
|
|
@@ -193,6 +192,43 @@ async function runScreenshot(argv) {
|
|
|
193
192
|
}
|
|
194
193
|
//#endregion
|
|
195
194
|
//#region src/cli/run-automator.ts
|
|
195
|
+
const COMMON_OPTION_DEFINITIONS = [
|
|
196
|
+
{
|
|
197
|
+
flag: "-p, --project <path>",
|
|
198
|
+
description: {
|
|
199
|
+
zh: "项目路径(默认:当前目录)",
|
|
200
|
+
en: "Project path (default: current directory)"
|
|
201
|
+
}
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
flag: "-t, --timeout <ms>",
|
|
205
|
+
description: {
|
|
206
|
+
zh: "连接超时时间(默认:30000)",
|
|
207
|
+
en: "Connection timeout (default: 30000)"
|
|
208
|
+
}
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
flag: "--json",
|
|
212
|
+
description: {
|
|
213
|
+
zh: "支持时以 JSON 输出",
|
|
214
|
+
en: "Output as JSON when supported"
|
|
215
|
+
}
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
flag: "--lang <lang>",
|
|
219
|
+
description: {
|
|
220
|
+
zh: "语言切换:zh | en(默认:zh)",
|
|
221
|
+
en: "Language: zh | en (default: zh)"
|
|
222
|
+
}
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
flag: "-h, --help",
|
|
226
|
+
description: {
|
|
227
|
+
zh: "显示命令帮助",
|
|
228
|
+
en: "Show command help"
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
];
|
|
196
232
|
const COMMON_ALLOWED_OPTIONS = new Set([
|
|
197
233
|
"-p",
|
|
198
234
|
"--project",
|
|
@@ -203,6 +239,27 @@ const COMMON_ALLOWED_OPTIONS = new Set([
|
|
|
203
239
|
"-h",
|
|
204
240
|
"--help"
|
|
205
241
|
]);
|
|
242
|
+
function createDefinition(input) {
|
|
243
|
+
return {
|
|
244
|
+
description: input.description,
|
|
245
|
+
usage: input.usage,
|
|
246
|
+
options: input.options ?? [],
|
|
247
|
+
allowedOptions: new Set([...COMMON_ALLOWED_OPTIONS, ...input.allowedOptions ?? []]),
|
|
248
|
+
handler: input.handler
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
function requiredPositional(value, errorMessage) {
|
|
252
|
+
if (!value) throw new Error(errorMessage);
|
|
253
|
+
return value;
|
|
254
|
+
}
|
|
255
|
+
function validateUnsupportedOptions(command, argv, allowedOptions) {
|
|
256
|
+
for (const token of argv) {
|
|
257
|
+
if (!token.startsWith("-")) continue;
|
|
258
|
+
const optionName = token.includes("=") ? token.slice(0, token.indexOf("=")) : token;
|
|
259
|
+
if (allowedOptions.has(optionName)) continue;
|
|
260
|
+
throw new Error(i18nText(`'${command}' 命令不支持参数 '${optionName}'`, `Command '${command}' does not support option '${optionName}'`));
|
|
261
|
+
}
|
|
262
|
+
}
|
|
206
263
|
const COMMAND_DEFINITIONS = {
|
|
207
264
|
"navigate": createDefinition({
|
|
208
265
|
description: {
|
|
@@ -405,85 +462,26 @@ const COMMAND_DEFINITIONS = {
|
|
|
405
462
|
})
|
|
406
463
|
};
|
|
407
464
|
const AUTOMATOR_COMMAND_NAMES = ["screenshot", ...Object.keys(COMMAND_DEFINITIONS)];
|
|
408
|
-
const
|
|
465
|
+
const AUTOMATOR_COMMAND_SET = new Set(AUTOMATOR_COMMAND_NAMES);
|
|
409
466
|
/**
|
|
410
467
|
* @description 判断是否属于 automator 子命令。
|
|
411
468
|
*/
|
|
412
469
|
function isAutomatorCommand(command) {
|
|
413
|
-
return Boolean(command &&
|
|
470
|
+
return Boolean(command && AUTOMATOR_COMMAND_SET.has(command));
|
|
414
471
|
}
|
|
415
472
|
/**
|
|
416
|
-
* @description
|
|
417
|
-
*/
|
|
418
|
-
async function runAutomatorCommand(command, argv) {
|
|
419
|
-
if (command === "screenshot") {
|
|
420
|
-
await runScreenshot(argv);
|
|
421
|
-
return;
|
|
422
|
-
}
|
|
423
|
-
const definition = COMMAND_DEFINITIONS[command];
|
|
424
|
-
if (!definition) throw new Error(i18nText(`未知 automator 命令: ${command}`, `Unknown automator command: ${command}`));
|
|
425
|
-
if (argv.includes("-h") || argv.includes("--help")) {
|
|
426
|
-
printCommandHelp(command);
|
|
427
|
-
return;
|
|
428
|
-
}
|
|
429
|
-
validateUnsupportedOptions(command, argv, definition.allowedOptions);
|
|
430
|
-
const args = parseAutomatorArgs(argv);
|
|
431
|
-
await definition.handler({
|
|
432
|
-
argv,
|
|
433
|
-
args
|
|
434
|
-
});
|
|
435
|
-
}
|
|
436
|
-
/**
|
|
437
|
-
* @description 获取 automator 命令帮助文本。
|
|
473
|
+
* @description 获取 automator 子命令帮助文本。
|
|
438
474
|
*/
|
|
439
475
|
function getAutomatorCommandHelp(command) {
|
|
440
476
|
const definition = COMMAND_DEFINITIONS[command];
|
|
441
477
|
if (!definition) return;
|
|
442
|
-
const optionLines = [
|
|
443
|
-
...definition.options,
|
|
444
|
-
{
|
|
445
|
-
flag: "-p, --project <path>",
|
|
446
|
-
description: {
|
|
447
|
-
zh: "项目路径(默认:当前目录)",
|
|
448
|
-
en: "Project path (default: current directory)"
|
|
449
|
-
}
|
|
450
|
-
},
|
|
451
|
-
{
|
|
452
|
-
flag: "-t, --timeout <ms>",
|
|
453
|
-
description: {
|
|
454
|
-
zh: "连接超时时间(默认:30000)",
|
|
455
|
-
en: "Connection timeout (default: 30000)"
|
|
456
|
-
}
|
|
457
|
-
},
|
|
458
|
-
{
|
|
459
|
-
flag: "--json",
|
|
460
|
-
description: {
|
|
461
|
-
zh: "支持时以 JSON 输出",
|
|
462
|
-
en: "Output as JSON when supported"
|
|
463
|
-
}
|
|
464
|
-
},
|
|
465
|
-
{
|
|
466
|
-
flag: "--lang <lang>",
|
|
467
|
-
description: {
|
|
468
|
-
zh: "语言切换:zh | en(默认:zh)",
|
|
469
|
-
en: "Language: zh | en (default: zh)"
|
|
470
|
-
}
|
|
471
|
-
},
|
|
472
|
-
{
|
|
473
|
-
flag: "-h, --help",
|
|
474
|
-
description: {
|
|
475
|
-
zh: "显示命令帮助",
|
|
476
|
-
en: "Show command help"
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
];
|
|
480
478
|
return [
|
|
481
479
|
i18nText(definition.description.zh, definition.description.en),
|
|
482
480
|
"",
|
|
483
481
|
`Usage: ${definition.usage}`,
|
|
484
482
|
"",
|
|
485
483
|
i18nText("参数:", "Options:"),
|
|
486
|
-
...
|
|
484
|
+
...[...definition.options, ...COMMON_OPTION_DEFINITIONS].map((option) => ` ${option.flag.padEnd(24)} ${i18nText(option.description.zh, option.description.en)}`)
|
|
487
485
|
].join("\n");
|
|
488
486
|
}
|
|
489
487
|
function printCommandHelp(command) {
|
|
@@ -494,28 +492,26 @@ function printCommandHelp(command) {
|
|
|
494
492
|
}
|
|
495
493
|
logger_default.warn(i18nText(`命令 ${command} 暂无帮助信息`, `No help available for command: ${command}`));
|
|
496
494
|
}
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
allowedOptions,
|
|
505
|
-
handler: input.handler
|
|
506
|
-
};
|
|
507
|
-
}
|
|
508
|
-
function validateUnsupportedOptions(command, argv, allowedOptions) {
|
|
509
|
-
for (const token of argv) {
|
|
510
|
-
if (!token.startsWith("-")) continue;
|
|
511
|
-
const optionName = token.includes("=") ? token.slice(0, token.indexOf("=")) : token;
|
|
512
|
-
if (allowedOptions.has(optionName)) continue;
|
|
513
|
-
throw new Error(i18nText(`'${command}' 命令不支持参数 '${optionName}'`, `Unknown option '${optionName}' for '${command}' command`));
|
|
495
|
+
/**
|
|
496
|
+
* @description 执行 automator 子命令。
|
|
497
|
+
*/
|
|
498
|
+
async function runAutomatorCommand(command, argv) {
|
|
499
|
+
if (command === "screenshot") {
|
|
500
|
+
await runScreenshot(argv);
|
|
501
|
+
return;
|
|
514
502
|
}
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
if (
|
|
518
|
-
|
|
503
|
+
const definition = COMMAND_DEFINITIONS[command];
|
|
504
|
+
if (!definition) throw new Error(i18nText(`未知 automator 命令: ${command}`, `Unknown automator command: ${command}`));
|
|
505
|
+
if (argv.includes("-h") || argv.includes("--help")) {
|
|
506
|
+
printCommandHelp(command);
|
|
507
|
+
return;
|
|
508
|
+
}
|
|
509
|
+
validateUnsupportedOptions(command, argv, definition.allowedOptions);
|
|
510
|
+
const args = parseAutomatorArgs(argv);
|
|
511
|
+
await definition.handler({
|
|
512
|
+
argv,
|
|
513
|
+
args
|
|
514
|
+
});
|
|
519
515
|
}
|
|
520
516
|
//#endregion
|
|
521
517
|
//#region src/cli/command-catalog.ts
|
|
@@ -559,93 +555,6 @@ function isWeappIdeTopLevelCommand(command) {
|
|
|
559
555
|
return Boolean(command && WEAPP_IDE_TOP_LEVEL_COMMAND_SET.has(command));
|
|
560
556
|
}
|
|
561
557
|
//#endregion
|
|
562
|
-
//#region src/utils/path.ts
|
|
563
|
-
/**
|
|
564
|
-
* @description 解析为绝对路径(基于当前工作目录)
|
|
565
|
-
*/
|
|
566
|
-
function resolvePath(filePath) {
|
|
567
|
-
if (path.isAbsolute(filePath)) return filePath;
|
|
568
|
-
return path.resolve(process.cwd(), filePath);
|
|
569
|
-
}
|
|
570
|
-
//#endregion
|
|
571
|
-
//#region src/config/paths.ts
|
|
572
|
-
const homedir = os.homedir();
|
|
573
|
-
/**
|
|
574
|
-
* @description 默认自定义配置目录
|
|
575
|
-
*/
|
|
576
|
-
const defaultCustomConfigDirPath = path.join(homedir, ".weapp-ide-cli");
|
|
577
|
-
/**
|
|
578
|
-
* @description 默认自定义配置文件路径
|
|
579
|
-
*/
|
|
580
|
-
const defaultCustomConfigFilePath = path.join(defaultCustomConfigDirPath, "config.json");
|
|
581
|
-
//#endregion
|
|
582
|
-
//#region src/config/custom.ts
|
|
583
|
-
const JSON_OPTIONS = {
|
|
584
|
-
encoding: "utf8",
|
|
585
|
-
spaces: 2
|
|
586
|
-
};
|
|
587
|
-
/**
|
|
588
|
-
* @description 写入自定义 CLI 路径配置
|
|
589
|
-
*/
|
|
590
|
-
async function createCustomConfig(params) {
|
|
591
|
-
const trimmedCliPath = params.cliPath.trim();
|
|
592
|
-
if (!trimmedCliPath) throw new Error("cliPath cannot be empty");
|
|
593
|
-
const normalizedCliPath = resolvePath(trimmedCliPath);
|
|
594
|
-
await writeCustomConfig({ cliPath: normalizedCliPath });
|
|
595
|
-
return normalizedCliPath;
|
|
596
|
-
}
|
|
597
|
-
/**
|
|
598
|
-
* @description 写入语言配置(zh / en)。
|
|
599
|
-
*/
|
|
600
|
-
async function createLocaleConfig(locale) {
|
|
601
|
-
await writeCustomConfig({ locale });
|
|
602
|
-
return locale;
|
|
603
|
-
}
|
|
604
|
-
/**
|
|
605
|
-
* @description 删除指定配置项。
|
|
606
|
-
*/
|
|
607
|
-
async function removeCustomConfigKey(key) {
|
|
608
|
-
const currentConfig = await readCustomConfig();
|
|
609
|
-
if (!(key in currentConfig)) return;
|
|
610
|
-
const nextConfig = { ...currentConfig };
|
|
611
|
-
delete nextConfig[key];
|
|
612
|
-
await writeCustomConfig(nextConfig, { replace: true });
|
|
613
|
-
}
|
|
614
|
-
/**
|
|
615
|
-
* @description 覆盖写入配置内容(会替换原内容)。
|
|
616
|
-
*/
|
|
617
|
-
async function overwriteCustomConfig(config) {
|
|
618
|
-
const nextConfig = {};
|
|
619
|
-
if (typeof config.cliPath === "string" && config.cliPath.trim()) nextConfig.cliPath = resolvePath(config.cliPath.trim());
|
|
620
|
-
if (config.locale === "zh" || config.locale === "en") nextConfig.locale = config.locale;
|
|
621
|
-
await writeCustomConfig(nextConfig, { replace: true });
|
|
622
|
-
}
|
|
623
|
-
/**
|
|
624
|
-
* @description 读取原始自定义配置。
|
|
625
|
-
*/
|
|
626
|
-
async function readCustomConfig() {
|
|
627
|
-
if (!await fs.pathExists(defaultCustomConfigFilePath)) return {};
|
|
628
|
-
try {
|
|
629
|
-
const config = await fs.readJSON(defaultCustomConfigFilePath);
|
|
630
|
-
if (!config || typeof config !== "object") return {};
|
|
631
|
-
const candidate = config;
|
|
632
|
-
const next = {};
|
|
633
|
-
if (typeof candidate.cliPath === "string" && candidate.cliPath.trim()) next.cliPath = candidate.cliPath.trim();
|
|
634
|
-
if (candidate.locale === "zh" || candidate.locale === "en") next.locale = candidate.locale;
|
|
635
|
-
return next;
|
|
636
|
-
} catch {
|
|
637
|
-
return {};
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
async function writeCustomConfig(patch, options = {}) {
|
|
641
|
-
const nextConfig = {
|
|
642
|
-
...options.replace ? {} : await readCustomConfig(),
|
|
643
|
-
...patch
|
|
644
|
-
};
|
|
645
|
-
await fs.ensureDir(defaultCustomConfigDirPath);
|
|
646
|
-
await fs.writeJSON(defaultCustomConfigFilePath, nextConfig, JSON_OPTIONS);
|
|
647
|
-
}
|
|
648
|
-
//#endregion
|
|
649
558
|
//#region src/cli/prompt.ts
|
|
650
559
|
/**
|
|
651
560
|
* @description 交互式提示并保存 CLI 路径
|
|
@@ -681,134 +590,6 @@ async function promptForCliPath() {
|
|
|
681
590
|
}
|
|
682
591
|
}
|
|
683
592
|
//#endregion
|
|
684
|
-
//#region src/runtime/platform.ts
|
|
685
|
-
/**
|
|
686
|
-
* @description 官方微信开发者工具只支持 Windows、macOS,Linux 只有社区版
|
|
687
|
-
* https://github.com/msojocs/wechat-web-devtools-linux
|
|
688
|
-
*/
|
|
689
|
-
const SupportedPlatformsMap = {
|
|
690
|
-
Windows_NT: "Windows_NT",
|
|
691
|
-
Darwin: "Darwin",
|
|
692
|
-
Linux: "Linux"
|
|
693
|
-
};
|
|
694
|
-
/**
|
|
695
|
-
* @description 判断当前系统是否支持微信开发者工具
|
|
696
|
-
*/
|
|
697
|
-
function isOperatingSystemSupported(osName = os.type()) {
|
|
698
|
-
return osName === SupportedPlatformsMap.Windows_NT || osName === SupportedPlatformsMap.Darwin || osName === SupportedPlatformsMap.Linux;
|
|
699
|
-
}
|
|
700
|
-
/**
|
|
701
|
-
* @description 当前系统名称
|
|
702
|
-
*/
|
|
703
|
-
const operatingSystemName = os.type();
|
|
704
|
-
function createLinuxCliResolver() {
|
|
705
|
-
let resolvedPath;
|
|
706
|
-
let attempted = false;
|
|
707
|
-
let pending = null;
|
|
708
|
-
return async () => {
|
|
709
|
-
if (attempted) return resolvedPath;
|
|
710
|
-
if (!pending) pending = (async () => {
|
|
711
|
-
try {
|
|
712
|
-
const envPath = await getFirstBinaryPath("wechat-devtools-cli");
|
|
713
|
-
if (envPath) resolvedPath = envPath;
|
|
714
|
-
} catch (error) {
|
|
715
|
-
const reason = error instanceof Error ? error.message : String(error);
|
|
716
|
-
logger_default.warn(`获取 Linux wechat-devtools-cli 路径失败:${reason}`);
|
|
717
|
-
} finally {
|
|
718
|
-
attempted = true;
|
|
719
|
-
}
|
|
720
|
-
return resolvedPath;
|
|
721
|
-
})();
|
|
722
|
-
return pending;
|
|
723
|
-
};
|
|
724
|
-
}
|
|
725
|
-
const linuxCliResolver = createLinuxCliResolver();
|
|
726
|
-
const WINDOWS_DEFAULT_CLI = "C:\\Program Files (x86)\\Tencent\\微信web开发者工具\\cli.bat";
|
|
727
|
-
const DARWIN_DEFAULT_CLI = "/Applications/wechatwebdevtools.app/Contents/MacOS/cli";
|
|
728
|
-
const cliPathResolvers = {
|
|
729
|
-
[SupportedPlatformsMap.Windows_NT]: async () => WINDOWS_DEFAULT_CLI,
|
|
730
|
-
[SupportedPlatformsMap.Darwin]: async () => DARWIN_DEFAULT_CLI,
|
|
731
|
-
[SupportedPlatformsMap.Linux]: linuxCliResolver
|
|
732
|
-
};
|
|
733
|
-
/**
|
|
734
|
-
* @description 获取默认 CLI 路径(按系统)
|
|
735
|
-
*/
|
|
736
|
-
async function getDefaultCliPath(targetOs = operatingSystemName) {
|
|
737
|
-
if (!isOperatingSystemSupported(targetOs)) return;
|
|
738
|
-
const resolver = cliPathResolvers[targetOs];
|
|
739
|
-
return await resolver();
|
|
740
|
-
}
|
|
741
|
-
async function getFirstBinaryPath(command) {
|
|
742
|
-
const pathDirs = (process.env.PATH || "").split(path.delimiter);
|
|
743
|
-
for (const dir of pathDirs) {
|
|
744
|
-
const fullPath = path.join(dir, command);
|
|
745
|
-
try {
|
|
746
|
-
await fs.access(fullPath, fs.constants.X_OK);
|
|
747
|
-
return fullPath;
|
|
748
|
-
} catch {
|
|
749
|
-
continue;
|
|
750
|
-
}
|
|
751
|
-
}
|
|
752
|
-
}
|
|
753
|
-
//#endregion
|
|
754
|
-
//#region src/config/resolver.ts
|
|
755
|
-
/**
|
|
756
|
-
* @description 读取并解析 CLI 配置(自定义优先)
|
|
757
|
-
*/
|
|
758
|
-
async function getConfig() {
|
|
759
|
-
if (await fs.pathExists(defaultCustomConfigFilePath)) try {
|
|
760
|
-
const config = await fs.readJSON(defaultCustomConfigFilePath);
|
|
761
|
-
const cliPath = typeof config.cliPath === "string" ? config.cliPath.trim() : "";
|
|
762
|
-
const locale = config.locale === "zh" || config.locale === "en" ? config.locale : void 0;
|
|
763
|
-
if (cliPath) {
|
|
764
|
-
logger_default.info(`全局配置文件路径:${colors.green(defaultCustomConfigFilePath)}`);
|
|
765
|
-
logger_default.info(`自定义 CLI 路径:${colors.green(cliPath)}`);
|
|
766
|
-
return {
|
|
767
|
-
cliPath,
|
|
768
|
-
locale,
|
|
769
|
-
source: "custom"
|
|
770
|
-
};
|
|
771
|
-
}
|
|
772
|
-
logger_default.warn("自定义配置文件缺少有效的 CLI 路径,将尝试使用默认路径。");
|
|
773
|
-
} catch (error) {
|
|
774
|
-
const reason = error instanceof Error ? error.message : String(error);
|
|
775
|
-
logger_default.warn(`解析自定义配置失败,将尝试使用默认路径。原因:${reason}`);
|
|
776
|
-
}
|
|
777
|
-
const fallbackPath = await getDefaultCliPath();
|
|
778
|
-
if (fallbackPath) return {
|
|
779
|
-
cliPath: fallbackPath,
|
|
780
|
-
locale: void 0,
|
|
781
|
-
source: "default"
|
|
782
|
-
};
|
|
783
|
-
return {
|
|
784
|
-
cliPath: "",
|
|
785
|
-
locale: void 0,
|
|
786
|
-
source: "missing"
|
|
787
|
-
};
|
|
788
|
-
}
|
|
789
|
-
/**
|
|
790
|
-
* @description 获取用户配置的语言偏好。
|
|
791
|
-
*/
|
|
792
|
-
async function getConfiguredLocale() {
|
|
793
|
-
return (await readCustomConfig()).locale;
|
|
794
|
-
}
|
|
795
|
-
//#endregion
|
|
796
|
-
//#region src/cli/resolver.ts
|
|
797
|
-
/**
|
|
798
|
-
* @description 解析 CLI 路径并校验可用性
|
|
799
|
-
*/
|
|
800
|
-
async function resolveCliPath() {
|
|
801
|
-
const config = await getConfig();
|
|
802
|
-
if (!config.cliPath) return {
|
|
803
|
-
cliPath: null,
|
|
804
|
-
source: config.source
|
|
805
|
-
};
|
|
806
|
-
return {
|
|
807
|
-
cliPath: await fs.pathExists(config.cliPath) ? config.cliPath : null,
|
|
808
|
-
source: config.source
|
|
809
|
-
};
|
|
810
|
-
}
|
|
811
|
-
//#endregion
|
|
812
593
|
//#region src/cli/config-command.ts
|
|
813
594
|
/**
|
|
814
595
|
* @description 处理 config 子命令。
|
|
@@ -1375,16 +1156,8 @@ function isNonEmptyText(value) {
|
|
|
1375
1156
|
}
|
|
1376
1157
|
//#endregion
|
|
1377
1158
|
//#region src/cli/run.ts
|
|
1378
|
-
const MINIDEV_NAMESPACE = new Set(
|
|
1379
|
-
|
|
1380
|
-
"ali",
|
|
1381
|
-
"minidev"
|
|
1382
|
-
]);
|
|
1383
|
-
const ALIPAY_PLATFORM_ALIASES = new Set([
|
|
1384
|
-
"alipay",
|
|
1385
|
-
"ali",
|
|
1386
|
-
"minidev"
|
|
1387
|
-
]);
|
|
1159
|
+
const MINIDEV_NAMESPACE = new Set(MINIDEV_NAMESPACE_COMMAND_NAMES);
|
|
1160
|
+
const ALIPAY_PLATFORM_ALIASES = new Set(MINIDEV_NAMESPACE_COMMAND_NAMES);
|
|
1388
1161
|
const ARG_TRANSFORMS = [
|
|
1389
1162
|
createAlias({
|
|
1390
1163
|
find: "-p",
|
|
@@ -1398,40 +1171,108 @@ const ARG_TRANSFORMS = [
|
|
|
1398
1171
|
createPathCompat("-i")
|
|
1399
1172
|
];
|
|
1400
1173
|
/**
|
|
1174
|
+
* @description 基于 cac 注册顶层命令,用于统一识别入口。
|
|
1175
|
+
*/
|
|
1176
|
+
function createCli() {
|
|
1177
|
+
const cli = cac("weapp");
|
|
1178
|
+
cli.command("help [command]", "显示命令帮助").allowUnknownOptions();
|
|
1179
|
+
for (const command of WECHAT_CLI_COMMAND_NAMES) cli.command(command, "微信开发者工具官方命令透传").allowUnknownOptions();
|
|
1180
|
+
for (const command of MINIDEV_NAMESPACE_COMMAND_NAMES) cli.command(`${command} [...args]`, "支付宝 minidev 命令透传").allowUnknownOptions();
|
|
1181
|
+
cli.command(`${CONFIG_COMMAND_NAME} [...args]`, "配置 weapp-ide-cli").allowUnknownOptions();
|
|
1182
|
+
for (const command of [
|
|
1183
|
+
"screenshot",
|
|
1184
|
+
"navigate",
|
|
1185
|
+
"redirect",
|
|
1186
|
+
"back",
|
|
1187
|
+
"relaunch",
|
|
1188
|
+
"switch-tab",
|
|
1189
|
+
"page-stack",
|
|
1190
|
+
"current-page",
|
|
1191
|
+
"system-info",
|
|
1192
|
+
"page-data",
|
|
1193
|
+
"tap",
|
|
1194
|
+
"input",
|
|
1195
|
+
"scroll",
|
|
1196
|
+
"audit",
|
|
1197
|
+
"remote"
|
|
1198
|
+
]) cli.command(`${command} [...args]`, "automator 增强命令").allowUnknownOptions();
|
|
1199
|
+
return cli;
|
|
1200
|
+
}
|
|
1201
|
+
async function handleHelpCommand(args) {
|
|
1202
|
+
const targetCommand = args[0];
|
|
1203
|
+
if (!targetCommand) {
|
|
1204
|
+
createCli().outputHelp();
|
|
1205
|
+
return;
|
|
1206
|
+
}
|
|
1207
|
+
if (targetCommand === "screenshot") {
|
|
1208
|
+
printScreenshotHelp();
|
|
1209
|
+
return;
|
|
1210
|
+
}
|
|
1211
|
+
if (isAutomatorCommand(targetCommand)) {
|
|
1212
|
+
const help = getAutomatorCommandHelp(targetCommand);
|
|
1213
|
+
if (help) {
|
|
1214
|
+
console.log(help);
|
|
1215
|
+
return;
|
|
1216
|
+
}
|
|
1217
|
+
}
|
|
1218
|
+
createCli().outputHelp();
|
|
1219
|
+
}
|
|
1220
|
+
async function handleMissingCliPath(source) {
|
|
1221
|
+
const message = source === "custom" ? i18nText("在当前自定义路径中未找到微信web开发者命令行工具,请重新指定路径。", "Cannot find Wechat Web DevTools CLI in custom path, please reconfigure it.") : i18nText(`未检测到微信web开发者命令行工具,请执行 ${colors.bold(colors.green("weapp-ide-cli config"))} 指定路径。`, `Wechat Web DevTools CLI not found, please run ${colors.bold(colors.green("weapp-ide-cli config"))} to configure it.`);
|
|
1222
|
+
logger_default.warn(message);
|
|
1223
|
+
await promptForCliPath();
|
|
1224
|
+
}
|
|
1225
|
+
/**
|
|
1226
|
+
* @description 判断 open 指令是否应转发到 minidev。
|
|
1227
|
+
*/
|
|
1228
|
+
function shouldDelegateOpenToMinidev(argv) {
|
|
1229
|
+
if (argv[0] !== "open") return false;
|
|
1230
|
+
const platform = readOptionValue(argv, "--platform");
|
|
1231
|
+
if (!platform) return false;
|
|
1232
|
+
return ALIPAY_PLATFORM_ALIASES.has(platform.toLowerCase());
|
|
1233
|
+
}
|
|
1234
|
+
/**
|
|
1235
|
+
* @description 将 open 命令参数改写为 minidev ide 参数。
|
|
1236
|
+
*/
|
|
1237
|
+
function createMinidevOpenArgv(argv) {
|
|
1238
|
+
const nextArgv = [...argv];
|
|
1239
|
+
nextArgv[0] = "ide";
|
|
1240
|
+
return removeOption(nextArgv, "--platform");
|
|
1241
|
+
}
|
|
1242
|
+
/**
|
|
1401
1243
|
* @description CLI 入口解析与分发。
|
|
1402
1244
|
*/
|
|
1403
1245
|
async function parse(argv) {
|
|
1404
1246
|
validateLocaleOption(argv);
|
|
1405
1247
|
configureLocaleFromArgv(argv, await getConfiguredLocale());
|
|
1406
|
-
const
|
|
1407
|
-
|
|
1248
|
+
const cli = createCli();
|
|
1249
|
+
cli.parse([
|
|
1250
|
+
"node",
|
|
1251
|
+
"weapp",
|
|
1252
|
+
...argv
|
|
1253
|
+
], { run: false });
|
|
1254
|
+
const matchedCommand = cli.matchedCommandName;
|
|
1255
|
+
if (matchedCommand === "help") {
|
|
1256
|
+
await handleHelpCommand(cli.args);
|
|
1257
|
+
return;
|
|
1258
|
+
}
|
|
1259
|
+
if (matchedCommand && MINIDEV_NAMESPACE.has(matchedCommand)) {
|
|
1408
1260
|
await runMinidev(argv.slice(1));
|
|
1409
1261
|
return;
|
|
1410
1262
|
}
|
|
1411
|
-
if (
|
|
1412
|
-
await
|
|
1263
|
+
if (matchedCommand === "config") {
|
|
1264
|
+
await handleConfigCommand(argv.slice(1));
|
|
1413
1265
|
return;
|
|
1414
1266
|
}
|
|
1415
|
-
if (
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
printScreenshotHelp();
|
|
1419
|
-
return;
|
|
1420
|
-
}
|
|
1421
|
-
if (isAutomatorCommand(targetCommand)) {
|
|
1422
|
-
await runAutomatorCommand(targetCommand, ["--help"]);
|
|
1423
|
-
return;
|
|
1424
|
-
}
|
|
1267
|
+
if (matchedCommand && isAutomatorCommand(matchedCommand)) {
|
|
1268
|
+
await runAutomatorCommand(matchedCommand, argv.slice(1));
|
|
1269
|
+
return;
|
|
1425
1270
|
}
|
|
1426
1271
|
const formattedArgv = transformArgv(argv, ARG_TRANSFORMS);
|
|
1427
1272
|
if (shouldDelegateOpenToMinidev(formattedArgv)) {
|
|
1428
1273
|
await runMinidev(createMinidevOpenArgv(formattedArgv));
|
|
1429
1274
|
return;
|
|
1430
1275
|
}
|
|
1431
|
-
if (command === "config") {
|
|
1432
|
-
await handleConfigCommand(argv.slice(1));
|
|
1433
|
-
return;
|
|
1434
|
-
}
|
|
1435
1276
|
if (!isOperatingSystemSupported(operatingSystemName)) {
|
|
1436
1277
|
logger_default.warn(i18nText(`微信web开发者工具不支持当前平台:${operatingSystemName} !`, `Wechat Web DevTools CLI is not supported on current platform: ${operatingSystemName}!`));
|
|
1437
1278
|
return;
|
|
@@ -1439,29 +1280,10 @@ async function parse(argv) {
|
|
|
1439
1280
|
validateWechatCliCommandArgs(formattedArgv);
|
|
1440
1281
|
const { cliPath, source } = await resolveCliPath();
|
|
1441
1282
|
if (!cliPath) {
|
|
1442
|
-
|
|
1443
|
-
logger_default.warn(message);
|
|
1444
|
-
await promptForCliPath();
|
|
1283
|
+
await handleMissingCliPath(source);
|
|
1445
1284
|
return;
|
|
1446
1285
|
}
|
|
1447
1286
|
await runWechatCliWithRetry(cliPath, formattedArgv);
|
|
1448
1287
|
}
|
|
1449
|
-
/**
|
|
1450
|
-
* @description 判断 open 指令是否应分发到 minidev。
|
|
1451
|
-
*/
|
|
1452
|
-
function shouldDelegateOpenToMinidev(argv) {
|
|
1453
|
-
if (argv[0] !== "open") return false;
|
|
1454
|
-
const platform = readOptionValue(argv, "--platform");
|
|
1455
|
-
if (!platform) return false;
|
|
1456
|
-
return ALIPAY_PLATFORM_ALIASES.has(platform.toLowerCase());
|
|
1457
|
-
}
|
|
1458
|
-
/**
|
|
1459
|
-
* @description 将 open 命令参数转换为 minidev ide 参数。
|
|
1460
|
-
*/
|
|
1461
|
-
function createMinidevOpenArgv(argv) {
|
|
1462
|
-
const nextArgv = [...argv];
|
|
1463
|
-
nextArgv[0] = "ide";
|
|
1464
|
-
return removeOption(nextArgv, "--platform");
|
|
1465
|
-
}
|
|
1466
1288
|
//#endregion
|
|
1467
|
-
export {
|
|
1289
|
+
export { parseAutomatorArgs as A, isWeappIdeTopLevelCommand as C, runAutomatorCommand as D, isAutomatorCommand as E, removeOption as M, parseScreenshotArgs as O, WECHAT_CLI_COMMAND_NAMES as S, getAutomatorCommandHelp as T, handleConfigCommand as _, createWechatIdeLoginRequiredExitError as a, MINIDEV_NAMESPACE_COMMAND_NAMES as b, formatWechatIdeLoginRequiredError as c, runMinidev as d, execute as f, startForwardConsole as g, transformArgv as h, runWechatCliWithRetry as i, readOptionValue as j, printScreenshotHelp as k, isWechatIdeLoginRequiredError as l, createPathCompat as m, parse as n, extractExecutionErrorText as o, createAlias as p, validateWechatCliCommandArgs as r, formatRetryHotkeyPrompt as s, createCli as t, waitForRetryKeypress as u, promptForCliPath as v, AUTOMATOR_COMMAND_NAMES as w, WEAPP_IDE_TOP_LEVEL_COMMAND_NAMES as x, CONFIG_COMMAND_NAME as y };
|
package/dist/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { H as logger_default } from "./commands-CSbpftLN.js";
|
|
2
|
+
import { n as parse } from "./cli-BkQJ3Aww.js";
|
|
3
3
|
import process from "node:process";
|
|
4
4
|
//#region src/cli.ts
|
|
5
5
|
parse(process.argv.slice(2)).catch((err) => {
|