weapp-ide-cli 5.0.3 → 5.1.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/index.d.ts CHANGED
@@ -1,5 +1,151 @@
1
+ import * as miniprogram_automator_out_MiniProgram from 'miniprogram-automator/out/MiniProgram';
2
+ import { Buffer } from 'node:buffer';
1
3
  import * as execa from 'execa';
2
4
 
5
+ interface AutomatorOptions {
6
+ projectPath: string;
7
+ timeout?: number;
8
+ }
9
+ /**
10
+ * @description Check if error is a DevTools HTTP port error
11
+ */
12
+ declare function isDevtoolsHttpPortError(error: unknown): boolean;
13
+ /**
14
+ * @description Check if error is a login required error
15
+ */
16
+ declare function isAutomatorLoginError(error: unknown): boolean;
17
+ /**
18
+ * @description Format login error for display
19
+ */
20
+ declare function formatAutomatorLoginError(error: unknown): string;
21
+ /**
22
+ * @description Launch automator with default options
23
+ */
24
+ declare function launchAutomator(options: AutomatorOptions): Promise<miniprogram_automator_out_MiniProgram.default>;
25
+
26
+ interface ParsedAutomatorArgs {
27
+ projectPath: string;
28
+ timeout?: number;
29
+ json: boolean;
30
+ positionals: string[];
31
+ }
32
+ /**
33
+ * @description 解析 automator 命令通用参数与位置参数。
34
+ */
35
+ declare function parseAutomatorArgs(argv: readonly string[]): ParsedAutomatorArgs;
36
+ /**
37
+ * @description 读取选项值,支持 --option value 与 --option=value。
38
+ */
39
+ declare function readOptionValue(argv: readonly string[], optionName: string): string | undefined;
40
+ /**
41
+ * @description 删除参数中的指定选项(同时支持 --opt value 与 --opt=value)。
42
+ */
43
+ declare function removeOption(argv: readonly string[], optionName: string): string[];
44
+
45
+ interface AutomatorSessionOptions {
46
+ projectPath: string;
47
+ timeout?: number;
48
+ }
49
+ interface MiniProgramElement {
50
+ tap: () => Promise<void>;
51
+ input?: (value: string) => Promise<void>;
52
+ }
53
+ interface MiniProgramPage {
54
+ path?: string;
55
+ query?: Record<string, unknown>;
56
+ data: (path?: string) => Promise<unknown>;
57
+ $: (selector: string) => Promise<MiniProgramElement | null>;
58
+ }
59
+ interface MiniProgramLike {
60
+ navigateTo: (url: string) => Promise<unknown>;
61
+ redirectTo: (url: string) => Promise<unknown>;
62
+ navigateBack: () => Promise<unknown>;
63
+ reLaunch: (url: string) => Promise<unknown>;
64
+ switchTab: (url: string) => Promise<unknown>;
65
+ pageStack: () => Promise<MiniProgramPage[]>;
66
+ currentPage: () => Promise<MiniProgramPage>;
67
+ systemInfo: () => Promise<unknown>;
68
+ pageScrollTo: (scrollTop: number) => Promise<unknown>;
69
+ stopAudits: () => Promise<unknown>;
70
+ screenshot: () => Promise<string | Buffer>;
71
+ remote: (enable?: boolean) => Promise<unknown>;
72
+ close: () => Promise<void>;
73
+ }
74
+ /**
75
+ * @description 统一管理 automator 会话生命周期与常见连接错误提示。
76
+ */
77
+ declare function withMiniProgram<T>(options: AutomatorSessionOptions, runner: (miniProgram: MiniProgramLike) => Promise<T>): Promise<T>;
78
+
79
+ declare const WECHAT_CLI_COMMAND_NAMES: readonly ["open", "login", "islogin", "preview", "auto-preview", "upload", "build-npm", "auto", "auto-replay", "reset-fileutils", "close", "quit", "cache", "engine", "open-other", "build-ipa", "build-apk", "cloud"];
80
+ declare const MINIDEV_NAMESPACE_COMMAND_NAMES: readonly ["alipay", "ali", "minidev"];
81
+ declare const CONFIG_COMMAND_NAME: "config";
82
+ declare const WEAPP_IDE_TOP_LEVEL_COMMAND_NAMES: string[];
83
+ /**
84
+ * @description 判断是否为 weapp-ide-cli 支持的顶层命令。
85
+ */
86
+ declare function isWeappIdeTopLevelCommand(command: string | undefined): boolean;
87
+
88
+ interface AutomatorCommandOptions extends AutomatorSessionOptions {
89
+ }
90
+ interface NavigateOptions extends AutomatorCommandOptions {
91
+ url: string;
92
+ }
93
+ interface PageInfoOptions extends AutomatorCommandOptions {
94
+ json?: boolean;
95
+ }
96
+ interface PageDataOptions extends PageInfoOptions {
97
+ path?: string;
98
+ }
99
+ interface SelectorOptions extends AutomatorCommandOptions {
100
+ selector: string;
101
+ }
102
+ interface TapOptions extends SelectorOptions {
103
+ }
104
+ interface InputOptions extends SelectorOptions {
105
+ value: string;
106
+ }
107
+ interface ScrollOptions extends AutomatorCommandOptions {
108
+ scrollTop: number;
109
+ }
110
+ interface AuditOptions extends AutomatorCommandOptions {
111
+ outputPath?: string;
112
+ }
113
+ interface ScreenshotOptions extends AutomatorCommandOptions {
114
+ outputPath?: string;
115
+ page?: string;
116
+ }
117
+ interface ScreenshotResult {
118
+ base64?: string;
119
+ path?: string;
120
+ }
121
+ interface RemoteOptions extends AutomatorCommandOptions {
122
+ enable?: boolean;
123
+ }
124
+ interface PageSnapshot {
125
+ path: string;
126
+ query: Record<string, unknown> | undefined;
127
+ }
128
+ declare function navigateTo(options: NavigateOptions): Promise<void>;
129
+ declare function redirectTo(options: NavigateOptions): Promise<void>;
130
+ declare function navigateBack(options: AutomatorCommandOptions): Promise<void>;
131
+ declare function reLaunch(options: NavigateOptions): Promise<void>;
132
+ declare function switchTab(options: NavigateOptions): Promise<void>;
133
+ declare function pageStack(options: PageInfoOptions): Promise<PageSnapshot[]>;
134
+ declare function currentPage(options: PageInfoOptions): Promise<PageSnapshot>;
135
+ declare function systemInfo(options: PageInfoOptions): Promise<unknown>;
136
+ declare function pageData(options: PageDataOptions): Promise<unknown>;
137
+ declare function tap(options: TapOptions): Promise<void>;
138
+ declare function input(options: InputOptions): Promise<void>;
139
+ declare function scrollTo(options: ScrollOptions): Promise<void>;
140
+ declare function audit(options: AuditOptions): Promise<unknown>;
141
+ declare function takeScreenshot(options: ScreenshotOptions): Promise<ScreenshotResult>;
142
+ declare function remote(options: RemoteOptions): Promise<void>;
143
+
144
+ /**
145
+ * @description 处理 config 子命令。
146
+ */
147
+ declare function handleConfigCommand(argv: string[]): Promise<void>;
148
+
3
149
  /**
4
150
  * @description 运行支付宝小程序 CLI(minidev)
5
151
  */
