weapp-ide-cli 5.2.5 → 5.2.6
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-D7gUmbTG.js → cli-lB9HDuk-.js} +58 -2
- package/dist/cli.js +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.js +1 -1
- package/package.json +3 -3
|
@@ -7,6 +7,7 @@ import { PNG } from "pngjs";
|
|
|
7
7
|
import pixelmatch from "pixelmatch";
|
|
8
8
|
import { createInterface } from "node:readline/promises";
|
|
9
9
|
import { emitKeypressEvents } from "node:readline";
|
|
10
|
+
import { execa } from "execa";
|
|
10
11
|
import { inspect } from "node:util";
|
|
11
12
|
import { cac } from "cac";
|
|
12
13
|
//#region src/cli/automator-argv.ts
|
|
@@ -1231,6 +1232,9 @@ function createEngineBuildError(message, code) {
|
|
|
1231
1232
|
error.code = code;
|
|
1232
1233
|
return error;
|
|
1233
1234
|
}
|
|
1235
|
+
const ENGINE_BUILD_ENDPOINT_MISSING_PATTERNS = [/Cannot GET \/engine\/build\b/i, /Cannot GET \/engine\/buildResult\//i];
|
|
1236
|
+
const ENGINE_BUILD_CLI_OPENED_PATTERN = /打开项目成功|project\s+opened|open\s+project\s+success/i;
|
|
1237
|
+
const COMPACT_WHITESPACE_PATTERN = /\s+/g;
|
|
1234
1238
|
function sleep(ms) {
|
|
1235
1239
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
1236
1240
|
}
|
|
@@ -1259,6 +1263,38 @@ async function writeEngineBuildLog(logPath, content) {
|
|
|
1259
1263
|
const filePath = await resolveEngineBuildLogFilePath(logPath);
|
|
1260
1264
|
await fs.writeFile(filePath, content, "utf8");
|
|
1261
1265
|
}
|
|
1266
|
+
function isEngineBuildEndpointMissingError(error) {
|
|
1267
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1268
|
+
return ENGINE_BUILD_ENDPOINT_MISSING_PATTERNS.some((pattern) => pattern.test(message));
|
|
1269
|
+
}
|
|
1270
|
+
function compactOutput(value) {
|
|
1271
|
+
return typeof value === "string" ? value.replace(COMPACT_WHITESPACE_PATTERN, " ").trim() : "";
|
|
1272
|
+
}
|
|
1273
|
+
async function runWechatIdeEngineBuildByCli(projectPath, options = {}) {
|
|
1274
|
+
const { cliPath } = await resolveCliPath();
|
|
1275
|
+
if (!cliPath) throw createEngineBuildError("WECHAT_DEVTOOLS_CLI_NOT_FOUND", "WECHAT_DEVTOOLS_CLI_NOT_FOUND");
|
|
1276
|
+
const result = await execa(cliPath, [
|
|
1277
|
+
"engine",
|
|
1278
|
+
"build",
|
|
1279
|
+
path.resolve(projectPath)
|
|
1280
|
+
], {
|
|
1281
|
+
reject: false,
|
|
1282
|
+
timeout: options.overallTimeoutMs ?? 12e4
|
|
1283
|
+
});
|
|
1284
|
+
const stdout = typeof result.stdout === "string" ? result.stdout : "";
|
|
1285
|
+
const stderr = typeof result.stderr === "string" ? result.stderr : "";
|
|
1286
|
+
const output = [stdout, stderr].filter(Boolean).join("\n");
|
|
1287
|
+
await writeEngineBuildLog(options.logPath, output);
|
|
1288
|
+
if ((result.exitCode ?? 1) === 0) {
|
|
1289
|
+
if (stdout) process.stdout.write(stdout);
|
|
1290
|
+
if (stderr) process.stderr.write(stderr);
|
|
1291
|
+
return;
|
|
1292
|
+
}
|
|
1293
|
+
if (ENGINE_BUILD_CLI_OPENED_PATTERN.test(output)) return;
|
|
1294
|
+
if (stdout) process.stdout.write(stdout);
|
|
1295
|
+
if (stderr) process.stderr.write(stderr);
|
|
1296
|
+
throw createEngineBuildError(compactOutput(stderr) || compactOutput(stdout) || `WECHAT_DEVTOOLS_ENGINE_BUILD_CLI_FAILED:${result.exitCode ?? 1}`, "WECHAT_DEVTOOLS_ENGINE_BUILD_CLI_FAILED");
|
|
1297
|
+
}
|
|
1262
1298
|
/**
|
|
1263
1299
|
* @description 通过开发者工具 HTTP 服务端口执行 engine build,并轮询直到构建结束。
|
|
1264
1300
|
*/
|
|
@@ -1294,6 +1330,7 @@ async function runWechatIdeEngineBuild(projectPath, options = {}) {
|
|
|
1294
1330
|
await writeEngineBuildLog(options.logPath, logs.join("\n"));
|
|
1295
1331
|
return result;
|
|
1296
1332
|
} catch (error) {
|
|
1333
|
+
if (isEngineBuildEndpointMissingError(error)) return await runWechatIdeEngineBuildByCli(projectPath, options);
|
|
1297
1334
|
logs.push(error instanceof Error ? error.message : String(error));
|
|
1298
1335
|
await writeEngineBuildLog(options.logPath, logs.join("\n"));
|
|
1299
1336
|
throw error;
|
|
@@ -1762,6 +1799,22 @@ async function runWechatCliWithRetry(cliPath, argv) {
|
|
|
1762
1799
|
function shouldBootstrapWechatDevtools(command) {
|
|
1763
1800
|
return command === "open" || command === "auto" || command === "auto-preview";
|
|
1764
1801
|
}
|
|
1802
|
+
function appendOptionValue(argv, sourceArgv, optionName) {
|
|
1803
|
+
const value = readOptionValue(sourceArgv, optionName);
|
|
1804
|
+
if (value !== void 0) argv.push(optionName, value);
|
|
1805
|
+
}
|
|
1806
|
+
function createAutoPreviewWakeArgv(argv, trustProject) {
|
|
1807
|
+
if (argv[0] !== "auto-preview") return;
|
|
1808
|
+
const projectPath = readOptionValue(argv, "--project");
|
|
1809
|
+
const appid = readOptionValue(argv, "--appid");
|
|
1810
|
+
if (!projectPath && !appid) return;
|
|
1811
|
+
const wakeArgv = ["open"];
|
|
1812
|
+
appendOptionValue(wakeArgv, argv, "--project");
|
|
1813
|
+
appendOptionValue(wakeArgv, argv, "--appid");
|
|
1814
|
+
appendOptionValue(wakeArgv, argv, "--ext-appid");
|
|
1815
|
+
if (trustProject === true) wakeArgv.push("--trust-project");
|
|
1816
|
+
return wakeArgv;
|
|
1817
|
+
}
|
|
1765
1818
|
function resolveBooleanCliOption(argv, optionName) {
|
|
1766
1819
|
if (argv.includes(optionName)) return true;
|
|
1767
1820
|
const rawValue = readOptionValue(argv, optionName);
|
|
@@ -1783,10 +1836,12 @@ async function maybeBootstrapWechatDevtoolsSettings(argv) {
|
|
|
1783
1836
|
if (config.autoBootstrapDevtools === false) return;
|
|
1784
1837
|
const projectPath = readOptionValue(argv, "--project");
|
|
1785
1838
|
const trustProjectOption = resolveBooleanCliOption(argv, "--trust-project");
|
|
1839
|
+
const trustProject = trustProjectOption === void 0 ? config.autoTrustProject ?? false : trustProjectOption;
|
|
1786
1840
|
await bootstrapWechatDevtoolsSettings({
|
|
1787
1841
|
projectPath,
|
|
1788
|
-
trustProject
|
|
1842
|
+
trustProject
|
|
1789
1843
|
});
|
|
1844
|
+
return { trustProject };
|
|
1790
1845
|
}
|
|
1791
1846
|
/**
|
|
1792
1847
|
* @description 执行微信开发者工具 CLI 阶段,包括环境检查、路径解析、bootstrap 与登录重试。
|
|
@@ -1801,7 +1856,8 @@ async function runWechatCliCommand(argv) {
|
|
|
1801
1856
|
await handleMissingCliPath(source);
|
|
1802
1857
|
return;
|
|
1803
1858
|
}
|
|
1804
|
-
await maybeBootstrapWechatDevtoolsSettings(argv);
|
|
1859
|
+
const wakeArgv = createAutoPreviewWakeArgv(argv, (await maybeBootstrapWechatDevtoolsSettings(argv))?.trustProject);
|
|
1860
|
+
if (wakeArgv) await runWechatCliWithRetry(cliPath, wakeArgv);
|
|
1805
1861
|
await runWechatCliWithRetry(cliPath, argv);
|
|
1806
1862
|
}
|
|
1807
1863
|
//#endregion
|
package/dist/cli.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Buffer } from "node:buffer";
|
|
2
2
|
import * as _$_weapp_vite_miniprogram_automator0 from "@weapp-vite/miniprogram-automator";
|
|
3
3
|
import { Element, MiniProgram, Page } from "@weapp-vite/miniprogram-automator";
|
|
4
|
-
import * as _$cac from "cac";
|
|
5
4
|
import * as _$execa from "execa";
|
|
5
|
+
import * as _$cac from "cac";
|
|
6
6
|
|
|
7
7
|
//#region src/cli/automator.d.ts
|
|
8
8
|
interface AutomatorOptions {
|
|
@@ -316,7 +316,7 @@ declare function runWechatIdeEngineBuildByHttp(projectPath: string, options?: Ru
|
|
|
316
316
|
/**
|
|
317
317
|
* @description 以更接近官方 CLI 的方式执行 engine build,并支持将构建日志写入文件。
|
|
318
318
|
*/
|
|
319
|
-
declare function runWechatIdeEngineBuild(projectPath: string, options?: RunWechatIdeEngineBuildOptions): Promise<PollWechatIdeEngineBuildResult>;
|
|
319
|
+
declare function runWechatIdeEngineBuild(projectPath: string, options?: RunWechatIdeEngineBuildOptions): Promise<void | PollWechatIdeEngineBuildResult>;
|
|
320
320
|
//#endregion
|
|
321
321
|
//#region src/cli/forwardConsole.d.ts
|
|
322
322
|
type ForwardConsoleLogLevel = 'debug' | 'log' | 'info' | 'warn' | 'error';
|
|
@@ -480,12 +480,12 @@ declare function runWechatCliWithRetry(cliPath: string, argv: string[]): Promise
|
|
|
480
480
|
//#endregion
|
|
481
481
|
//#region src/cli/run-login-executor.d.ts
|
|
482
482
|
interface RetryableCommandExecutorOptions<TResult, TPromptResult> {
|
|
483
|
-
createCancelError: (
|
|
483
|
+
createCancelError: (result: TResult) => Error;
|
|
484
484
|
execute: () => Promise<TResult>;
|
|
485
485
|
isRetryableResult: (result: TResult) => boolean;
|
|
486
|
-
onCancel?: (
|
|
486
|
+
onCancel?: (result: TResult) => void;
|
|
487
487
|
onRetry?: () => void;
|
|
488
|
-
promptRetry: (
|
|
488
|
+
promptRetry: (result: TResult, retryCount: number) => Promise<TPromptResult>;
|
|
489
489
|
shouldRetry: (result: TPromptResult) => boolean;
|
|
490
490
|
}
|
|
491
491
|
/**
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { $ as readCustomConfig, A as isAutomatorProtocolTimeoutError, B as getConfiguredLocale, D as formatAutomatorLoginError, E as connectOpenedAutomator, F as launchAutomator, G as operatingSystemName, H as SupportedPlatformsMap, I as bootstrapWechatDevtoolsSettings, J as createAutoBootstrapDevtoolsConfig, L as detectWechatDevtoolsServicePort, M as isDevtoolsExtensionContextInvalidatedError, N as isDevtoolsHttpPortError, O as getAutomatorProtocolTimeoutMethod, P as isRetryableAutomatorLaunchError, Q as overwriteCustomConfig, R as resolveCliPath, S as withMiniProgram, U as getDefaultCliPath, V as resolveDevtoolsAutomationDefaults, W as isOperatingSystemSupported, X as createCustomConfig, Y as createAutoTrustProjectConfig, Z as createLocaleConfig, _ as acquireSharedMiniProgram, a as navigateBack, b as getSharedMiniProgramSessionCount, c as pageStack, d as remote, et as removeCustomConfigKey, f as scrollTo, g as tap, h as takeScreenshot, i as input, j as isAutomatorWsConnectError, k as isAutomatorLoginError, l as reLaunch, m as systemInfo, n as captureScreenshotBuffer, nt as defaultCustomConfigFilePath, o as navigateTo, p as switchTab, r as currentPage, rt as resolvePath, s as pageData, t as audit, tt as defaultCustomConfigDirPath, u as redirectTo, v as closeSharedMiniProgram, x as releaseSharedMiniProgram, y as connectMiniProgram, z as getConfig } from "./commands-XD_wemcg.js";
|
|
2
|
-
import { $ as resetWechatIdeFileUtilsByHttp, A as RETRY_CANCEL_KEYS, B as waitForRetryKeypress, C as refreshWechatIdeTicket, D as validateWechatCliCommandArgs, E as uploadWechatIde, F as formatRetryHotkeyPrompt, G as transformArgv, H as execute, I as formatWechatIdeLoginRequiredError, J as runWechatIdeEngineBuildByHttp, K as startForwardConsole, L as isWechatIdeLoginRequiredError, M as RETRY_PROMPT_INITIAL_IGNORE_MS, N as createWechatIdeLoginRequiredExitError, O as runWechatCliWithRetry, P as extractExecutionErrorText, Q as requestWechatDevtoolsHttp, R as promptRetryKeypress, S as quitWechatIde, St as removeOption, T as setWechatIdeTicket, U as createAlias, V as runMinidev, W as createPathCompat, X as openWechatIdeProjectByHttp, Y as WECHAT_DEVTOOLS_ENGINE_BUILD_STATUSES, Z as pollWechatIdeEngineBuildResultByHttp, _ as isWechatIdeLoggedIn, _t as parseCompareArgs, a as autoReplayWechatIde, at as waitForExclusiveKeypress, b as openWechatIdeOtherProject, bt as readBooleanOption, c as buildWechatIdeIpa, ct as WEAPP_IDE_TOP_LEVEL_COMMAND_NAMES, d as clearWechatIdeCacheByAutomator, dt as AUTOMATOR_COMMAND_NAMES, et as startWechatIdeEngineBuildByHttp, f as closeWechatIdeProject, ft as getAutomatorCommandHelp, g as getWechatIdeToolInfo, gt as printScreenshotHelp, h as getWechatIdeTicket, ht as parseScreenshotArgs, i as autoPreviewWechatIde, it as runWithSuspendedSharedInput, j as RETRY_CONFIRM_KEYS, k as runRetryableCommand, l as buildWechatIdeNpm, lt as WECHAT_CLI_COMMAND_NAMES, m as getWechatIdeTestAccounts, mt as runAutomatorCommand, n as parse, nt as promptForCliPath, o as autoWechatIde, ot as CONFIG_COMMAND_NAME, p as compileWechatIdeByAutomator, pt as isAutomatorCommand, q as runWechatIdeEngineBuild, r as dispatchWechatCliCommand, rt as createSharedInputSession, s as buildWechatIdeApk, st as MINIDEV_NAMESPACE_COMMAND_NAMES, t as createCli, tt as handleConfigCommand, u as clearWechatIdeCache, ut as isWeappIdeTopLevelCommand, v as loginWechatIde, vt as printCompareHelp, w as resetWechatIdeFileUtils, x as previewWechatIde, xt as readOptionValue, y as openWechatIde, yt as parseAutomatorArgs, z as promptWechatIdeLoginRetry } from "./cli-
|
|
2
|
+
import { $ as resetWechatIdeFileUtilsByHttp, A as RETRY_CANCEL_KEYS, B as waitForRetryKeypress, C as refreshWechatIdeTicket, D as validateWechatCliCommandArgs, E as uploadWechatIde, F as formatRetryHotkeyPrompt, G as transformArgv, H as execute, I as formatWechatIdeLoginRequiredError, J as runWechatIdeEngineBuildByHttp, K as startForwardConsole, L as isWechatIdeLoginRequiredError, M as RETRY_PROMPT_INITIAL_IGNORE_MS, N as createWechatIdeLoginRequiredExitError, O as runWechatCliWithRetry, P as extractExecutionErrorText, Q as requestWechatDevtoolsHttp, R as promptRetryKeypress, S as quitWechatIde, St as removeOption, T as setWechatIdeTicket, U as createAlias, V as runMinidev, W as createPathCompat, X as openWechatIdeProjectByHttp, Y as WECHAT_DEVTOOLS_ENGINE_BUILD_STATUSES, Z as pollWechatIdeEngineBuildResultByHttp, _ as isWechatIdeLoggedIn, _t as parseCompareArgs, a as autoReplayWechatIde, at as waitForExclusiveKeypress, b as openWechatIdeOtherProject, bt as readBooleanOption, c as buildWechatIdeIpa, ct as WEAPP_IDE_TOP_LEVEL_COMMAND_NAMES, d as clearWechatIdeCacheByAutomator, dt as AUTOMATOR_COMMAND_NAMES, et as startWechatIdeEngineBuildByHttp, f as closeWechatIdeProject, ft as getAutomatorCommandHelp, g as getWechatIdeToolInfo, gt as printScreenshotHelp, h as getWechatIdeTicket, ht as parseScreenshotArgs, i as autoPreviewWechatIde, it as runWithSuspendedSharedInput, j as RETRY_CONFIRM_KEYS, k as runRetryableCommand, l as buildWechatIdeNpm, lt as WECHAT_CLI_COMMAND_NAMES, m as getWechatIdeTestAccounts, mt as runAutomatorCommand, n as parse, nt as promptForCliPath, o as autoWechatIde, ot as CONFIG_COMMAND_NAME, p as compileWechatIdeByAutomator, pt as isAutomatorCommand, q as runWechatIdeEngineBuild, r as dispatchWechatCliCommand, rt as createSharedInputSession, s as buildWechatIdeApk, st as MINIDEV_NAMESPACE_COMMAND_NAMES, t as createCli, tt as handleConfigCommand, u as clearWechatIdeCache, ut as isWeappIdeTopLevelCommand, v as loginWechatIde, vt as printCompareHelp, w as resetWechatIdeFileUtils, x as previewWechatIde, xt as readOptionValue, y as openWechatIde, yt as parseAutomatorArgs, z as promptWechatIdeLoginRetry } from "./cli-lB9HDuk-.js";
|
|
3
3
|
export { AUTOMATOR_COMMAND_NAMES, CONFIG_COMMAND_NAME, MINIDEV_NAMESPACE_COMMAND_NAMES, RETRY_CANCEL_KEYS, RETRY_CONFIRM_KEYS, RETRY_PROMPT_INITIAL_IGNORE_MS, SupportedPlatformsMap, WEAPP_IDE_TOP_LEVEL_COMMAND_NAMES, WECHAT_CLI_COMMAND_NAMES, WECHAT_DEVTOOLS_ENGINE_BUILD_STATUSES, acquireSharedMiniProgram, audit, autoPreviewWechatIde, autoReplayWechatIde, autoWechatIde, bootstrapWechatDevtoolsSettings, buildWechatIdeApk, buildWechatIdeIpa, buildWechatIdeNpm, captureScreenshotBuffer, clearWechatIdeCache, clearWechatIdeCacheByAutomator, closeSharedMiniProgram, closeWechatIdeProject, compileWechatIdeByAutomator, connectMiniProgram, connectOpenedAutomator, createAlias, createAutoBootstrapDevtoolsConfig, createAutoTrustProjectConfig, createCli, createCustomConfig, createLocaleConfig, createPathCompat, createSharedInputSession, createWechatIdeLoginRequiredExitError, currentPage, defaultCustomConfigDirPath, defaultCustomConfigFilePath, detectWechatDevtoolsServicePort, dispatchWechatCliCommand, execute, extractExecutionErrorText, formatAutomatorLoginError, formatRetryHotkeyPrompt, formatWechatIdeLoginRequiredError, getAutomatorCommandHelp, getAutomatorProtocolTimeoutMethod, getConfig, getConfiguredLocale, getDefaultCliPath, getSharedMiniProgramSessionCount, getWechatIdeTestAccounts, getWechatIdeTicket, getWechatIdeToolInfo, handleConfigCommand, input, isAutomatorCommand, isAutomatorLoginError, isAutomatorProtocolTimeoutError, isAutomatorWsConnectError, isDevtoolsExtensionContextInvalidatedError, isDevtoolsHttpPortError, isOperatingSystemSupported, isRetryableAutomatorLaunchError, isWeappIdeTopLevelCommand, isWechatIdeLoggedIn, isWechatIdeLoginRequiredError, launchAutomator, loginWechatIde, navigateBack, navigateTo, openWechatIde, openWechatIdeOtherProject, openWechatIdeProjectByHttp, operatingSystemName, overwriteCustomConfig, pageData, pageStack, parse, parseAutomatorArgs, parseCompareArgs, parseScreenshotArgs, pollWechatIdeEngineBuildResultByHttp, previewWechatIde, printCompareHelp, printScreenshotHelp, promptForCliPath, promptRetryKeypress, promptWechatIdeLoginRetry, quitWechatIde, reLaunch, readBooleanOption, readCustomConfig, readOptionValue, redirectTo, refreshWechatIdeTicket, releaseSharedMiniProgram, remote, removeCustomConfigKey, removeOption, requestWechatDevtoolsHttp, resetWechatIdeFileUtils, resetWechatIdeFileUtilsByHttp, resolveCliPath, resolveDevtoolsAutomationDefaults, resolvePath, runAutomatorCommand, runMinidev, runRetryableCommand, runWechatCliWithRetry, runWechatIdeEngineBuild, runWechatIdeEngineBuildByHttp, runWithSuspendedSharedInput, scrollTo, setWechatIdeTicket, startForwardConsole, startWechatIdeEngineBuildByHttp, switchTab, systemInfo, takeScreenshot, tap, transformArgv, uploadWechatIde, validateWechatCliCommandArgs, waitForExclusiveKeypress, waitForRetryKeypress, withMiniProgram };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "weapp-ide-cli",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "5.2.
|
|
4
|
+
"version": "5.2.6",
|
|
5
5
|
"description": "让微信开发者工具,用起来更加方便!",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -67,9 +67,9 @@
|
|
|
67
67
|
"pathe": "^2.0.3",
|
|
68
68
|
"pixelmatch": "^7.1.0",
|
|
69
69
|
"pngjs": "^7.0.0",
|
|
70
|
+
"@weapp-core/logger": "^3.1.1",
|
|
70
71
|
"@weapp-core/shared": "^3.0.4",
|
|
71
|
-
"@weapp-vite/miniprogram-automator": "1.0.4"
|
|
72
|
-
"@weapp-core/logger": "^3.1.1"
|
|
72
|
+
"@weapp-vite/miniprogram-automator": "1.0.4"
|
|
73
73
|
},
|
|
74
74
|
"scripts": {
|
|
75
75
|
"dev": "tsdown -w --sourcemap",
|