weapp-ide-cli 5.0.4 → 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
  */
@@ -51,15 +197,50 @@ declare function waitForRetryKeypress(options?: RetryKeypressOptions): Promise<R
51
197
  declare function formatRetryHotkeyPrompt(timeoutMs?: number): string;
52
198
 
53
199
  /**
54
- * @description CLI 入口解析与分发
200
+ * @description CLI 入口解析与分发。
55
201
  */
56
202
  declare function parse(argv: string[]): Promise<void>;
57
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
+
58
238
  /**
59
239
  * @description 基础配置
60
240
  */
61
241
  interface BaseConfig {
62
242
  cliPath: string;
243
+ locale?: 'zh' | 'en';
63
244
  }
64
245
  /**
65
246
  * @description 配置来源
@@ -79,10 +260,30 @@ interface AliasEntry {
79
260
  replacement: string;
80
261
  }
81
262
 
263
+ interface CustomConfigFile {
264
+ cliPath?: string;
265
+ locale?: 'zh' | 'en';
266
+ }
82
267
  /**
83
268
  * @description 写入自定义 CLI 路径配置
84
269
  */
85
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>;
86
287
 
87
288
  /**
88
289
  * @description 默认自定义配置目录
@@ -97,6 +298,10 @@ declare const defaultCustomConfigFilePath: string;
97
298
  * @description 读取并解析 CLI 配置(自定义优先)
98
299
  */
99
300
  declare function getConfig(): Promise<ResolvedConfig>;
301
+ /**
302
+ * @description 获取用户配置的语言偏好。
303
+ */
304
+ declare function getConfiguredLocale(): Promise<"zh" | "en" | undefined>;
100
305
 
101
306
  /**
102
307
  * @description 官方微信开发者工具只支持 Windows、macOS,Linux 只有社区版
@@ -155,4 +360,4 @@ declare function execute(cliPath: string, argv: string[], options?: ExecuteOptio
155
360
  */
156
361
  declare function resolvePath(filePath: string): string;
157
362
 
158
- export { type ArgvTransform, type BaseConfig, type ConfigSource, type ResolvedConfig, type RetryKeypressOptions, type RetryPromptResult, type SupportedPlatform, SupportedPlatformsMap, createAlias, createCustomConfig, createPathCompat, createWechatIdeLoginRequiredExitError, 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,7 +1,13 @@
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,
6
12
  createWechatIdeLoginRequiredExitError,
7
13
  defaultCustomConfigDirPath,
@@ -10,41 +16,121 @@ import {
10
16
  extractExecutionErrorText,
11
17
  formatRetryHotkeyPrompt,
12
18
  formatWechatIdeLoginRequiredError,
19
+ getAutomatorCommandHelp,
13
20
  getConfig,
21
+ getConfiguredLocale,
14
22
  getDefaultCliPath,
23
+ handleConfigCommand,
24
+ isAutomatorCommand,
15
25
  isOperatingSystemSupported,
26
+ isWeappIdeTopLevelCommand,
16
27
  isWechatIdeLoginRequiredError,
17
28
  operatingSystemName,
29
+ overwriteCustomConfig,
18
30
  parse,
31
+ parseAutomatorArgs,
32
+ parseScreenshotArgs,
33
+ printScreenshotHelp,
19
34
  promptForCliPath,
35
+ readCustomConfig,
36
+ readOptionValue,
37
+ removeCustomConfigKey,
38
+ removeOption,
20
39
  resolveCliPath,
21
40
  resolvePath,
41
+ runAutomatorCommand,
22
42
  runMinidev,
43
+ runWechatCliWithRetry,
23
44
  transformArgv,
45
+ validateWechatCliCommandArgs,
24
46
  waitForRetryKeypress
25
- } from "./chunk-QTQD5BFV.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";
26
70
  export {
71
+ AUTOMATOR_COMMAND_NAMES,
72
+ CONFIG_COMMAND_NAME,
73
+ MINIDEV_NAMESPACE_COMMAND_NAMES,
27
74
  SupportedPlatformsMap,
75
+ WEAPP_IDE_TOP_LEVEL_COMMAND_NAMES,
76
+ WECHAT_CLI_COMMAND_NAMES,
77
+ audit,
28
78
  createAlias,
29
79
  createCustomConfig,
80
+ createLocaleConfig,
30
81
  createPathCompat,
31
82
  createWechatIdeLoginRequiredExitError,
83
+ currentPage,
32
84
  defaultCustomConfigDirPath,
33
85
  defaultCustomConfigFilePath,
34
86
  execute,
35
87
  extractExecutionErrorText,
88
+ formatAutomatorLoginError,
36
89
  formatRetryHotkeyPrompt,
37
90
  formatWechatIdeLoginRequiredError,
91
+ getAutomatorCommandHelp,
38
92
  getConfig,
93
+ getConfiguredLocale,
39
94
  getDefaultCliPath,
95
+ handleConfigCommand,
96
+ input,
97
+ isAutomatorCommand,
98
+ isAutomatorLoginError,
99
+ isDevtoolsHttpPortError,
40
100
  isOperatingSystemSupported,
101
+ isWeappIdeTopLevelCommand,
41
102
  isWechatIdeLoginRequiredError,
103
+ launchAutomator,
104
+ navigateBack,
105
+ navigateTo,
42
106
  operatingSystemName,
107
+ overwriteCustomConfig,
108
+ pageData,
109
+ pageStack,
43
110
  parse,
111
+ parseAutomatorArgs,
112
+ parseScreenshotArgs,
113
+ printScreenshotHelp,
44
114
  promptForCliPath,
115
+ reLaunch,
116
+ readCustomConfig,
117
+ readOptionValue,
118
+ redirectTo,
119
+ remote,
120
+ removeCustomConfigKey,
121
+ removeOption,
45
122
  resolveCliPath,
46
123
  resolvePath,
124
+ runAutomatorCommand,
47
125
  runMinidev,
126
+ runWechatCliWithRetry,
127
+ scrollTo,
128
+ switchTab,
129
+ systemInfo,
130
+ takeScreenshot,
131
+ tap,
48
132
  transformArgv,
49
- waitForRetryKeypress
133
+ validateWechatCliCommandArgs,
134
+ waitForRetryKeypress,
135
+ withMiniProgram
50
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.4",
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
  },