@@ -18,6 +164,10 @@ declare function resolveCliPath(): Promise<{
18
164
  source: ConfigSource;
19
165
  }>;
20
166
 
167
+ interface RetryKeypressOptions {
168
+ timeoutMs?: number;
169
+ }
170
+ type RetryPromptResult = 'retry' | 'cancel' | 'timeout';
21
171
  /**
22
172
  * @description 判断是否为微信开发者工具登录失效错误。
23
173
  */
@@ -30,25 +180,67 @@ declare function extractExecutionErrorText(error: unknown): string;
30
180
  * @description 将登录失效错误格式化为更易读的摘要。
31
181
  */
32
182
  declare function formatWechatIdeLoginRequiredError(error: unknown): string;
183
+ /**
184
+ * @description 创建登录失效专用错误,并携带退出码语义。
185
+ */
186
+ declare function createWechatIdeLoginRequiredExitError(error: unknown, reason?: string): Error & {
187
+ code: number;
188
+ exitCode: number;
189
+ };
33
190
  /**
34
191
  * @description 交互等待用户按键重试,按 r 重试,按 q 或 Ctrl+C 取消。
35
192
  */
36
- declare function waitForRetryKeypress(): Promise<boolean>;
193
+ declare function waitForRetryKeypress(options?: RetryKeypressOptions): Promise<RetryPromptResult>;
37
194
  /**
38
195
  * @description 生成重试按键提示,并高亮关键热键。
39
196
  */
