weapp-ide-cli 4.1.2 → 5.0.1

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,56 +1,120 @@
1
+ /**
2
+ * @description 运行支付宝小程序 CLI(minidev)
3
+ */
1
4
  declare function runMinidev(argv: readonly string[]): Promise<void>;
2
5
 
6
+ /**
7
+ * @description 交互式提示并保存 CLI 路径
8
+ */
3
9
  declare function promptForCliPath(): Promise<string | null>;
4
10
 
11
+ /**
12
+ * @description 解析 CLI 路径并校验可用性
13
+ */
5
14
  declare function resolveCliPath(): Promise<{
6
15
  cliPath: string | null;
7
16
  source: ConfigSource;
8
17
  }>;
9
18
 
19
+ /**
20
+ * @description CLI 入口解析与分发
21
+ */
10
22
  declare function parse(argv: string[]): Promise<void>;
11
23
 
24
+ /**
25
+ * @description 基础配置
26
+ */
12
27
  interface BaseConfig {
13
28
  cliPath: string;
14
29
  }
30
+ /**
31
+ * @description 配置来源
32
+ */
15
33
  type ConfigSource = 'custom' | 'default' | 'missing';
34
+ /**
35
+ * @description 解析后的配置
36
+ */
16
37
  interface ResolvedConfig extends BaseConfig {
17
38
  source: ConfigSource;
18
39
  }
40
+ /**
41
+ * @description CLI 参数别名配置
42
+ */
19
43
  interface AliasEntry {
20
44
  find: string;
21
45
  replacement: string;
22
46
  }
23
47
 
48
+ /**
49
+ * @description 写入自定义 CLI 路径配置
50
+ */
24
51
  declare function createCustomConfig(params: BaseConfig): Promise<string>;
25
52
 
53
+ /**
54
+ * @description 默认自定义配置目录
55
+ */
26
56
  declare const defaultCustomConfigDirPath: string;
57
+ /**
58
+ * @description 默认自定义配置文件路径
59
+ */
27
60
  declare const defaultCustomConfigFilePath: string;
28
61
 
62
+ /**
63
+ * @description 读取并解析 CLI 配置(自定义优先)
64
+ */
29
65
  declare function getConfig(): Promise<ResolvedConfig>;
30
66
 
31
67
  /**
32
- * 官方微信开发者工具只支持 Windows、macOS, Linux只有社区版 https://github.com/msojocs/wechat-web-devtools-linux
68
+ * @description 官方微信开发者工具只支持 Windows、macOS,Linux 只有社区版
69
+ * https://github.com/msojocs/wechat-web-devtools-linux
33
70
  */
34
71
  declare const SupportedPlatformsMap: {
35
72
  readonly Windows_NT: "Windows_NT";
36
73
  readonly Darwin: "Darwin";
37
74
  readonly Linux: "Linux";
38
75
  };
76
+ /**
77
+ * @description 支持的系统类型
78
+ */
39
79
  type SupportedPlatform = (typeof SupportedPlatformsMap)[keyof typeof SupportedPlatformsMap];
80
+ /**
81
+ * @description 判断当前系统是否支持微信开发者工具
82
+ */
40
83
  declare function isOperatingSystemSupported(osName?: string): osName is SupportedPlatform;
84
+ /**
85
+ * @description 当前系统名称
86
+ */
41
87
  declare const operatingSystemName: string;
88
+ /**
89
+ * @description 获取默认 CLI 路径(按系统)
90
+ */
42
91
  declare function getDefaultCliPath(targetOs?: string): Promise<string | undefined>;
43
92
 
93
+ /**
94
+ * @description argv 处理函数
95
+ */
44
96
  type ArgvTransform = (argv: readonly string[]) => string[];
45
97
  /**
46
- * Apply a list of argv transforms in order while keeping the original argv untouched.
98
+ * @description 依次应用 argv 处理函数(不修改原始 argv
47
99
  */
48
100
  declare function transformArgv(argv: readonly string[], transforms: readonly ArgvTransform[]): string[];
101
+ /**
102
+ * @description 创建参数别名转换器
103
+ */
49
104
  declare function createAlias(entry: AliasEntry): ArgvTransform;
105
+ /**
106
+ * @description 创建路径参数兼容转换器(补全或规范化路径)
107
+ */
50
108
  declare function createPathCompat(option: string): ArgvTransform;
51
109
 
110
+ /**
111
+ * @description 执行 CLI 命令并透传输出
112
+ */
52
113
  declare function execute(cliPath: string, argv: string[]): Promise<void>;
53
114
 
115
+ /**
116
+ * @description 解析为绝对路径(基于当前工作目录)
117
+ */
54
118
  declare function resolvePath(filePath: string): string;
55
119
 
56
120
  export { type ArgvTransform, type BaseConfig, type ConfigSource, type ResolvedConfig, type SupportedPlatform, SupportedPlatformsMap, createAlias, createCustomConfig, createPathCompat, defaultCustomConfigDirPath, defaultCustomConfigFilePath, execute, getConfig, getDefaultCliPath, isOperatingSystemSupported, operatingSystemName, parse, promptForCliPath, resolveCliPath, resolvePath, runMinidev, transformArgv };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "weapp-ide-cli",
3
3
  "type": "module",
4
- "version": "4.1.2",
4
+ "version": "5.0.1",
5
5
  "description": "让微信开发者工具,用起来更加方便!",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",
@@ -29,11 +29,10 @@
29
29
  "exports": {
30
30
  ".": {
31
31
  "types": "./dist/index.d.ts",
32
- "import": "./dist/index.js",
33
- "require": "./dist/index.cjs"
32
+ "import": "./dist/index.js"
34
33
  }
35
34
  },