40
- declare function formatRetryHotkeyPrompt(): string;
197
+ declare function formatRetryHotkeyPrompt(timeoutMs?: number): string;
41
198
 
42
199
  /**
43
- * @description CLI 入口解析与分发
200
+ * @description CLI 入口解析与分发。
44
201
  */
45
202
  declare function parse(argv: string[]): Promise<void>;
46
203
 
204
+ declare const AUTOMATOR_COMMAND_NAMES: string[];
205
+ /**
206
+ * @description 判断是否属于 automator 子命令。
207
+ */
208
+ declare function isAutomatorCommand(command: string | undefined): boolean;
209
+ /**
210
+ * @description 分发 automator 子命令。
211
+ */
212
+ declare function runAutomatorCommand(command: string, argv: string[]): Promise<void>;
213
+ /**
214
+ * @description 获取 automator 命令帮助文本。
215
+ */
216
+ declare function getAutomatorCommandHelp(command: string): string | undefined;
217
+
218
+ type LoginRetryMode = 'never' | 'once' | 'always';
219
+ /**
220
+ * @description 运行微信开发者工具 CLI,并在登录失效时允许按键重试。
221
+ */
222
+ declare function runWechatCliWithRetry(cliPath: string, argv: string[]): Promise<void>;
223
+
224
+ /**
225
+ * @description Print help for screenshot command
226
+ */
227
+ declare function printScreenshotHelp(): void;
228
+ /**
229
+ * @description Parse command line arguments for screenshot command
230
+ */
231
+ declare function parseScreenshotArgs(argv: string[]): ScreenshotOptions;
232
+
233
+ /**
234
+ * @description 在调用官方微信 CLI 前做轻量参数校验。
235
+ */
236
+ declare function validateWechatCliCommandArgs(argv: readonly string[]): void;
237
+
47
238
  /**
48
239
  * @description 基础配置
49
240
  */
50
241
  interface BaseConfig {
51
242
  cliPath: string;
243
+ locale?: 'zh' | 'en';
52
244
  }
53
245
  /**
54
246
  * @description 配置来源
@@ -68,10 +260,30 @@ interface AliasEntry {
68
260
  replacement: string;
69
261
  }
70
262
 
263
+ interface CustomConfigFile {
264
+ cliPath?: string;
265
+ locale?: 'zh' | 'en';
266
+ }
71
267
  /**
72
268
  * @description 写入自定义 CLI 路径配置
73
269
  */
74
270
  declare function createCustomConfig(params: BaseConfig): Promise<string>;
271
+ /**
272
+ * @description 写入语言配置(zh / en)。
273
+ */
274
+ declare function createLocaleConfig(locale: 'zh' | 'en'): Promise<"zh" | "en">;
275
+ /**
276
+ * @description 删除指定配置项。
277
+ */
278
+ declare function removeCustomConfigKey(key: keyof CustomConfigFile): Promise<void>;
279
+ /**
280
+ * @description 覆盖写入配置内容(会替换原内容)。
281
+ */
282
+ declare function overwriteCustomConfig(config: CustomConfigFile): Promise<void>;
283
+ /**
284
+ * @description 读取原始自定义配置。
285
+ */
286
+ declare function readCustomConfig(): Promise<CustomConfigFile>;
75
287
 
76
288
  /**
77
289
  * @description 默认自定义配置目录
@@ -86,6 +298,10 @@ declare const defaultCustomConfigFilePath: string;
86
298
  * @description 读取并解析 CLI 配置(自定义优先)
87
299
  */
88
300
  declare function getConfig(): Promise<ResolvedConfig>;
301
+ /**
302
+ * @description 获取用户配置的语言偏好。
303
+ */
304
+ declare function getConfiguredLocale(): Promise<"zh" | "en" | undefined>;
89
305
 
90
306
  /**
91
307
  * @description 官方微信开发者工具只支持 Windows、macOS,Linux 只有社区版
@@ -144,4 +360,4 @@ declare function execute(cliPath: string, argv: string[], options?: ExecuteOptio
144
360
  */
145
361
  declare function resolvePath(filePath: string): string;
146
362
 
147
- export { type ArgvTransform, type BaseConfig, type ConfigSource, type ResolvedConfig, type SupportedPlatform, SupportedPlatformsMap, createAlias, createCustomConfig, createPathCompat, defaultCustomConfigDirPath, defaultCustomConfigFilePath, execute, extractExecutionErrorText, formatRetryHotkeyPrompt, formatWechatIdeLoginRequiredError, getConfig, getDefaultCliPath, isOperatingSystemSupported, isWechatIdeLoginRequiredError, operatingSystemName, parse, promptForCliPath, resolveCliPath, resolvePath, runMinidev, transformArgv, waitForRetryKeypress };
363
+ export { AUTOMATOR_COMMAND_NAMES, type ArgvTransform, type AuditOptions, type AutomatorCommandOptions, type AutomatorOptions, type AutomatorSessionOptions, type BaseConfig, CONFIG_COMMAND_NAME, type ConfigSource, type InputOptions, type LoginRetryMode, MINIDEV_NAMESPACE_COMMAND_NAMES, type MiniProgramElement, type MiniProgramLike, type MiniProgramPage, type NavigateOptions, type PageDataOptions, type PageInfoOptions, type ParsedAutomatorArgs, type RemoteOptions, type ResolvedConfig, type RetryKeypressOptions, type RetryPromptResult, type ScreenshotOptions, type ScreenshotResult, type ScrollOptions, type SelectorOptions, type SupportedPlatform, SupportedPlatformsMap, type TapOptions, WEAPP_IDE_TOP_LEVEL_COMMAND_NAMES, WECHAT_CLI_COMMAND_NAMES, audit, createAlias, createCustomConfig, createLocaleConfig, createPathCompat, createWechatIdeLoginRequiredExitError, currentPage, defaultCustomConfigDirPath, defaultCustomConfigFilePath, execute, extractExecutionErrorText, formatAutomatorLoginError, formatRetryHotkeyPrompt, formatWechatIdeLoginRequiredError, getAutomatorCommandHelp, getConfig, getConfiguredLocale, getDefaultCliPath, handleConfigCommand, input, isAutomatorCommand, isAutomatorLoginError, isDevtoolsHttpPortError, isOperatingSystemSupported, isWeappIdeTopLevelCommand, isWechatIdeLoginRequiredError, launchAutomator, navigateBack, navigateTo, operatingSystemName, overwriteCustomConfig, pageData, pageStack, parse, parseAutomatorArgs, parseScreenshotArgs, printScreenshotHelp, promptForCliPath, reLaunch, readCustomConfig, readOptionValue, redirectTo, remote, removeCustomConfigKey, removeOption, resolveCliPath, resolvePath, runAutomatorCommand, runMinidev, runWechatCliWithRetry, scrollTo, switchTab, systemInfo, takeScreenshot, tap, transformArgv, validateWechatCliCommandArgs, waitForRetryKeypress, withMiniProgram };
package/dist/index.js CHANGED
@@ -1,48 +1,136 @@
1
1
  import {
2
+ AUTOMATOR_COMMAND_NAMES,
3
+ CONFIG_COMMAND_NAME,
4
+ MINIDEV_NAMESPACE_COMMAND_NAMES,
2
5
  SupportedPlatformsMap,
6
+ WEAPP_IDE_TOP_LEVEL_COMMAND_NAMES,
7
+ WECHAT_CLI_COMMAND_NAMES,
3
8
  createAlias,
4
9
  createCustomConfig,
10
+ createLocaleConfig,
5
11
  createPathCompat,
12
+ createWechatIdeLoginRequiredExitError,
6
13
  defaultCustomConfigDirPath,
7
14
  defaultCustomConfigFilePath,
8
15
  execute,
9
16
  extractExecutionErrorText,
10
17
  formatRetryHotkeyPrompt,
11
18
  formatWechatIdeLoginRequiredError,
19
+ getAutomatorCommandHelp,
12
20
  getConfig,
21
+ getConfiguredLocale,
13
22
  getDefaultCliPath,
23
+ handleConfigCommand,
24
+ isAutomatorCommand,
14
25
  isOperatingSystemSupported,
26
+ isWeappIdeTopLevelCommand,
15
27
  isWechatIdeLoginRequiredError,
16
28
  operatingSystemName,
29
+ overwriteCustomConfig,
17
30
  parse,
31
+ parseAutomatorArgs,
32
+ parseScreenshotArgs,
33
+ printScreenshotHelp,
18
34
  promptForCliPath,
35
+ readCustomConfig,
36
+ readOptionValue,
37
+ removeCustomConfigKey,
38
+ removeOption,
19
39
  resolveCliPath,
20
40
  resolvePath,
41
+ runAutomatorCommand,
21
42
  runMinidev,
43
+ runWechatCliWithRetry,
22
44
  transformArgv,
45
+ validateWechatCliCommandArgs,
23
46
  waitForRetryKeypress
24
- } from "./chunk-A26E3I4U.js";
47
+ } from "./chunk-C2MXNGAM.js";
48
+ import {
49
+ audit,
50
+ currentPage,
51
+ formatAutomatorLoginError,
52
+ input,
53
+ isAutomatorLoginError,
54
+ isDevtoolsHttpPortError,
55
+ launchAutomator,
56
+ navigateBack,
57
+ navigateTo,
58
+ pageData,
59
+ pageStack,
60
+ reLaunch,
61
+ redirectTo,
62
+ remote,
63
+ scrollTo,
64
+ switchTab,
65
+ systemInfo,
66
+ takeScreenshot,
67
+ tap,
68
+ withMiniProgram
69
+ } from "./chunk-NSYCXXXT.js";
25
70
  export {
71
+ AUTOMATOR_COMMAND_NAMES,
72
+ CONFIG_COMMAND_NAME,
73
+ MINIDEV_NAMESPACE_COMMAND_NAMES,
26
74
  SupportedPlatformsMap,
75
+ WEAPP_IDE_TOP_LEVEL_COMMAND_NAMES,
76
+ WECHAT_CLI_COMMAND_NAMES,
77
+ audit,
27
78
  createAlias,
28
79
  createCustomConfig,
80
+ createLocaleConfig,
29
81
  createPathCompat,
82
+ createWechatIdeLoginRequiredExitError,
83
+ currentPage,
30
84
  defaultCustomConfigDirPath,
31
85
  defaultCustomConfigFilePath,
32
86
  execute,
33
87
  extractExecutionErrorText,
88
+ formatAutomatorLoginError,
34
89
  formatRetryHotkeyPrompt,
35
90
  formatWechatIdeLoginRequiredError,
91
+ getAutomatorCommandHelp,
36
92
  getConfig,
93
+ getConfiguredLocale,
37
94
  getDefaultCliPath,
95
+ handleConfigCommand,
96
+ input,
97
+ isAutomatorCommand,
98
+ isAutomatorLoginError,
99
+ isDevtoolsHttpPortError,
38
100
  isOperatingSystemSupported,
101
+ isWeappIdeTopLevelCommand,
39
102
  isWechatIdeLoginRequiredError,
103
+ launchAutomator,
104
+ navigateBack,
105
+ navigateTo,
40
106
  operatingSystemName,
107
+ overwriteCustomConfig,
108
+ pageData,
109
+ pageStack,
41
110
  parse,
111
+ parseAutomatorArgs,
112
+ parseScreenshotArgs,
113
+ printScreenshotHelp,
42
114
  promptForCliPath,
115
+ reLaunch,
116
+ readCustomConfig,
117
+ readOptionValue,
118
+ redirectTo,
119
+ remote,
120
+ removeCustomConfigKey,
121
+ removeOption,
43
122
  resolveCliPath,
44
123
  resolvePath,
124
+ runAutomatorCommand,
45
125
  runMinidev,
126
+ runWechatCliWithRetry,
127
+ scrollTo,
128
+ switchTab,
129
+ systemInfo,
130
+ takeScreenshot,
131
+ tap,
46
132
  transformArgv,
47
- waitForRetryKeypress
133
+ validateWechatCliCommandArgs,
134
+ waitForRetryKeypress,
135
+ withMiniProgram
48
136
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "weapp-ide-cli",
3
3
  "type": "module",
4
- "version": "5.0.3",
4
+ "version": "5.1.0",
5
5
  "description": "让微信开发者工具,用起来更加方便!",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",
@@ -64,6 +64,7 @@
64
64
  "dependencies": {
65
65
  "execa": "9.6.1",
66
66
  "fs-extra": "^11.3.3",
67
+ "miniprogram-automator": "^0.12.1",
67
68
  "pathe": "^2.0.3",
68
69
  "@weapp-core/logger": "^3.1.0"
69
70
  },