36
- "main": "./dist/index.cjs",
35
+ "main": "./dist/index.js",
37
36
  "module": "./dist/index.js",
38
37
  "types": "./dist/index.d.ts",
39
38
  "bin": {
@@ -55,6 +54,9 @@
55
54
  "bin",
56
55
  "dist"
57
56
  ],
57
+ "engines": {
58
+ "node": "^20.19.0 || >=22.12.0"
59
+ },
58
60
  "publishConfig": {
59
61
  "access": "public",
60
62
  "registry": "https://registry.npmjs.org/"
@@ -63,7 +65,7 @@
63
65
  "execa": "9.6.1",
64
66
  "fs-extra": "^11.3.3",
65
67
  "pathe": "^2.0.3",
66
- "@weapp-core/logger": "^2.0.0"
68
+ "@weapp-core/logger": "^3.0.3"
67
69
  },
68
70
  "scripts": {
69
71
  "dev": "tsup --watch --sourcemap",
package/dist/cli.cjs DELETED
@@ -1,354 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __copyProps = (to, from, except, desc) => {
9
- if (from && typeof from === "object" || typeof from === "function") {
10
- for (let key of __getOwnPropNames(from))
11
- if (!__hasOwnProp.call(to, key) && key !== except)
12
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
- }
14
- return to;
15
- };
16
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
17
- // If the importer is in node compatibility mode or this is not an ESM
18
- // file that has been converted to a CommonJS file using a Babel-
19
- // compatible transform (i.e. "__esModule" has not been set), then set
20
- // "default" to the CommonJS "module.exports" for node compatibility.
21
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
- mod
23
- ));
24
-
25
- // src/cli.ts
26
- var import_node_process6 = __toESM(require("process"), 1);
27
-
28
- // src/logger.ts
29
- var import_logger = __toESM(require("@weapp-core/logger"), 1);
30
- var logger_default = import_logger.default;
31
-
32
- // src/utils/argv.ts
33
- var import_node_process2 = __toESM(require("process"), 1);
34
-
35
- // src/utils/path.ts
36
- var import_node_process = __toESM(require("process"), 1);
37
- var import_pathe = __toESM(require("pathe"), 1);
38
- function resolvePath(filePath) {
39
- if (import_pathe.default.isAbsolute(filePath)) {
40
- return filePath;
41
- }
42
- return import_pathe.default.resolve(import_node_process.default.cwd(), filePath);
43
- }
44
-
45
- // src/utils/argv.ts
46
- function ensurePathArgument(argv2, optionIndex) {
47
- const paramIdx = optionIndex + 1;
48
- const param = argv2[paramIdx];
49
- if (param && !param.startsWith("-")) {
50
- argv2[paramIdx] = resolvePath(param);
51
- } else {
52
- argv2.splice(paramIdx, 0, import_node_process2.default.cwd());
53
- }
54
- return argv2;
55
- }
56
- function transformArgv(argv2, transforms) {
57
- return transforms.reduce((current, transform) => transform(current), [
58
- ...argv2
59
- ]);
60
- }
61
- function createAlias(entry) {
62
- return (input2) => {
63
- const argv2 = [...input2];
64
- let optionIndex = argv2.indexOf(entry.find);
65
- if (optionIndex > -1) {
66
- argv2.splice(optionIndex, 1, entry.replacement);
67
- } else {
68
- optionIndex = argv2.indexOf(entry.replacement);
69
- }
70
- if (optionIndex === -1) {
71
- return argv2;
72
- }
73
- return ensurePathArgument(argv2, optionIndex);
74
- };
75
- }
76
- function createPathCompat(option) {
77
- return (input2) => {
78
- const argv2 = [...input2];
79
- const optionIndex = argv2.indexOf(option);
80
- if (optionIndex === -1) {
81
- return argv2;
82
- }
83
- return ensurePathArgument(argv2, optionIndex);
84
- };
85
- }
86
-
87
- // src/utils/exec.ts
88
- var import_node_process3 = __toESM(require("process"), 1);
89
- async function execute(cliPath, argv2) {
90
- const { execa } = await import("execa");
91
- const task = execa(cliPath, argv2);
92
- task?.stdout?.pipe(import_node_process3.default.stdout);
93
- task?.stderr?.pipe(import_node_process3.default.stderr);
94
- await task;
95
- }
96
-
97
- // src/cli/minidev.ts
98
- var MINIDEV_COMMAND = "minidev";
99
- function isCommandNotFound(error) {
100
- return Boolean(
101
- error && typeof error === "object" && "code" in error && error.code === "ENOENT"
102
- );
103
- }
104
- async function runMinidev(argv2) {
105
- try {
106
- await execute(MINIDEV_COMMAND, [...argv2]);
107
- } catch (error) {
108
- if (isCommandNotFound(error)) {
109
- logger_default.error("\u672A\u68C0\u6D4B\u5230\u652F\u4ED8\u5B9D\u5C0F\u7A0B\u5E8F CLI\uFF1Aminidev");
110
- logger_default.log("\u8BF7\u5148\u5B89\u88C5 minidev\uFF0C\u53EF\u4F7F\u7528\u4EE5\u4E0B\u4EFB\u4E00\u547D\u4EE4\uFF1A");
111
- logger_default.log("- pnpm add -g minidev");
112
- logger_default.log("- npm install -g minidev");
113
- logger_default.log("- yarn global add minidev");
114
- return;
115
- }
116
- throw error;
117
- }
118
- }
119
-
120
- // src/cli/prompt.ts
121
- var import_node_process4 = require("process");
122
- var import_promises = require("readline/promises");
123
- var import_fs_extra2 = __toESM(require("fs-extra"), 1);
124
-
125
- // src/config/custom.ts
126
- var import_fs_extra = __toESM(require("fs-extra"), 1);
127
-
128
- // src/config/paths.ts
129
- var import_node_os = __toESM(require("os"), 1);
130
- var import_pathe2 = __toESM(require("pathe"), 1);
131
- var homedir = import_node_os.default.homedir();
132
- var defaultCustomConfigDirPath = import_pathe2.default.join(homedir, ".weapp-ide-cli");
133
- var defaultCustomConfigFilePath = import_pathe2.default.join(
134
- defaultCustomConfigDirPath,
135
- "config.json"
136
- );
137
-
138
- // src/config/custom.ts
139
- var JSON_OPTIONS = {
140
- encoding: "utf8",
141
- spaces: 2
142
- };
143
- async function createCustomConfig(params) {
144
- const trimmedCliPath = params.cliPath.trim();
145
- if (!trimmedCliPath) {
146
- throw new Error("cliPath cannot be empty");
147
- }
148
- const normalizedCliPath = resolvePath(trimmedCliPath);
149
- await import_fs_extra.default.ensureDir(defaultCustomConfigDirPath);
150
- await import_fs_extra.default.writeJSON(
151
- defaultCustomConfigFilePath,
152
- {
153
- cliPath: normalizedCliPath
154
- },
155
- JSON_OPTIONS
156
- );
157
- return normalizedCliPath;
158
- }
159
-
160
- // src/cli/prompt.ts
161
- async function promptForCliPath() {
162
- const rl = (0, import_promises.createInterface)({ input: import_node_process4.stdin, output: import_node_process4.stdout });
163
- try {
164
- logger_default.log("\u8BF7\u8BBE\u7F6E\u5FAE\u4FE1web\u5F00\u53D1\u8005\u5DE5\u5177 CLI \u7684\u8DEF\u5F84");
165
- logger_default.log("> \u63D0\u793A\uFF1A\u547D\u4EE4\u884C\u5DE5\u5177\u9ED8\u8BA4\u6240\u5728\u4F4D\u7F6E\uFF1A");
166
- logger_default.log("- MacOS: <\u5B89\u88C5\u8DEF\u5F84>/Contents/MacOS/cli");
167
- logger_default.log("- Windows: <\u5B89\u88C5\u8DEF\u5F84>/cli.bat");
168
- logger_default.log("- Linux: <\u5B89\u88C5\u8DEF\u5F84>/files/bin/bin/wechat-devtools-cli");
169
- const cliPath = (await rl.question("\u8BF7\u8F93\u5165\u5FAE\u4FE1web\u5F00\u53D1\u8005\u5DE5\u5177 CLI \u8DEF\u5F84\uFF1A")).trim();
170
- if (!cliPath) {
171
- logger_default.error("\u8DEF\u5F84\u4E0D\u80FD\u4E3A\u7A7A\uFF0C\u5DF2\u53D6\u6D88\u672C\u6B21\u914D\u7F6E\u3002");
172
- return null;
173
- }
174
- try {
175
- const normalizedPath = await createCustomConfig({ cliPath });
176
- logger_default.log(`\u5168\u5C40\u914D\u7F6E\u5B58\u50A8\u4F4D\u7F6E\uFF1A${defaultCustomConfigFilePath}`);
177
- if (!await import_fs_extra2.default.pathExists(normalizedPath)) {
178
- logger_default.warn("\u5728\u5F53\u524D\u8DEF\u5F84\u672A\u627E\u5230\u5FAE\u4FE1web\u5F00\u53D1\u8005\u547D\u4EE4\u884C\u5DE5\u5177\uFF0C\u8BF7\u786E\u8BA4\u8DEF\u5F84\u662F\u5426\u6B63\u786E\u3002");
179
- }
180
- return normalizedPath;
181
- } catch (error) {
182
- const reason = error instanceof Error ? error.message : String(error);
183
- logger_default.error(`\u4FDD\u5B58\u914D\u7F6E\u5931\u8D25\uFF1A${reason}`);
184
- return null;
185
- }
186
- } finally {
187
- rl.close();
188
- }
189
- }
190
-
191
- // src/cli/resolver.ts
192
- var import_fs_extra5 = __toESM(require("fs-extra"), 1);
193
-
194
- // src/config/resolver.ts
195
- var import_fs_extra4 = __toESM(require("fs-extra"), 1);
196
-
197
- // src/runtime/platform.ts
198
- var import_node_os2 = __toESM(require("os"), 1);
199
- var import_node_process5 = __toESM(require("process"), 1);
200
- var import_fs_extra3 = __toESM(require("fs-extra"), 1);
201
- var import_pathe3 = __toESM(require("pathe"), 1);
202
- var SupportedPlatformsMap = {
203
- Windows_NT: "Windows_NT",
204
- Darwin: "Darwin",
205
- Linux: "Linux"
206
- };
207
- function isOperatingSystemSupported(osName = import_node_os2.default.type()) {
208
- return osName === SupportedPlatformsMap.Windows_NT || osName === SupportedPlatformsMap.Darwin || osName === SupportedPlatformsMap.Linux;
209
- }
210
- var operatingSystemName = import_node_os2.default.type();
211
- function createLinuxCliResolver() {
212
- let resolvedPath;
213
- let attempted = false;
214
- let pending = null;
215
- return async () => {
216
- if (attempted) {
217
- return resolvedPath;
218
- }
219
- if (!pending) {
220
- pending = (async () => {
221
- try {
222
- const envPath = await getFirstBinaryPath("wechat-devtools-cli");
223
- if (envPath) {
224
- resolvedPath = envPath;
225
- }
226
- } catch (error) {
227
- const reason = error instanceof Error ? error.message : String(error);
228
- logger_default.warn(`\u83B7\u53D6 Linux wechat-devtools-cli \u8DEF\u5F84\u5931\u8D25\uFF1A${reason}`);
229
- } finally {
230
- attempted = true;
231
- }
232
- return resolvedPath;
233
- })();
234
- }
235
- return pending;
236
- };
237
- }
238
- var linuxCliResolver = createLinuxCliResolver();
239
- var WINDOWS_DEFAULT_CLI = "C:\\Program Files (x86)\\Tencent\\\u5FAE\u4FE1web\u5F00\u53D1\u8005\u5DE5\u5177\\cli.bat";
240
- var DARWIN_DEFAULT_CLI = "/Applications/wechatwebdevtools.app/Contents/MacOS/cli";
241
- var cliPathResolvers = {
242
- [SupportedPlatformsMap.Windows_NT]: async () => WINDOWS_DEFAULT_CLI,
243
- [SupportedPlatformsMap.Darwin]: async () => DARWIN_DEFAULT_CLI,
244
- [SupportedPlatformsMap.Linux]: linuxCliResolver
245
- };
246
- async function getDefaultCliPath(targetOs = operatingSystemName) {
247
- if (!isOperatingSystemSupported(targetOs)) {
248
- return void 0;
249
- }
250
- const resolver = cliPathResolvers[targetOs];
251
- const resolvedPath = await resolver();
252
- return resolvedPath;
253
- }
254
- async function getFirstBinaryPath(command) {
255
- const envPath = import_node_process5.default.env.PATH || "";
256
- const pathDirs = envPath.split(import_pathe3.default.delimiter);
257
- for (const dir of pathDirs) {
258
- const fullPath = import_pathe3.default.join(dir, command);
259
- try {
260
- await import_fs_extra3.default.access(fullPath, import_fs_extra3.default.constants.X_OK);
261
- return fullPath;
262
- } catch {
263
- continue;
264
- }
265
- }
266
- return void 0;
267
- }
268
-
269
- // src/config/resolver.ts
270
- async function getConfig() {
271
- if (await import_fs_extra4.default.pathExists(defaultCustomConfigFilePath)) {
272
- try {
273
- const config = await import_fs_extra4.default.readJSON(defaultCustomConfigFilePath);
274
- const cliPath = typeof config.cliPath === "string" ? config.cliPath.trim() : "";
275
- if (cliPath) {
276
- logger_default.log("> \u5168\u5C40\u914D\u7F6E\u6587\u4EF6\u8DEF\u5F84\uFF1A", defaultCustomConfigFilePath);
277
- logger_default.log("> \u81EA\u5B9A\u4E49 CLI \u8DEF\u5F84\uFF1A", cliPath);
278
- return {
279
- cliPath,
280
- source: "custom"
281
- };
282
- }
283
- logger_default.warn("\u81EA\u5B9A\u4E49\u914D\u7F6E\u6587\u4EF6\u7F3A\u5C11\u6709\u6548\u7684 CLI \u8DEF\u5F84\uFF0C\u5C06\u5C1D\u8BD5\u4F7F\u7528\u9ED8\u8BA4\u8DEF\u5F84\u3002");
284
- } catch (error) {
285
- const reason = error instanceof Error ? error.message : String(error);
286
- logger_default.warn(`\u89E3\u6790\u81EA\u5B9A\u4E49\u914D\u7F6E\u5931\u8D25\uFF0C\u5C06\u5C1D\u8BD5\u4F7F\u7528\u9ED8\u8BA4\u8DEF\u5F84\u3002\u539F\u56E0\uFF1A${reason}`);
287
- }
288
- }
289
- const fallbackPath = await getDefaultCliPath();
290
- if (fallbackPath) {
291
- return {
292
- cliPath: fallbackPath,
293
- source: "default"
294
- };
295
- }
296
- return {
297
- cliPath: "",
298
- source: "missing"
299
- };
300
- }
301
-
302
- // src/cli/resolver.ts
303
- async function resolveCliPath() {
304
- const config = await getConfig();
305
- if (!config.cliPath) {
306
- return { cliPath: null, source: config.source };
307
- }
308
- const exists = await import_fs_extra5.default.pathExists(config.cliPath);
309
- return {
310
- cliPath: exists ? config.cliPath : null,
311
- source: config.source
312
- };
313
- }
314
-
315
- // src/cli/run.ts
316
- var ARG_TRANSFORMS = [
317
- createAlias({ find: "-p", replacement: "--project" }),
318
- createPathCompat("--result-output"),
319
- createPathCompat("-r"),
320
- createPathCompat("--qr-output"),
321
- createPathCompat("-o"),
322
- createPathCompat("--info-output"),
323
- createPathCompat("-i")
324
- ];
325
- async function parse(argv2) {
326
- const head = argv2[0];
327
- if (head && ["alipay", "ali", "minidev"].includes(head)) {
328
- await runMinidev(argv2.slice(1));
329
- return;
330
- }
331
- if (!isOperatingSystemSupported(operatingSystemName)) {
332
- logger_default.log(`\u5FAE\u4FE1web\u5F00\u53D1\u8005\u5DE5\u5177\u4E0D\u652F\u6301\u5F53\u524D\u5E73\u53F0\uFF1A${operatingSystemName} !`);
333
- return;
334
- }
335
- if (head === "config") {
336
- await promptForCliPath();
337
- return;
338
- }
339
- const { cliPath, source } = await resolveCliPath();
340
- if (!cliPath) {
341
- const message = source === "custom" ? "\u5728\u5F53\u524D\u81EA\u5B9A\u4E49\u8DEF\u5F84\u4E2D\u672A\u627E\u5230\u5FAE\u4FE1web\u5F00\u53D1\u8005\u547D\u4EE4\u884C\u5DE5\u5177\uFF0C\u8BF7\u91CD\u65B0\u6307\u5B9A\u8DEF\u5F84\u3002" : "\u672A\u68C0\u6D4B\u5230\u5FAE\u4FE1web\u5F00\u53D1\u8005\u547D\u4EE4\u884C\u5DE5\u5177\uFF0C\u8BF7\u6267\u884C `weapp-ide-cli config` \u6307\u5B9A\u8DEF\u5F84\u3002";
342
- logger_default.log(message);
343
- await promptForCliPath();
344
- return;
345
- }
346
- const formattedArgv = transformArgv(argv2, ARG_TRANSFORMS);
347
- await execute(cliPath, formattedArgv);
348
- }
349
-
350
- // src/cli.ts
351
- var argv = import_node_process6.default.argv.slice(2);
352
- parse(argv).catch((err) => {
353
- logger_default.error(err);
354
- });
package/dist/cli.d.cts DELETED
@@ -1,2 +0,0 @@
1
-
2
- export { }
package/dist/index.cjs DELETED
@@ -1,393 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/index.ts
31
- var src_exports = {};
32
- __export(src_exports, {
33
- SupportedPlatformsMap: () => SupportedPlatformsMap,
34
- createAlias: () => createAlias,
35
- createCustomConfig: () => createCustomConfig,
36
- createPathCompat: () => createPathCompat,
37
- defaultCustomConfigDirPath: () => defaultCustomConfigDirPath,
38
- defaultCustomConfigFilePath: () => defaultCustomConfigFilePath,
39
- execute: () => execute,
40
- getConfig: () => getConfig,
41
- getDefaultCliPath: () => getDefaultCliPath,
42
- isOperatingSystemSupported: () => isOperatingSystemSupported,
43
- operatingSystemName: () => operatingSystemName,
44
- parse: () => parse,
45
- promptForCliPath: () => promptForCliPath,
46
- resolveCliPath: () => resolveCliPath,
47
- resolvePath: () => resolvePath,
48
- runMinidev: () => runMinidev,
49
- transformArgv: () => transformArgv
50
- });
51
- module.exports = __toCommonJS(src_exports);
52
-
53
- // src/logger.ts
54
- var import_logger = __toESM(require("@weapp-core/logger"), 1);
55
- var logger_default = import_logger.default;
56
-
57
- // src/utils/argv.ts
58
- var import_node_process2 = __toESM(require("process"), 1);
59
-
60
- // src/utils/path.ts
61
- var import_node_process = __toESM(require("process"), 1);
62
- var import_pathe = __toESM(require("pathe"), 1);
63
- function resolvePath(filePath) {
64
- if (import_pathe.default.isAbsolute(filePath)) {
65
- return filePath;
66
- }
67
- return import_pathe.default.resolve(import_node_process.default.cwd(), filePath);
68
- }
69
-
70
- // src/utils/argv.ts
71
- function ensurePathArgument(argv, optionIndex) {
72
- const paramIdx = optionIndex + 1;
73
- const param = argv[paramIdx];
74
- if (param && !param.startsWith("-")) {
75
- argv[paramIdx] = resolvePath(param);
76
- } else {
77
- argv.splice(paramIdx, 0, import_node_process2.default.cwd());
78
- }
79
- return argv;
80
- }
81
- function transformArgv(argv, transforms) {
82
- return transforms.reduce((current, transform) => transform(current), [
83
- ...argv
84
- ]);
85
- }
86
- function createAlias(entry) {
87
- return (input2) => {
88
- const argv = [...input2];
89
- let optionIndex = argv.indexOf(entry.find);
90
- if (optionIndex > -1) {
91
- argv.splice(optionIndex, 1, entry.replacement);
92
- } else {
93
- optionIndex = argv.indexOf(entry.replacement);
94
- }
95
- if (optionIndex === -1) {
96
- return argv;
97
- }
98
- return ensurePathArgument(argv, optionIndex);
99
- };
100
- }
101
- function createPathCompat(option) {
102
- return (input2) => {
103
- const argv = [...input2];
104
- const optionIndex = argv.indexOf(option);
105
- if (optionIndex === -1) {
106
- return argv;
107
- }
108
- return ensurePathArgument(argv, optionIndex);
109
- };
110
- }
111
-
112
- // src/utils/exec.ts
113
- var import_node_process3 = __toESM(require("process"), 1);
114
- async function execute(cliPath, argv) {
115
- const { execa } = await import("execa");
116
- const task = execa(cliPath, argv);
117
- task?.stdout?.pipe(import_node_process3.default.stdout);
118
- task?.stderr?.pipe(import_node_process3.default.stderr);
119
- await task;
120
- }
121
-
122
- // src/cli/minidev.ts
123
- var MINIDEV_COMMAND = "minidev";
124
- function isCommandNotFound(error) {
125
- return Boolean(
126
- error && typeof error === "object" && "code" in error && error.code === "ENOENT"
127
- );
128
- }
129
- async function runMinidev(argv) {
130
- try {
131
- await execute(MINIDEV_COMMAND, [...argv]);
132
- } catch (error) {
133
- if (isCommandNotFound(error)) {
134
- logger_default.error("\u672A\u68C0\u6D4B\u5230\u652F\u4ED8\u5B9D\u5C0F\u7A0B\u5E8F CLI\uFF1Aminidev");
135
- logger_default.log("\u8BF7\u5148\u5B89\u88C5 minidev\uFF0C\u53EF\u4F7F\u7528\u4EE5\u4E0B\u4EFB\u4E00\u547D\u4EE4\uFF1A");
136
- logger_default.log("- pnpm add -g minidev");
137
- logger_default.log("- npm install -g minidev");
138
- logger_default.log("- yarn global add minidev");
139
- return;
140
- }
141
- throw error;
142
- }
143
- }
144
-
145
- // src/cli/prompt.ts
146
- var import_node_process4 = require("process");
147
- var import_promises = require("readline/promises");
148
- var import_fs_extra2 = __toESM(require("fs-extra"), 1);
149
-
150
- // src/config/custom.ts
151
- var import_fs_extra = __toESM(require("fs-extra"), 1);
152
-
153
- // src/config/paths.ts
154
- var import_node_os = __toESM(require("os"), 1);
155
- var import_pathe2 = __toESM(require("pathe"), 1);
156
- var homedir = import_node_os.default.homedir();
157
- var defaultCustomConfigDirPath = import_pathe2.default.join(homedir, ".weapp-ide-cli");
158
- var defaultCustomConfigFilePath = import_pathe2.default.join(
159
- defaultCustomConfigDirPath,
160
- "config.json"
161
- );
162
-
163
- // src/config/custom.ts
164
- var JSON_OPTIONS = {
165
- encoding: "utf8",
166
- spaces: 2
167
- };
168
- async function createCustomConfig(params) {
169
- const trimmedCliPath = params.cliPath.trim();
170
- if (!trimmedCliPath) {
171
- throw new Error("cliPath cannot be empty");
172
- }
173
- const normalizedCliPath = resolvePath(trimmedCliPath);
174
- await import_fs_extra.default.ensureDir(defaultCustomConfigDirPath);
175
- await import_fs_extra.default.writeJSON(
176
- defaultCustomConfigFilePath,
177
- {
178
- cliPath: normalizedCliPath
179
- },
180
- JSON_OPTIONS
181
- );
182
- return normalizedCliPath;
183
- }
184
-
185
- // src/cli/prompt.ts
186
- async function promptForCliPath() {
187
- const rl = (0, import_promises.createInterface)({ input: import_node_process4.stdin, output: import_node_process4.stdout });
188
- try {
189
- logger_default.log("\u8BF7\u8BBE\u7F6E\u5FAE\u4FE1web\u5F00\u53D1\u8005\u5DE5\u5177 CLI \u7684\u8DEF\u5F84");
190
- logger_default.log("> \u63D0\u793A\uFF1A\u547D\u4EE4\u884C\u5DE5\u5177\u9ED8\u8BA4\u6240\u5728\u4F4D\u7F6E\uFF1A");
191
- logger_default.log("- MacOS: <\u5B89\u88C5\u8DEF\u5F84>/Contents/MacOS/cli");
192
- logger_default.log("- Windows: <\u5B89\u88C5\u8DEF\u5F84>/cli.bat");
193
- logger_default.log("- Linux: <\u5B89\u88C5\u8DEF\u5F84>/files/bin/bin/wechat-devtools-cli");
194
- const cliPath = (await rl.question("\u8BF7\u8F93\u5165\u5FAE\u4FE1web\u5F00\u53D1\u8005\u5DE5\u5177 CLI \u8DEF\u5F84\uFF1A")).trim();
195
- if (!cliPath) {
196
- logger_default.error("\u8DEF\u5F84\u4E0D\u80FD\u4E3A\u7A7A\uFF0C\u5DF2\u53D6\u6D88\u672C\u6B21\u914D\u7F6E\u3002");
197
- return null;
198
- }
199
- try {
200
- const normalizedPath = await createCustomConfig({ cliPath });
201
- logger_default.log(`\u5168\u5C40\u914D\u7F6E\u5B58\u50A8\u4F4D\u7F6E\uFF1A${defaultCustomConfigFilePath}`);
202
- if (!await import_fs_extra2.default.pathExists(normalizedPath)) {
203
- logger_default.warn("\u5728\u5F53\u524D\u8DEF\u5F84\u672A\u627E\u5230\u5FAE\u4FE1web\u5F00\u53D1\u8005\u547D\u4EE4\u884C\u5DE5\u5177\uFF0C\u8BF7\u786E\u8BA4\u8DEF\u5F84\u662F\u5426\u6B63\u786E\u3002");
204
- }
205
- return normalizedPath;
206
- } catch (error) {
207
- const reason = error instanceof Error ? error.message : String(error);
208
- logger_default.error(`\u4FDD\u5B58\u914D\u7F6E\u5931\u8D25\uFF1A${reason}`);
209
- return null;
210
- }
211
- } finally {
212
- rl.close();
213
- }
214
- }
215
-
216
- // src/cli/resolver.ts
217
- var import_fs_extra5 = __toESM(require("fs-extra"), 1);
218
-
219
- // src/config/resolver.ts
220
- var import_fs_extra4 = __toESM(require("fs-extra"), 1);
221
-
222
- // src/runtime/platform.ts
223
- var import_node_os2 = __toESM(require("os"), 1);
224
- var import_node_process5 = __toESM(require("process"), 1);
225
- var import_fs_extra3 = __toESM(require("fs-extra"), 1);
226
- var import_pathe3 = __toESM(require("pathe"), 1);
227
- var SupportedPlatformsMap = {
228
- Windows_NT: "Windows_NT",
229
- Darwin: "Darwin",
230
- Linux: "Linux"
231
- };
232
- function isOperatingSystemSupported(osName = import_node_os2.default.type()) {
233
- return osName === SupportedPlatformsMap.Windows_NT || osName === SupportedPlatformsMap.Darwin || osName === SupportedPlatformsMap.Linux;
234
- }
235
- var operatingSystemName = import_node_os2.default.type();
236
- function createLinuxCliResolver() {
237
- let resolvedPath;
238
- let attempted = false;
239
- let pending = null;
240
- return async () => {
241
- if (attempted) {
242
- return resolvedPath;
243
- }
244
- if (!pending) {
245
- pending = (async () => {
246
- try {
247
- const envPath = await getFirstBinaryPath("wechat-devtools-cli");
248
- if (envPath) {
249
- resolvedPath = envPath;
250
- }
251
- } catch (error) {
252
- const reason = error instanceof Error ? error.message : String(error);
253
- logger_default.warn(`\u83B7\u53D6 Linux wechat-devtools-cli \u8DEF\u5F84\u5931\u8D25\uFF1A${reason}`);
254
- } finally {
255
- attempted = true;
256
- }
257
- return resolvedPath;
258
- })();
259
- }
260
- return pending;
261
- };
262
- }
263
- var linuxCliResolver = createLinuxCliResolver();
264
- var WINDOWS_DEFAULT_CLI = "C:\\Program Files (x86)\\Tencent\\\u5FAE\u4FE1web\u5F00\u53D1\u8005\u5DE5\u5177\\cli.bat";
265
- var DARWIN_DEFAULT_CLI = "/Applications/wechatwebdevtools.app/Contents/MacOS/cli";
266
- var cliPathResolvers = {
267
- [SupportedPlatformsMap.Windows_NT]: async () => WINDOWS_DEFAULT_CLI,
268
- [SupportedPlatformsMap.Darwin]: async () => DARWIN_DEFAULT_CLI,
269
- [SupportedPlatformsMap.Linux]: linuxCliResolver
270
- };
271
- async function getDefaultCliPath(targetOs = operatingSystemName) {
272
- if (!isOperatingSystemSupported(targetOs)) {
273
- return void 0;
274
- }
275
- const resolver = cliPathResolvers[targetOs];
276
- const resolvedPath = await resolver();
277
- return resolvedPath;
278
- }
279
- async function getFirstBinaryPath(command) {
280
- const envPath = import_node_process5.default.env.PATH || "";
281
- const pathDirs = envPath.split(import_pathe3.default.delimiter);
282
- for (const dir of pathDirs) {
283
- const fullPath = import_pathe3.default.join(dir, command);
284
- try {
285
- await import_fs_extra3.default.access(fullPath, import_fs_extra3.default.constants.X_OK);
286
- return fullPath;
287
- } catch {
288
- continue;
289
- }
290
- }
291
- return void 0;
292
- }
293
-
294
- // src/config/resolver.ts
295
- async function getConfig() {
296
- if (await import_fs_extra4.default.pathExists(defaultCustomConfigFilePath)) {
297
- try {
298
- const config = await import_fs_extra4.default.readJSON(defaultCustomConfigFilePath);
299
- const cliPath = typeof config.cliPath === "string" ? config.cliPath.trim() : "";
300
- if (cliPath) {
301
- logger_default.log("> \u5168\u5C40\u914D\u7F6E\u6587\u4EF6\u8DEF\u5F84\uFF1A", defaultCustomConfigFilePath);
302
- logger_default.log("> \u81EA\u5B9A\u4E49 CLI \u8DEF\u5F84\uFF1A", cliPath);
303
- return {
304
- cliPath,
305
- source: "custom"
306
- };
307
- }
308
- logger_default.warn("\u81EA\u5B9A\u4E49\u914D\u7F6E\u6587\u4EF6\u7F3A\u5C11\u6709\u6548\u7684 CLI \u8DEF\u5F84\uFF0C\u5C06\u5C1D\u8BD5\u4F7F\u7528\u9ED8\u8BA4\u8DEF\u5F84\u3002");
309
- } catch (error) {
310
- const reason = error instanceof Error ? error.message : String(error);
311
- logger_default.warn(`\u89E3\u6790\u81EA\u5B9A\u4E49\u914D\u7F6E\u5931\u8D25\uFF0C\u5C06\u5C1D\u8BD5\u4F7F\u7528\u9ED8\u8BA4\u8DEF\u5F84\u3002\u539F\u56E0\uFF1A${reason}`);
312
- }
313
- }
314
- const fallbackPath = await getDefaultCliPath();
315
- if (fallbackPath) {
316
- return {
317
- cliPath: fallbackPath,
318
- source: "default"
319
- };
320
- }
321
- return {
322
- cliPath: "",
323
- source: "missing"
324
- };
325
- }
326
-
327
- // src/cli/resolver.ts
328
- async function resolveCliPath() {
329
- const config = await getConfig();
330
- if (!config.cliPath) {
331
- return { cliPath: null, source: config.source };
332
- }
333
- const exists = await import_fs_extra5.default.pathExists(config.cliPath);
334
- return {
335
- cliPath: exists ? config.cliPath : null,
336
- source: config.source
337
- };
338
- }
339
-
340
- // src/cli/run.ts
341
- var ARG_TRANSFORMS = [
342
- createAlias({ find: "-p", replacement: "--project" }),
343
- createPathCompat("--result-output"),
344
- createPathCompat("-r"),
345
- createPathCompat("--qr-output"),
346
- createPathCompat("-o"),
347
- createPathCompat("--info-output"),
348
- createPathCompat("-i")
349
- ];
350
- async function parse(argv) {
351
- const head = argv[0];
352
- if (head && ["alipay", "ali", "minidev"].includes(head)) {
353
- await runMinidev(argv.slice(1));
354
- return;
355
- }
356
- if (!isOperatingSystemSupported(operatingSystemName)) {
357
- logger_default.log(`\u5FAE\u4FE1web\u5F00\u53D1\u8005\u5DE5\u5177\u4E0D\u652F\u6301\u5F53\u524D\u5E73\u53F0\uFF1A${operatingSystemName} !`);
358
- return;
359
- }
360
- if (head === "config") {
361
- await promptForCliPath();
362
- return;
363
- }
364
- const { cliPath, source } = await resolveCliPath();
365
- if (!cliPath) {
366
- const message = source === "custom" ? "\u5728\u5F53\u524D\u81EA\u5B9A\u4E49\u8DEF\u5F84\u4E2D\u672A\u627E\u5230\u5FAE\u4FE1web\u5F00\u53D1\u8005\u547D\u4EE4\u884C\u5DE5\u5177\uFF0C\u8BF7\u91CD\u65B0\u6307\u5B9A\u8DEF\u5F84\u3002" : "\u672A\u68C0\u6D4B\u5230\u5FAE\u4FE1web\u5F00\u53D1\u8005\u547D\u4EE4\u884C\u5DE5\u5177\uFF0C\u8BF7\u6267\u884C `weapp-ide-cli config` \u6307\u5B9A\u8DEF\u5F84\u3002";
367
- logger_default.log(message);
368
- await promptForCliPath();
369
- return;
370
- }
371
- const formattedArgv = transformArgv(argv, ARG_TRANSFORMS);
372
- await execute(cliPath, formattedArgv);
373
- }
374
- // Annotate the CommonJS export names for ESM import in node:
375
- 0 && (module.exports = {
376
- SupportedPlatformsMap,
377
- createAlias,
378
- createCustomConfig,
379
- createPathCompat,
380
- defaultCustomConfigDirPath,
381
- defaultCustomConfigFilePath,
382
- execute,
383
- getConfig,
384
- getDefaultCliPath,
385
- isOperatingSystemSupported,
386
- operatingSystemName,
387
- parse,
388
- promptForCliPath,
389
- resolveCliPath,
390
- resolvePath,
391
- runMinidev,
392
- transformArgv
393
- });
package/dist/index.d.cts DELETED
@@ -1,56 +0,0 @@
1
- declare function runMinidev(argv: readonly string[]): Promise<void>;
2
-
3
- declare function promptForCliPath(): Promise<string | null>;
4
-
5
- declare function resolveCliPath(): Promise<{
6
- cliPath: string | null;
7
- source: ConfigSource;
8
- }>;
9
-
10
- declare function parse(argv: string[]): Promise<void>;
11
-
12
- interface BaseConfig {
13
- cliPath: string;
14
- }
15
- type ConfigSource = 'custom' | 'default' | 'missing';
16
- interface ResolvedConfig extends BaseConfig {
17
- source: ConfigSource;
18
- }
19
- interface AliasEntry {
20
- find: string;
21
- replacement: string;
22
- }
23
-
24
- declare function createCustomConfig(params: BaseConfig): Promise<string>;
25
-
26
- declare const defaultCustomConfigDirPath: string;
27
- declare const defaultCustomConfigFilePath: string;
28
-
29
- declare function getConfig(): Promise<ResolvedConfig>;
30
-
31
- /**
32
- * 官方微信开发者工具只支持 Windows、macOS, Linux只有社区版 https://github.com/msojocs/wechat-web-devtools-linux
33
- */
34
- declare const SupportedPlatformsMap: {
35
- readonly Windows_NT: "Windows_NT";
36
- readonly Darwin: "Darwin";
37
- readonly Linux: "Linux";
38
- };
39
- type SupportedPlatform = (typeof SupportedPlatformsMap)[keyof typeof SupportedPlatformsMap];
40
- declare function isOperatingSystemSupported(osName?: string): osName is SupportedPlatform;
41
- declare const operatingSystemName: string;
42
- declare function getDefaultCliPath(targetOs?: string): Promise<string | undefined>;
43
-
44
- type ArgvTransform = (argv: readonly string[]) => string[];
45
- /**
46
- * Apply a list of argv transforms in order while keeping the original argv untouched.
47
- */
48
- declare function transformArgv(argv: readonly string[], transforms: readonly ArgvTransform[]): string[];
49
- declare function createAlias(entry: AliasEntry): ArgvTransform;
50
- declare function createPathCompat(option: string): ArgvTransform;
51
-
52
- declare function execute(cliPath: string, argv: string[]): Promise<void>;
53
-
54
- declare function resolvePath(filePath: string): string;
55
-
56
- export { type ArgvTransform, type BaseConfig, type ConfigSource, type ResolvedConfig, type SupportedPlatform, SupportedPlatformsMap, createAlias, createCustomConfig, createPathCompat, defaultCustomConfigDirPath, defaultCustomConfigFilePath, execute, getConfig, getDefaultCliPath, isOperatingSystemSupported, operatingSystemName, parse, promptForCliPath, resolveCliPath, resolvePath, runMinidev, transformArgv };