weapp-ide-cli 5.0.2 → 5.0.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/README.md +18 -0
- package/dist/chunk-QTQD5BFV.js +661 -0
- package/dist/cli.js +10 -1
- package/dist/index.d.ts +40 -2
- package/dist/index.js +15 -3
- package/package.json +2 -2
- package/dist/chunk-DNENPZKW.js +0 -393
package/README.md
CHANGED
|
@@ -110,9 +110,27 @@ weapp config
|
|
|
110
110
|
2. 首次运行前可通过 `weapp config` 写入 CLI 路径,也可在 CI 中直接向 `~/.weapp-ide-cli/config.json` 写入。
|
|
111
111
|
3. 在自动化流程中建议加上 `--qr-output`、`--result-output` 等参数,以便收集产物或日志。
|
|
112
112
|
|
|
113
|
+
推荐在 CI 或非交互脚本里显式启用非交互模式,避免登录失效时卡在按键等待:
|
|
114
|
+
|
|
115
|
+
```sh
|
|
116
|
+
weapp build-npm -p --non-interactive
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
登录重试相关参数:
|
|
120
|
+
|
|
121
|
+
- `--non-interactive`:非交互模式,登录失效时直接失败(退出码语义保留为 `10`)。
|
|
122
|
+
- `--login-retry=never|once|always`:控制登录失效后的重试策略。
|
|
123
|
+
- `--login-retry-timeout=<ms>`:交互重试等待超时(默认 `30000`)。
|
|
124
|
+
|
|
125
|
+
当检测到以下场景时,会自动启用非交互模式:
|
|
126
|
+
|
|
127
|
+
- `CI=true`
|
|
128
|
+
- `stdin` 非 TTY
|
|
129
|
+
|
|
113
130
|
## 常见问题
|
|
114
131
|
|
|
115
132
|
- **命令执行后无反应**:请确认微信开发者工具已开启服务端口,并尝试重新登录或升级工具版本。
|
|
133
|
+
- **提示 `需要重新登录` 或 `code: 10`**:表示微信开发者工具登录态失效。交互模式下可按 `r` 重试,按 `q`、`Esc` 或 `Ctrl+C` 取消;非交互模式(含 CI / 非TTY)会直接失败返回非 0。
|
|
116
134
|
- **提示未找到 CLI**:检查配置文件中的路径是否真实存在,可使用绝对路径避免解析误差。
|
|
117
135
|
- **Linux 环境报错**:需安装社区版工具并将 `wechat-devtools-cli` 加入 `PATH`,否则只能手动指定路径。
|
|
118
136
|
|
|
@@ -0,0 +1,661 @@
|
|
|
1
|
+
// src/logger.ts
|
|
2
|
+
import logger, { colors } from "@weapp-core/logger";
|
|
3
|
+
var logger_default = logger;
|
|
4
|
+
|
|
5
|
+
// src/utils/path.ts
|
|
6
|
+
import process from "process";
|
|
7
|
+
import path from "pathe";
|
|
8
|
+
function resolvePath(filePath) {
|
|
9
|
+
if (path.isAbsolute(filePath)) {
|
|
10
|
+
return filePath;
|
|
11
|
+
}
|
|
12
|
+
return path.resolve(process.cwd(), filePath);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// src/utils/argv.ts
|
|
16
|
+
import process2 from "process";
|
|
17
|
+
function ensurePathArgument(argv, optionIndex) {
|
|
18
|
+
const paramIdx = optionIndex + 1;
|
|
19
|
+
const param = argv[paramIdx];
|
|
20
|
+
if (param && !param.startsWith("-")) {
|
|
21
|
+
argv[paramIdx] = resolvePath(param);
|
|
22
|
+
} else {
|
|
23
|
+
argv.splice(paramIdx, 0, process2.cwd());
|
|
24
|
+
}
|
|
25
|
+
return argv;
|
|
26
|
+
}
|
|
27
|
+
function transformArgv(argv, transforms) {
|
|
28
|
+
return transforms.reduce((current, transform) => transform(current), [
|
|
29
|
+
...argv
|
|
30
|
+
]);
|
|
31
|
+
}
|
|
32
|
+
function createAlias(entry) {
|
|
33
|
+
return (input2) => {
|
|
34
|
+
const argv = [...input2];
|
|
35
|
+
let optionIndex = argv.indexOf(entry.find);
|
|
36
|
+
if (optionIndex > -1) {
|
|
37
|
+
argv.splice(optionIndex, 1, entry.replacement);
|
|
38
|
+
} else {
|
|
39
|
+
optionIndex = argv.indexOf(entry.replacement);
|
|
40
|
+
}
|
|
41
|
+
if (optionIndex === -1) {
|
|
42
|
+
return argv;
|
|
43
|
+
}
|
|
44
|
+
return ensurePathArgument(argv, optionIndex);
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function createPathCompat(option) {
|
|
48
|
+
return (input2) => {
|
|
49
|
+
const argv = [...input2];
|
|
50
|
+
const optionIndex = argv.indexOf(option);
|
|
51
|
+
if (optionIndex === -1) {
|
|
52
|
+
return argv;
|
|
53
|
+
}
|
|
54
|
+
return ensurePathArgument(argv, optionIndex);
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// src/utils/exec.ts
|
|
59
|
+
import process3 from "process";
|
|
60
|
+
async function execute(cliPath, argv, options = {}) {
|
|
61
|
+
const {
|
|
62
|
+
pipeStdout = true,
|
|
63
|
+
pipeStderr = true
|
|
64
|
+
} = options;
|
|
65
|
+
const { execa } = await import("execa");
|
|
66
|
+
const task = execa(cliPath, argv);
|
|
67
|
+
if (pipeStdout) {
|
|
68
|
+
task?.stdout?.pipe(process3.stdout);
|
|
69
|
+
}
|
|
70
|
+
if (pipeStderr) {
|
|
71
|
+
task?.stderr?.pipe(process3.stderr);
|
|
72
|
+
}
|
|
73
|
+
return await task;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// src/cli/minidev.ts
|
|
77
|
+
var MINIDEV_COMMAND = "minidev";
|
|
78
|
+
function isCommandNotFound(error) {
|
|
79
|
+
return Boolean(
|
|
80
|
+
error && typeof error === "object" && "code" in error && error.code === "ENOENT"
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
async function runMinidev(argv) {
|
|
84
|
+
try {
|
|
85
|
+
await execute(MINIDEV_COMMAND, [...argv]);
|
|
86
|
+
} catch (error) {
|
|
87
|
+
if (isCommandNotFound(error)) {
|
|
88
|
+
logger_default.error("\u672A\u68C0\u6D4B\u5230\u652F\u4ED8\u5B9D\u5C0F\u7A0B\u5E8F CLI\uFF1Aminidev");
|
|
89
|
+
logger_default.warn("\u8BF7\u5148\u5B89\u88C5 minidev\uFF0C\u53EF\u4F7F\u7528\u4EE5\u4E0B\u4EFB\u4E00\u547D\u4EE4\uFF1A");
|
|
90
|
+
logger_default.info(`- ${colors.green("pnpm add -g minidev")}`);
|
|
91
|
+
logger_default.info(`- ${colors.green("npm install -g minidev")}`);
|
|
92
|
+
logger_default.info(`- ${colors.green("yarn global add minidev")}`);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
throw error;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// src/config/paths.ts
|
|
100
|
+
import os from "os";
|
|
101
|
+
import path2 from "pathe";
|
|
102
|
+
var homedir = os.homedir();
|
|
103
|
+
var defaultCustomConfigDirPath = path2.join(homedir, ".weapp-ide-cli");
|
|
104
|
+
var defaultCustomConfigFilePath = path2.join(
|
|
105
|
+
defaultCustomConfigDirPath,
|
|
106
|
+
"config.json"
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
// src/config/custom.ts
|
|
110
|
+
import fs from "fs-extra";
|
|
111
|
+
var JSON_OPTIONS = {
|
|
112
|
+
encoding: "utf8",
|
|
113
|
+
spaces: 2
|
|
114
|
+
};
|
|
115
|
+
async function createCustomConfig(params) {
|
|
116
|
+
const trimmedCliPath = params.cliPath.trim();
|
|
117
|
+
if (!trimmedCliPath) {
|
|
118
|
+
throw new Error("cliPath cannot be empty");
|
|
119
|
+
}
|
|
120
|
+
const normalizedCliPath = resolvePath(trimmedCliPath);
|
|
121
|
+
await fs.ensureDir(defaultCustomConfigDirPath);
|
|
122
|
+
await fs.writeJSON(
|
|
123
|
+
defaultCustomConfigFilePath,
|
|
124
|
+
{
|
|
125
|
+
cliPath: normalizedCliPath
|
|
126
|
+
},
|
|
127
|
+
JSON_OPTIONS
|
|
128
|
+
);
|
|
129
|
+
return normalizedCliPath;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// src/cli/prompt.ts
|
|
133
|
+
import { stdin as input, stdout as output } from "process";
|
|
134
|
+
import { createInterface } from "readline/promises";
|
|
135
|
+
import fs2 from "fs-extra";
|
|
136
|
+
async function promptForCliPath() {
|
|
137
|
+
const rl = createInterface({ input, output });
|
|
138
|
+
try {
|
|
139
|
+
logger_default.info(`\u8BF7\u8BBE\u7F6E ${colors.bold("\u5FAE\u4FE1web\u5F00\u53D1\u8005\u5DE5\u5177 CLI")} \u7684\u8DEF\u5F84`);
|
|
140
|
+
logger_default.info("\u63D0\u793A\uFF1A\u547D\u4EE4\u884C\u5DE5\u5177\u9ED8\u8BA4\u6240\u5728\u4F4D\u7F6E\uFF1A");
|
|
141
|
+
logger_default.info(`- MacOS: ${colors.green("<\u5B89\u88C5\u8DEF\u5F84>/Contents/MacOS/cli")}`);
|
|
142
|
+
logger_default.info(`- Windows: ${colors.green("<\u5B89\u88C5\u8DEF\u5F84>/cli.bat")}`);
|
|
143
|
+
logger_default.info(`- Linux: ${colors.green("<\u5B89\u88C5\u8DEF\u5F84>/files/bin/bin/wechat-devtools-cli")}`);
|
|
144
|
+
const cliPath = (await rl.question("\u8BF7\u8F93\u5165\u5FAE\u4FE1web\u5F00\u53D1\u8005\u5DE5\u5177 CLI \u8DEF\u5F84\uFF1A")).trim();
|
|
145
|
+
if (!cliPath) {
|
|
146
|
+
logger_default.error("\u8DEF\u5F84\u4E0D\u80FD\u4E3A\u7A7A\uFF0C\u5DF2\u53D6\u6D88\u672C\u6B21\u914D\u7F6E\u3002");
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
try {
|
|
150
|
+
const normalizedPath = await createCustomConfig({ cliPath });
|
|
151
|
+
logger_default.info(`\u5168\u5C40\u914D\u7F6E\u5B58\u50A8\u4F4D\u7F6E\uFF1A${colors.green(defaultCustomConfigFilePath)}`);
|
|
152
|
+
if (!await fs2.pathExists(normalizedPath)) {
|
|
153
|
+
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");
|
|
154
|
+
}
|
|
155
|
+
return normalizedPath;
|
|
156
|
+
} catch (error) {
|
|
157
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
158
|
+
logger_default.error(`\u4FDD\u5B58\u914D\u7F6E\u5931\u8D25\uFF1A${reason}`);
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
} finally {
|
|
162
|
+
rl.close();
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// src/runtime/platform.ts
|
|
167
|
+
import os2 from "os";
|
|
168
|
+
import process4 from "process";
|
|
169
|
+
import fs3 from "fs-extra";
|
|
170
|
+
import path3 from "pathe";
|
|
171
|
+
var SupportedPlatformsMap = {
|
|
172
|
+
Windows_NT: "Windows_NT",
|
|
173
|
+
Darwin: "Darwin",
|
|
174
|
+
Linux: "Linux"
|
|
175
|
+
};
|
|
176
|
+
function isOperatingSystemSupported(osName = os2.type()) {
|
|
177
|
+
return osName === SupportedPlatformsMap.Windows_NT || osName === SupportedPlatformsMap.Darwin || osName === SupportedPlatformsMap.Linux;
|
|
178
|
+
}
|
|
179
|
+
var operatingSystemName = os2.type();
|
|
180
|
+
function createLinuxCliResolver() {
|
|
181
|
+
let resolvedPath;
|
|
182
|
+
let attempted = false;
|
|
183
|
+
let pending = null;
|
|
184
|
+
return async () => {
|
|
185
|
+
if (attempted) {
|
|
186
|
+
return resolvedPath;
|
|
187
|
+
}
|
|
188
|
+
if (!pending) {
|
|
189
|
+
pending = (async () => {
|
|
190
|
+
try {
|
|
191
|
+
const envPath = await getFirstBinaryPath("wechat-devtools-cli");
|
|
192
|
+
if (envPath) {
|
|
193
|
+
resolvedPath = envPath;
|
|
194
|
+
}
|
|
195
|
+
} catch (error) {
|
|
196
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
197
|
+
logger_default.warn(`\u83B7\u53D6 Linux wechat-devtools-cli \u8DEF\u5F84\u5931\u8D25\uFF1A${reason}`);
|
|
198
|
+
} finally {
|
|
199
|
+
attempted = true;
|
|
200
|
+
}
|
|
201
|
+
return resolvedPath;
|
|
202
|
+
})();
|
|
203
|
+
}
|
|
204
|
+
return pending;
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
var linuxCliResolver = createLinuxCliResolver();
|
|
208
|
+
var WINDOWS_DEFAULT_CLI = "C:\\Program Files (x86)\\Tencent\\\u5FAE\u4FE1web\u5F00\u53D1\u8005\u5DE5\u5177\\cli.bat";
|
|
209
|
+
var DARWIN_DEFAULT_CLI = "/Applications/wechatwebdevtools.app/Contents/MacOS/cli";
|
|
210
|
+
var cliPathResolvers = {
|
|
211
|
+
[SupportedPlatformsMap.Windows_NT]: async () => WINDOWS_DEFAULT_CLI,
|
|
212
|
+
[SupportedPlatformsMap.Darwin]: async () => DARWIN_DEFAULT_CLI,
|
|
213
|
+
[SupportedPlatformsMap.Linux]: linuxCliResolver
|
|
214
|
+
};
|
|
215
|
+
async function getDefaultCliPath(targetOs = operatingSystemName) {
|
|
216
|
+
if (!isOperatingSystemSupported(targetOs)) {
|
|
217
|
+
return void 0;
|
|
218
|
+
}
|
|
219
|
+
const resolver = cliPathResolvers[targetOs];
|
|
220
|
+
const resolvedPath = await resolver();
|
|
221
|
+
return resolvedPath;
|
|
222
|
+
}
|
|
223
|
+
async function getFirstBinaryPath(command) {
|
|
224
|
+
const envPath = process4.env.PATH || "";
|
|
225
|
+
const pathDirs = envPath.split(path3.delimiter);
|
|
226
|
+
for (const dir of pathDirs) {
|
|
227
|
+
const fullPath = path3.join(dir, command);
|
|
228
|
+
try {
|
|
229
|
+
await fs3.access(fullPath, fs3.constants.X_OK);
|
|
230
|
+
return fullPath;
|
|
231
|
+
} catch {
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return void 0;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// src/config/resolver.ts
|
|
239
|
+
import fs4 from "fs-extra";
|
|
240
|
+
async function getConfig() {
|
|
241
|
+
if (await fs4.pathExists(defaultCustomConfigFilePath)) {
|
|
242
|
+
try {
|
|
243
|
+
const config = await fs4.readJSON(defaultCustomConfigFilePath);
|
|
244
|
+
const cliPath = typeof config.cliPath === "string" ? config.cliPath.trim() : "";
|
|
245
|
+
if (cliPath) {
|
|
246
|
+
logger_default.info(`\u5168\u5C40\u914D\u7F6E\u6587\u4EF6\u8DEF\u5F84\uFF1A${colors.green(defaultCustomConfigFilePath)}`);
|
|
247
|
+
logger_default.info(`\u81EA\u5B9A\u4E49 CLI \u8DEF\u5F84\uFF1A${colors.green(cliPath)}`);
|
|
248
|
+
return {
|
|
249
|
+
cliPath,
|
|
250
|
+
source: "custom"
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
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");
|
|
254
|
+
} catch (error) {
|
|
255
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
256
|
+
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}`);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
const fallbackPath = await getDefaultCliPath();
|
|
260
|
+
if (fallbackPath) {
|
|
261
|
+
return {
|
|
262
|
+
cliPath: fallbackPath,
|
|
263
|
+
source: "default"
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
return {
|
|
267
|
+
cliPath: "",
|
|
268
|
+
source: "missing"
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// src/cli/resolver.ts
|
|
273
|
+
import fs5 from "fs-extra";
|
|
274
|
+
async function resolveCliPath() {
|
|
275
|
+
const config = await getConfig();
|
|
276
|
+
if (!config.cliPath) {
|
|
277
|
+
return { cliPath: null, source: config.source };
|
|
278
|
+
}
|
|
279
|
+
const exists = await fs5.pathExists(config.cliPath);
|
|
280
|
+
return {
|
|
281
|
+
cliPath: exists ? config.cliPath : null,
|
|
282
|
+
source: config.source
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// src/cli/retry.ts
|
|
287
|
+
import process5 from "process";
|
|
288
|
+
import { emitKeypressEvents } from "readline";
|
|
289
|
+
var LOGIN_REQUIRED_PATTERNS = [
|
|
290
|
+
/code\s*[:=]\s*10/i,
|
|
291
|
+
/需要重新登录/,
|
|
292
|
+
/need\s+re-?login/i,
|
|
293
|
+
/re-?login/i
|
|
294
|
+
];
|
|
295
|
+
function isWechatIdeLoginRequiredError(error) {
|
|
296
|
+
const text = extractExecutionErrorText(error);
|
|
297
|
+
if (!text) {
|
|
298
|
+
return false;
|
|
299
|
+
}
|
|
300
|
+
return LOGIN_REQUIRED_PATTERNS.some((pattern) => pattern.test(text));
|
|
301
|
+
}
|
|
302
|
+
function extractExecutionErrorText(error) {
|
|
303
|
+
if (!error || typeof error !== "object") {
|
|
304
|
+
return "";
|
|
305
|
+
}
|
|
306
|
+
const parts = [];
|
|
307
|
+
const candidate = error;
|
|
308
|
+
for (const field of [candidate.message, candidate.shortMessage, candidate.stderr, candidate.stdout]) {
|
|
309
|
+
if (typeof field === "string" && field.trim()) {
|
|
310
|
+
parts.push(field);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
return parts.join("\n");
|
|
314
|
+
}
|
|
315
|
+
function formatWechatIdeLoginRequiredError(error) {
|
|
316
|
+
const text = extractExecutionErrorText(error);
|
|
317
|
+
const code = text.match(/code\s*[:=]\s*(\d+)/i)?.[1];
|
|
318
|
+
const message = extractLoginRequiredMessage(text);
|
|
319
|
+
const lines = ["\u5FAE\u4FE1\u5F00\u53D1\u8005\u5DE5\u5177\u8FD4\u56DE\u767B\u5F55\u9519\u8BEF\uFF1A"];
|
|
320
|
+
if (code) {
|
|
321
|
+
lines.push(`- code: ${code}`);
|
|
322
|
+
}
|
|
323
|
+
if (message) {
|
|
324
|
+
lines.push(`- message: ${message}`);
|
|
325
|
+
}
|
|
326
|
+
if (!code && !message) {
|
|
327
|
+
lines.push("- message: \u9700\u8981\u91CD\u65B0\u767B\u5F55");
|
|
328
|
+
}
|
|
329
|
+
return lines.join("\n");
|
|
330
|
+
}
|
|
331
|
+
function createWechatIdeLoginRequiredExitError(error, reason) {
|
|
332
|
+
const summary = formatWechatIdeLoginRequiredError(error);
|
|
333
|
+
const message = reason ? `${reason}
|
|
334
|
+
${summary}` : summary;
|
|
335
|
+
const loginError = new Error(message);
|
|
336
|
+
loginError.name = "WechatIdeLoginRequiredError";
|
|
337
|
+
loginError.code = 10;
|
|
338
|
+
loginError.exitCode = 10;
|
|
339
|
+
return loginError;
|
|
340
|
+
}
|
|
341
|
+
function extractLoginRequiredMessage(text) {
|
|
342
|
+
if (!text) {
|
|
343
|
+
return "";
|
|
344
|
+
}
|
|
345
|
+
if (/需要重新登录/.test(text)) {
|
|
346
|
+
return "\u9700\u8981\u91CD\u65B0\u767B\u5F55";
|
|
347
|
+
}
|
|
348
|
+
const englishMatch = text.match(/need\s+re-?login|re-?login/i);
|
|
349
|
+
if (englishMatch?.[0]) {
|
|
350
|
+
return englishMatch[0].toLowerCase();
|
|
351
|
+
}
|
|
352
|
+
const firstLine = text.split(/\r?\n/).map((line) => line.trim()).find((line) => Boolean(line) && !line.startsWith("at "));
|
|
353
|
+
if (!firstLine) {
|
|
354
|
+
return "";
|
|
355
|
+
}
|
|
356
|
+
return firstLine.replace(/^\[error\]\s*/i, "").replace(/^error\s*:\s*/i, "").slice(0, 120);
|
|
357
|
+
}
|
|
358
|
+
async function waitForRetryKeypress(options = {}) {
|
|
359
|
+
const { timeoutMs = 3e4 } = options;
|
|
360
|
+
if (!process5.stdin.isTTY) {
|
|
361
|
+
return "cancel";
|
|
362
|
+
}
|
|
363
|
+
emitKeypressEvents(process5.stdin);
|
|
364
|
+
const hasSetRawMode = typeof process5.stdin.setRawMode === "function";
|
|
365
|
+
if (hasSetRawMode) {
|
|
366
|
+
process5.stdin.setRawMode(true);
|
|
367
|
+
}
|
|
368
|
+
process5.stdin.resume();
|
|
369
|
+
return new Promise((resolve) => {
|
|
370
|
+
let settled = false;
|
|
371
|
+
const normalizedTimeoutMs = Number.isFinite(timeoutMs) && timeoutMs > 0 ? timeoutMs : 3e4;
|
|
372
|
+
const timeout = setTimeout(() => {
|
|
373
|
+
done("timeout");
|
|
374
|
+
}, normalizedTimeoutMs);
|
|
375
|
+
const cleanup = () => {
|
|
376
|
+
clearTimeout(timeout);
|
|
377
|
+
process5.stdin.off("keypress", onKeypress);
|
|
378
|
+
if (hasSetRawMode) {
|
|
379
|
+
process5.stdin.setRawMode(false);
|
|
380
|
+
}
|
|
381
|
+
process5.stdin.pause();
|
|
382
|
+
};
|
|
383
|
+
const done = (value) => {
|
|
384
|
+
if (settled) {
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
settled = true;
|
|
388
|
+
cleanup();
|
|
389
|
+
resolve(value);
|
|
390
|
+
};
|
|
391
|
+
const onKeypress = (_str, key) => {
|
|
392
|
+
if (!key) {
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
if (key.ctrl && key.name === "c") {
|
|
396
|
+
done("cancel");
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
if (key.name === "r") {
|
|
400
|
+
done("retry");
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
if (key.name === "q" || key.name === "escape") {
|
|
404
|
+
done("cancel");
|
|
405
|
+
}
|
|
406
|
+
};
|
|
407
|
+
process5.stdin.on("keypress", onKeypress);
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
function formatRetryHotkeyPrompt(timeoutMs = 3e4) {
|
|
411
|
+
const highlight = (key) => highlightHotkey(key);
|
|
412
|
+
const timeoutSeconds = Math.max(1, Math.ceil(timeoutMs / 1e3));
|
|
413
|
+
return `\u6309 ${highlight("r")} \u91CD\u8BD5\uFF0C\u6309 ${highlight("q")} / ${highlight("Esc")} / ${highlight("Ctrl+C")} \u9000\u51FA\uFF08${timeoutSeconds}s \u5185\u65E0\u8F93\u5165\u5C06\u81EA\u52A8\u5931\u8D25\uFF09\u3002`;
|
|
414
|
+
}
|
|
415
|
+
function highlightHotkey(key) {
|
|
416
|
+
return colors.bold(colors.green(key));
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
// src/cli/run.ts
|
|
420
|
+
import process6 from "process";
|
|
421
|
+
var MINIDEV_NAMESPACE = /* @__PURE__ */ new Set(["alipay", "ali", "minidev"]);
|
|
422
|
+
var ALIPAY_PLATFORM_ALIASES = /* @__PURE__ */ new Set(["alipay", "ali", "minidev"]);
|
|
423
|
+
function isStdinInteractive() {
|
|
424
|
+
return Boolean(process6.stdin && process6.stdin.isTTY);
|
|
425
|
+
}
|
|
426
|
+
var ARG_TRANSFORMS = [
|
|
427
|
+
createAlias({ find: "-p", replacement: "--project" }),
|
|
428
|
+
createPathCompat("--result-output"),
|
|
429
|
+
createPathCompat("-r"),
|
|
430
|
+
createPathCompat("--qr-output"),
|
|
431
|
+
createPathCompat("-o"),
|
|
432
|
+
createPathCompat("--info-output"),
|
|
433
|
+
createPathCompat("-i")
|
|
434
|
+
];
|
|
435
|
+
async function parse(argv) {
|
|
436
|
+
const head = argv[0];
|
|
437
|
+
if (head && MINIDEV_NAMESPACE.has(head)) {
|
|
438
|
+
await runMinidev(argv.slice(1));
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
const formattedArgv = transformArgv(argv, ARG_TRANSFORMS);
|
|
442
|
+
const loginRetryOptions = resolveLoginRetryOptions(formattedArgv);
|
|
443
|
+
const runtimeArgv = stripLoginRetryControlFlags(formattedArgv);
|
|
444
|
+
if (shouldDelegateOpenToMinidev(runtimeArgv)) {
|
|
445
|
+
await runMinidev(createMinidevOpenArgv(runtimeArgv));
|
|
446
|
+
return;
|
|
447
|
+
}
|
|
448
|
+
if (!isOperatingSystemSupported(operatingSystemName)) {
|
|
449
|
+
logger_default.warn(`\u5FAE\u4FE1web\u5F00\u53D1\u8005\u5DE5\u5177\u4E0D\u652F\u6301\u5F53\u524D\u5E73\u53F0\uFF1A${operatingSystemName} !`);
|
|
450
|
+
return;
|
|
451
|
+
}
|
|
452
|
+
if (head === "config") {
|
|
453
|
+
await promptForCliPath();
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
456
|
+
const { cliPath, source } = await resolveCliPath();
|
|
457
|
+
if (!cliPath) {
|
|
458
|
+
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 ${colors.bold(colors.green("weapp-ide-cli config"))} \u6307\u5B9A\u8DEF\u5F84\u3002`;
|
|
459
|
+
logger_default.warn(message);
|
|
460
|
+
await promptForCliPath();
|
|
461
|
+
return;
|
|
462
|
+
}
|
|
463
|
+
await runWechatCliWithRetry(cliPath, runtimeArgv, loginRetryOptions);
|
|
464
|
+
}
|
|
465
|
+
async function runWechatCliWithRetry(cliPath, argv, options) {
|
|
466
|
+
let retryCount = 0;
|
|
467
|
+
while (true) {
|
|
468
|
+
try {
|
|
469
|
+
const result = await execute(cliPath, argv, {
|
|
470
|
+
pipeStdout: false,
|
|
471
|
+
pipeStderr: false
|
|
472
|
+
});
|
|
473
|
+
if (!isWechatIdeLoginRequiredError(result)) {
|
|
474
|
+
flushExecutionOutput(result);
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
477
|
+
const action = await promptLoginRetry(result, options, retryCount);
|
|
478
|
+
if (action === "retry") {
|
|
479
|
+
retryCount += 1;
|
|
480
|
+
logger_default.info("\u6B63\u5728\u91CD\u8BD5\u8FDE\u63A5\u5FAE\u4FE1\u5F00\u53D1\u8005\u5DE5\u5177...");
|
|
481
|
+
continue;
|
|
482
|
+
}
|
|
483
|
+
throw createWechatIdeLoginRequiredExitError(result);
|
|
484
|
+
} catch (error) {
|
|
485
|
+
if (!isWechatIdeLoginRequiredError(error)) {
|
|
486
|
+
throw error;
|
|
487
|
+
}
|
|
488
|
+
const action = await promptLoginRetry(error, options, retryCount);
|
|
489
|
+
if (action === "retry") {
|
|
490
|
+
retryCount += 1;
|
|
491
|
+
logger_default.info("\u6B63\u5728\u91CD\u8BD5\u8FDE\u63A5\u5FAE\u4FE1\u5F00\u53D1\u8005\u5DE5\u5177...");
|
|
492
|
+
continue;
|
|
493
|
+
}
|
|
494
|
+
throw createWechatIdeLoginRequiredExitError(error);
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
async function promptLoginRetry(errorLike, options, retryCount) {
|
|
499
|
+
const {
|
|
500
|
+
nonInteractive,
|
|
501
|
+
retryMode,
|
|
502
|
+
retryTimeoutMs
|
|
503
|
+
} = options;
|
|
504
|
+
logger_default.error("\u68C0\u6D4B\u5230\u5FAE\u4FE1\u5F00\u53D1\u8005\u5DE5\u5177\u767B\u5F55\u72B6\u6001\u5931\u6548\uFF0C\u8BF7\u5148\u767B\u5F55\u540E\u91CD\u8BD5\u3002");
|
|
505
|
+
logger_default.warn("\u8BF7\u5148\u6253\u5F00\u5FAE\u4FE1\u5F00\u53D1\u8005\u5DE5\u5177\u5B8C\u6210\u767B\u5F55\u3002");
|
|
506
|
+
logger_default.warn(formatWechatIdeLoginRequiredError(errorLike));
|
|
507
|
+
if (nonInteractive) {
|
|
508
|
+
logger_default.error("\u5F53\u524D\u4E3A\u975E\u4EA4\u4E92\u6A21\u5F0F\uFF0C\u68C0\u6D4B\u5230\u767B\u5F55\u5931\u6548\u540E\u76F4\u63A5\u5931\u8D25\u3002");
|
|
509
|
+
return "cancel";
|
|
510
|
+
}
|
|
511
|
+
const shouldAllowRetry = retryMode === "always" || retryMode === "once" && retryCount < 1;
|
|
512
|
+
if (!shouldAllowRetry) {
|
|
513
|
+
logger_default.info("\u5F53\u524D\u91CD\u8BD5\u7B56\u7565\u4E0D\u5141\u8BB8\u7EE7\u7EED\u91CD\u8BD5\u3002");
|
|
514
|
+
return "cancel";
|
|
515
|
+
}
|
|
516
|
+
logger_default.info(formatRetryHotkeyPrompt(retryTimeoutMs));
|
|
517
|
+
const action = await waitForRetryKeypress({ timeoutMs: retryTimeoutMs });
|
|
518
|
+
if (action === "timeout") {
|
|
519
|
+
logger_default.error(`\u7B49\u5F85\u767B\u5F55\u91CD\u8BD5\u8F93\u5165\u8D85\u65F6\uFF08${retryTimeoutMs}ms\uFF09\uFF0C\u5DF2\u81EA\u52A8\u53D6\u6D88\u3002`);
|
|
520
|
+
return "cancel";
|
|
521
|
+
}
|
|
522
|
+
if (action !== "retry") {
|
|
523
|
+
logger_default.info("\u5DF2\u53D6\u6D88\u91CD\u8BD5\u3002\u5B8C\u6210\u767B\u5F55\u540E\u8BF7\u91CD\u65B0\u6267\u884C\u5F53\u524D\u547D\u4EE4\u3002");
|
|
524
|
+
return "cancel";
|
|
525
|
+
}
|
|
526
|
+
return "retry";
|
|
527
|
+
}
|
|
528
|
+
function resolveLoginRetryOptions(argv) {
|
|
529
|
+
const nonInteractiveFlag = readBooleanFlag(argv, "--non-interactive");
|
|
530
|
+
const ciMode = process6.env.CI === "true";
|
|
531
|
+
const nonTtyStdin = !isStdinInteractive();
|
|
532
|
+
const nonInteractive = nonInteractiveFlag || ciMode || nonTtyStdin;
|
|
533
|
+
const retryModeRaw = readOptionValue(argv, "--login-retry");
|
|
534
|
+
const retryMode = normalizeLoginRetryMode(retryModeRaw, nonInteractive);
|
|
535
|
+
const retryTimeoutRaw = readOptionValue(argv, "--login-retry-timeout");
|
|
536
|
+
const retryTimeoutMs = normalizeLoginRetryTimeout(retryTimeoutRaw);
|
|
537
|
+
return {
|
|
538
|
+
nonInteractive,
|
|
539
|
+
retryMode,
|
|
540
|
+
retryTimeoutMs
|
|
541
|
+
};
|
|
542
|
+
}
|
|
543
|
+
function normalizeLoginRetryMode(value, nonInteractive) {
|
|
544
|
+
if (value === "never" || value === "once" || value === "always") {
|
|
545
|
+
return value;
|
|
546
|
+
}
|
|
547
|
+
return nonInteractive ? "never" : "always";
|
|
548
|
+
}
|
|
549
|
+
function normalizeLoginRetryTimeout(value) {
|
|
550
|
+
if (!value) {
|
|
551
|
+
return 3e4;
|
|
552
|
+
}
|
|
553
|
+
const parsed = Number.parseInt(value, 10);
|
|
554
|
+
if (!Number.isFinite(parsed) || parsed <= 0) {
|
|
555
|
+
return 3e4;
|
|
556
|
+
}
|
|
557
|
+
return parsed;
|
|
558
|
+
}
|
|
559
|
+
function readBooleanFlag(argv, optionName) {
|
|
560
|
+
return argv.includes(optionName);
|
|
561
|
+
}
|
|
562
|
+
function stripLoginRetryControlFlags(argv) {
|
|
563
|
+
let next = removeOption(argv, "--login-retry");
|
|
564
|
+
next = removeOption(next, "--login-retry-timeout");
|
|
565
|
+
next = removeOption(next, "--non-interactive");
|
|
566
|
+
return next;
|
|
567
|
+
}
|
|
568
|
+
function shouldDelegateOpenToMinidev(argv) {
|
|
569
|
+
if (argv[0] !== "open") {
|
|
570
|
+
return false;
|
|
571
|
+
}
|
|
572
|
+
const platform = readOptionValue(argv, "--platform");
|
|
573
|
+
if (!platform) {
|
|
574
|
+
return false;
|
|
575
|
+
}
|
|
576
|
+
return ALIPAY_PLATFORM_ALIASES.has(platform);
|
|
577
|
+
}
|
|
578
|
+
function createMinidevOpenArgv(argv) {
|
|
579
|
+
const nextArgv = [...argv];
|
|
580
|
+
nextArgv[0] = "ide";
|
|
581
|
+
return removeOption(nextArgv, "--platform");
|
|
582
|
+
}
|
|
583
|
+
function readOptionValue(argv, optionName) {
|
|
584
|
+
const optionWithEqual = `${optionName}=`;
|
|
585
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
586
|
+
const token = argv[index];
|
|
587
|
+
if (!token) {
|
|
588
|
+
continue;
|
|
589
|
+
}
|
|
590
|
+
if (token === optionName) {
|
|
591
|
+
const value = argv[index + 1];
|
|
592
|
+
return typeof value === "string" ? value.trim().toLowerCase() : void 0;
|
|
593
|
+
}
|
|
594
|
+
if (token.startsWith(optionWithEqual)) {
|
|
595
|
+
const value = token.slice(optionWithEqual.length);
|
|
596
|
+
return value.trim().toLowerCase();
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
return void 0;
|
|
600
|
+
}
|
|
601
|
+
function removeOption(argv, optionName) {
|
|
602
|
+
const optionWithEqual = `${optionName}=`;
|
|
603
|
+
const nextArgv = [];
|
|
604
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
605
|
+
const token = argv[index];
|
|
606
|
+
if (!token) {
|
|
607
|
+
continue;
|
|
608
|
+
}
|
|
609
|
+
if (token === optionName) {
|
|
610
|
+
const nextToken = argv[index + 1];
|
|
611
|
+
if (nextToken && !nextToken.startsWith("-")) {
|
|
612
|
+
index += 1;
|
|
613
|
+
}
|
|
614
|
+
continue;
|
|
615
|
+
}
|
|
616
|
+
if (token.startsWith(optionWithEqual)) {
|
|
617
|
+
continue;
|
|
618
|
+
}
|
|
619
|
+
nextArgv.push(token);
|
|
620
|
+
}
|
|
621
|
+
return nextArgv;
|
|
622
|
+
}
|
|
623
|
+
function flushExecutionOutput(result) {
|
|
624
|
+
if (!result || typeof result !== "object") {
|
|
625
|
+
return;
|
|
626
|
+
}
|
|
627
|
+
const candidate = result;
|
|
628
|
+
if (typeof candidate.stdout === "string" && candidate.stdout) {
|
|
629
|
+
process6.stdout.write(candidate.stdout);
|
|
630
|
+
}
|
|
631
|
+
if (typeof candidate.stderr === "string" && candidate.stderr) {
|
|
632
|
+
process6.stderr.write(candidate.stderr);
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
export {
|
|
637
|
+
logger_default,
|
|
638
|
+
resolvePath,
|
|
639
|
+
transformArgv,
|
|
640
|
+
createAlias,
|
|
641
|
+
createPathCompat,
|
|
642
|
+
execute,
|
|
643
|
+
runMinidev,
|
|
644
|
+
defaultCustomConfigDirPath,
|
|
645
|
+
defaultCustomConfigFilePath,
|
|
646
|
+
createCustomConfig,
|
|
647
|
+
promptForCliPath,
|
|
648
|
+
SupportedPlatformsMap,
|
|
649
|
+
isOperatingSystemSupported,
|
|
650
|
+
operatingSystemName,
|
|
651
|
+
getDefaultCliPath,
|
|
652
|
+
getConfig,
|
|
653
|
+
resolveCliPath,
|
|
654
|
+
isWechatIdeLoginRequiredError,
|
|
655
|
+
extractExecutionErrorText,
|
|
656
|
+
formatWechatIdeLoginRequiredError,
|
|
657
|
+
createWechatIdeLoginRequiredExitError,
|
|
658
|
+
waitForRetryKeypress,
|
|
659
|
+
formatRetryHotkeyPrompt,
|
|
660
|
+
parse
|
|
661
|
+
};
|
package/dist/cli.js
CHANGED
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
import {
|
|
2
2
|
logger_default,
|
|
3
3
|
parse
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-QTQD5BFV.js";
|
|
5
5
|
|
|
6
6
|
// src/cli.ts
|
|
7
7
|
import process from "process";
|
|
8
8
|
var argv = process.argv.slice(2);
|
|
9
9
|
parse(argv).catch((err) => {
|
|
10
10
|
logger_default.error(err);
|
|
11
|
+
if (typeof err?.exitCode === "number") {
|
|
12
|
+
process.exitCode = err.exitCode;
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
if (typeof err?.code === "number") {
|
|
16
|
+
process.exitCode = err.code;
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
process.exitCode = 1;
|
|
11
20
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import * as execa from 'execa';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* @description 运行支付宝小程序 CLI(minidev)
|
|
3
5
|
*/
|
|
@@ -16,6 +18,38 @@ declare function resolveCliPath(): Promise<{
|
|
|
16
18
|
source: ConfigSource;
|
|
17
19
|
}>;
|
|
18
20
|
|
|
21
|
+
interface RetryKeypressOptions {
|
|
22
|
+
timeoutMs?: number;
|
|
23
|
+
}
|
|
24
|
+
type RetryPromptResult = 'retry' | 'cancel' | 'timeout';
|
|
25
|
+
/**
|
|
26
|
+
* @description 判断是否为微信开发者工具登录失效错误。
|
|
27
|
+
*/
|
|
28
|
+
declare function isWechatIdeLoginRequiredError(error: unknown): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* @description 提取执行错误文本,便于统一匹配与提示。
|
|
31
|
+
*/
|
|
32
|
+
declare function extractExecutionErrorText(error: unknown): string;
|
|
33
|
+
/**
|
|
34
|
+
* @description 将登录失效错误格式化为更易读的摘要。
|
|
35
|
+
*/
|
|
36
|
+
declare function formatWechatIdeLoginRequiredError(error: unknown): string;
|
|
37
|
+
/**
|
|
38
|
+
* @description 创建登录失效专用错误,并携带退出码语义。
|
|
39
|
+
*/
|
|
40
|
+
declare function createWechatIdeLoginRequiredExitError(error: unknown, reason?: string): Error & {
|
|
41
|
+
code: number;
|
|
42
|
+
exitCode: number;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* @description 交互等待用户按键重试,按 r 重试,按 q 或 Ctrl+C 取消。
|
|
46
|
+
*/
|
|
47
|
+
declare function waitForRetryKeypress(options?: RetryKeypressOptions): Promise<RetryPromptResult>;
|
|
48
|
+
/**
|
|
49
|
+
* @description 生成重试按键提示,并高亮关键热键。
|
|
50
|
+
*/
|
|
51
|
+
declare function formatRetryHotkeyPrompt(timeoutMs?: number): string;
|
|
52
|
+
|
|
19
53
|
/**
|
|
20
54
|
* @description CLI 入口解析与分发
|
|
21
55
|
*/
|
|
@@ -107,14 +141,18 @@ declare function createAlias(entry: AliasEntry): ArgvTransform;
|
|
|
107
141
|
*/
|
|
108
142
|
declare function createPathCompat(option: string): ArgvTransform;
|
|
109
143
|
|
|
144
|
+
interface ExecuteOptions {
|
|
145
|
+
pipeStdout?: boolean;
|
|
146
|
+
pipeStderr?: boolean;
|
|
147
|
+
}
|
|
110
148
|
/**
|
|
111
149
|
* @description 执行 CLI 命令并透传输出
|
|
112
150
|
*/
|
|
113
|
-
declare function execute(cliPath: string, argv: string[]): Promise<
|
|
151
|
+
declare function execute(cliPath: string, argv: string[], options?: ExecuteOptions): Promise<execa.Result<{}>>;
|
|
114
152
|
|
|
115
153
|
/**
|
|
116
154
|
* @description 解析为绝对路径(基于当前工作目录)
|
|
117
155
|
*/
|
|
118
156
|
declare function resolvePath(filePath: string): string;
|
|
119
157
|
|
|
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 };
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -3,36 +3,48 @@ import {
|
|
|
3
3
|
createAlias,
|
|
4
4
|
createCustomConfig,
|
|
5
5
|
createPathCompat,
|
|
6
|
+
createWechatIdeLoginRequiredExitError,
|
|
6
7
|
defaultCustomConfigDirPath,
|
|
7
8
|
defaultCustomConfigFilePath,
|
|
8
9
|
execute,
|
|
10
|
+
extractExecutionErrorText,
|
|
11
|
+
formatRetryHotkeyPrompt,
|
|
12
|
+
formatWechatIdeLoginRequiredError,
|
|
9
13
|
getConfig,
|
|
10
14
|
getDefaultCliPath,
|
|
11
15
|
isOperatingSystemSupported,
|
|
16
|
+
isWechatIdeLoginRequiredError,
|
|
12
17
|
operatingSystemName,
|
|
13
18
|
parse,
|
|
14
19
|
promptForCliPath,
|
|
15
20
|
resolveCliPath,
|
|
16
21
|
resolvePath,
|
|
17
22
|
runMinidev,
|
|
18
|
-
transformArgv
|
|
19
|
-
|
|
23
|
+
transformArgv,
|
|
24
|
+
waitForRetryKeypress
|
|
25
|
+
} from "./chunk-QTQD5BFV.js";
|
|
20
26
|
export {
|
|
21
27
|
SupportedPlatformsMap,
|
|
22
28
|
createAlias,
|
|
23
29
|
createCustomConfig,
|
|
24
30
|
createPathCompat,
|
|
31
|
+
createWechatIdeLoginRequiredExitError,
|
|
25
32
|
defaultCustomConfigDirPath,
|
|
26
33
|
defaultCustomConfigFilePath,
|
|
27
34
|
execute,
|
|
35
|
+
extractExecutionErrorText,
|
|
36
|
+
formatRetryHotkeyPrompt,
|
|
37
|
+
formatWechatIdeLoginRequiredError,
|
|
28
38
|
getConfig,
|
|
29
39
|
getDefaultCliPath,
|
|
30
40
|
isOperatingSystemSupported,
|
|
41
|
+
isWechatIdeLoginRequiredError,
|
|
31
42
|
operatingSystemName,
|
|
32
43
|
parse,
|
|
33
44
|
promptForCliPath,
|
|
34
45
|
resolveCliPath,
|
|
35
46
|
resolvePath,
|
|
36
47
|
runMinidev,
|
|
37
|
-
transformArgv
|
|
48
|
+
transformArgv,
|
|
49
|
+
waitForRetryKeypress
|
|
38
50
|
};
|
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
|
+
"version": "5.0.4",
|
|
5
5
|
"description": "让微信开发者工具,用起来更加方便!",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"execa": "9.6.1",
|
|
66
66
|
"fs-extra": "^11.3.3",
|
|
67
67
|
"pathe": "^2.0.3",
|
|
68
|
-
"@weapp-core/logger": "^3.0
|
|
68
|
+
"@weapp-core/logger": "^3.1.0"
|
|
69
69
|
},
|
|
70
70
|
"scripts": {
|
|
71
71
|
"dev": "tsup --watch --sourcemap",
|
package/dist/chunk-DNENPZKW.js
DELETED
|
@@ -1,393 +0,0 @@
|
|
|
1
|
-
// src/logger.ts
|
|
2
|
-
import logger from "@weapp-core/logger";
|
|
3
|
-
var logger_default = logger;
|
|
4
|
-
|
|
5
|
-
// src/utils/path.ts
|
|
6
|
-
import process from "process";
|
|
7
|
-
import path from "pathe";
|
|
8
|
-
function resolvePath(filePath) {
|
|
9
|
-
if (path.isAbsolute(filePath)) {
|
|
10
|
-
return filePath;
|
|
11
|
-
}
|
|
12
|
-
return path.resolve(process.cwd(), filePath);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// src/utils/argv.ts
|
|
16
|
-
import process2 from "process";
|
|
17
|
-
function ensurePathArgument(argv, optionIndex) {
|
|
18
|
-
const paramIdx = optionIndex + 1;
|
|
19
|
-
const param = argv[paramIdx];
|
|
20
|
-
if (param && !param.startsWith("-")) {
|
|
21
|
-
argv[paramIdx] = resolvePath(param);
|
|
22
|
-
} else {
|
|
23
|
-
argv.splice(paramIdx, 0, process2.cwd());
|
|
24
|
-
}
|
|
25
|
-
return argv;
|
|
26
|
-
}
|
|
27
|
-
function transformArgv(argv, transforms) {
|
|
28
|
-
return transforms.reduce((current, transform) => transform(current), [
|
|
29
|
-
...argv
|
|
30
|
-
]);
|
|
31
|
-
}
|
|
32
|
-
function createAlias(entry) {
|
|
33
|
-
return (input2) => {
|
|
34
|
-
const argv = [...input2];
|
|
35
|
-
let optionIndex = argv.indexOf(entry.find);
|
|
36
|
-
if (optionIndex > -1) {
|
|
37
|
-
argv.splice(optionIndex, 1, entry.replacement);
|
|
38
|
-
} else {
|
|
39
|
-
optionIndex = argv.indexOf(entry.replacement);
|
|
40
|
-
}
|
|
41
|
-
if (optionIndex === -1) {
|
|
42
|
-
return argv;
|
|
43
|
-
}
|
|
44
|
-
return ensurePathArgument(argv, optionIndex);
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
function createPathCompat(option) {
|
|
48
|
-
return (input2) => {
|
|
49
|
-
const argv = [...input2];
|
|
50
|
-
const optionIndex = argv.indexOf(option);
|
|
51
|
-
if (optionIndex === -1) {
|
|
52
|
-
return argv;
|
|
53
|
-
}
|
|
54
|
-
return ensurePathArgument(argv, optionIndex);
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// src/utils/exec.ts
|
|
59
|
-
import process3 from "process";
|
|
60
|
-
async function execute(cliPath, argv) {
|
|
61
|
-
const { execa } = await import("execa");
|
|
62
|
-
const task = execa(cliPath, argv);
|
|
63
|
-
task?.stdout?.pipe(process3.stdout);
|
|
64
|
-
task?.stderr?.pipe(process3.stderr);
|
|
65
|
-
await task;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// src/cli/minidev.ts
|
|
69
|
-
var MINIDEV_COMMAND = "minidev";
|
|
70
|
-
function isCommandNotFound(error) {
|
|
71
|
-
return Boolean(
|
|
72
|
-
error && typeof error === "object" && "code" in error && error.code === "ENOENT"
|
|
73
|
-
);
|
|
74
|
-
}
|
|
75
|
-
async function runMinidev(argv) {
|
|
76
|
-
try {
|
|
77
|
-
await execute(MINIDEV_COMMAND, [...argv]);
|
|
78
|
-
} catch (error) {
|
|
79
|
-
if (isCommandNotFound(error)) {
|
|
80
|
-
logger_default.error("\u672A\u68C0\u6D4B\u5230\u652F\u4ED8\u5B9D\u5C0F\u7A0B\u5E8F CLI\uFF1Aminidev");
|
|
81
|
-
logger_default.log("\u8BF7\u5148\u5B89\u88C5 minidev\uFF0C\u53EF\u4F7F\u7528\u4EE5\u4E0B\u4EFB\u4E00\u547D\u4EE4\uFF1A");
|
|
82
|
-
logger_default.log("- pnpm add -g minidev");
|
|
83
|
-
logger_default.log("- npm install -g minidev");
|
|
84
|
-
logger_default.log("- yarn global add minidev");
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
throw error;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// src/config/paths.ts
|
|
92
|
-
import os from "os";
|
|
93
|
-
import path2 from "pathe";
|
|
94
|
-
var homedir = os.homedir();
|
|
95
|
-
var defaultCustomConfigDirPath = path2.join(homedir, ".weapp-ide-cli");
|
|
96
|
-
var defaultCustomConfigFilePath = path2.join(
|
|
97
|
-
defaultCustomConfigDirPath,
|
|
98
|
-
"config.json"
|
|
99
|
-
);
|
|
100
|
-
|
|
101
|
-
// src/config/custom.ts
|
|
102
|
-
import fs from "fs-extra";
|
|
103
|
-
var JSON_OPTIONS = {
|
|
104
|
-
encoding: "utf8",
|
|
105
|
-
spaces: 2
|
|
106
|
-
};
|
|
107
|
-
async function createCustomConfig(params) {
|
|
108
|
-
const trimmedCliPath = params.cliPath.trim();
|
|
109
|
-
if (!trimmedCliPath) {
|
|
110
|
-
throw new Error("cliPath cannot be empty");
|
|
111
|
-
}
|
|
112
|
-
const normalizedCliPath = resolvePath(trimmedCliPath);
|
|
113
|
-
await fs.ensureDir(defaultCustomConfigDirPath);
|
|
114
|
-
await fs.writeJSON(
|
|
115
|
-
defaultCustomConfigFilePath,
|
|
116
|
-
{
|
|
117
|
-
cliPath: normalizedCliPath
|
|
118
|
-
},
|
|
119
|
-
JSON_OPTIONS
|
|
120
|
-
);
|
|
121
|
-
return normalizedCliPath;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// src/cli/prompt.ts
|
|
125
|
-
import { stdin as input, stdout as output } from "process";
|
|
126
|
-
import { createInterface } from "readline/promises";
|
|
127
|
-
import fs2 from "fs-extra";
|
|
128
|
-
async function promptForCliPath() {
|
|
129
|
-
const rl = createInterface({ input, output });
|
|
130
|
-
try {
|
|
131
|
-
logger_default.log("\u8BF7\u8BBE\u7F6E\u5FAE\u4FE1web\u5F00\u53D1\u8005\u5DE5\u5177 CLI \u7684\u8DEF\u5F84");
|
|
132
|
-
logger_default.log("> \u63D0\u793A\uFF1A\u547D\u4EE4\u884C\u5DE5\u5177\u9ED8\u8BA4\u6240\u5728\u4F4D\u7F6E\uFF1A");
|
|
133
|
-
logger_default.log("- MacOS: <\u5B89\u88C5\u8DEF\u5F84>/Contents/MacOS/cli");
|
|
134
|
-
logger_default.log("- Windows: <\u5B89\u88C5\u8DEF\u5F84>/cli.bat");
|
|
135
|
-
logger_default.log("- Linux: <\u5B89\u88C5\u8DEF\u5F84>/files/bin/bin/wechat-devtools-cli");
|
|
136
|
-
const cliPath = (await rl.question("\u8BF7\u8F93\u5165\u5FAE\u4FE1web\u5F00\u53D1\u8005\u5DE5\u5177 CLI \u8DEF\u5F84\uFF1A")).trim();
|
|
137
|
-
if (!cliPath) {
|
|
138
|
-
logger_default.error("\u8DEF\u5F84\u4E0D\u80FD\u4E3A\u7A7A\uFF0C\u5DF2\u53D6\u6D88\u672C\u6B21\u914D\u7F6E\u3002");
|
|
139
|
-
return null;
|
|
140
|
-
}
|
|
141
|
-
try {
|
|
142
|
-
const normalizedPath = await createCustomConfig({ cliPath });
|
|
143
|
-
logger_default.log(`\u5168\u5C40\u914D\u7F6E\u5B58\u50A8\u4F4D\u7F6E\uFF1A${defaultCustomConfigFilePath}`);
|
|
144
|
-
if (!await fs2.pathExists(normalizedPath)) {
|
|
145
|
-
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");
|
|
146
|
-
}
|
|
147
|
-
return normalizedPath;
|
|
148
|
-
} catch (error) {
|
|
149
|
-
const reason = error instanceof Error ? error.message : String(error);
|
|
150
|
-
logger_default.error(`\u4FDD\u5B58\u914D\u7F6E\u5931\u8D25\uFF1A${reason}`);
|
|
151
|
-
return null;
|
|
152
|
-
}
|
|
153
|
-
} finally {
|
|
154
|
-
rl.close();
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
// src/runtime/platform.ts
|
|
159
|
-
import os2 from "os";
|
|
160
|
-
import process4 from "process";
|
|
161
|
-
import fs3 from "fs-extra";
|
|
162
|
-
import path3 from "pathe";
|
|
163
|
-
var SupportedPlatformsMap = {
|
|
164
|
-
Windows_NT: "Windows_NT",
|
|
165
|
-
Darwin: "Darwin",
|
|
166
|
-
Linux: "Linux"
|
|
167
|
-
};
|
|
168
|
-
function isOperatingSystemSupported(osName = os2.type()) {
|
|
169
|
-
return osName === SupportedPlatformsMap.Windows_NT || osName === SupportedPlatformsMap.Darwin || osName === SupportedPlatformsMap.Linux;
|
|
170
|
-
}
|
|
171
|
-
var operatingSystemName = os2.type();
|
|
172
|
-
function createLinuxCliResolver() {
|
|
173
|
-
let resolvedPath;
|
|
174
|
-
let attempted = false;
|
|
175
|
-
let pending = null;
|
|
176
|
-
return async () => {
|
|
177
|
-
if (attempted) {
|
|
178
|
-
return resolvedPath;
|
|
179
|
-
}
|
|
180
|
-
if (!pending) {
|
|
181
|
-
pending = (async () => {
|
|
182
|
-
try {
|
|
183
|
-
const envPath = await getFirstBinaryPath("wechat-devtools-cli");
|
|
184
|
-
if (envPath) {
|
|
185
|
-
resolvedPath = envPath;
|
|
186
|
-
}
|
|
187
|
-
} catch (error) {
|
|
188
|
-
const reason = error instanceof Error ? error.message : String(error);
|
|
189
|
-
logger_default.warn(`\u83B7\u53D6 Linux wechat-devtools-cli \u8DEF\u5F84\u5931\u8D25\uFF1A${reason}`);
|
|
190
|
-
} finally {
|
|
191
|
-
attempted = true;
|
|
192
|
-
}
|
|
193
|
-
return resolvedPath;
|
|
194
|
-
})();
|
|
195
|
-
}
|
|
196
|
-
return pending;
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
|
-
var linuxCliResolver = createLinuxCliResolver();
|
|
200
|
-
var WINDOWS_DEFAULT_CLI = "C:\\Program Files (x86)\\Tencent\\\u5FAE\u4FE1web\u5F00\u53D1\u8005\u5DE5\u5177\\cli.bat";
|
|
201
|
-
var DARWIN_DEFAULT_CLI = "/Applications/wechatwebdevtools.app/Contents/MacOS/cli";
|
|
202
|
-
var cliPathResolvers = {
|
|
203
|
-
[SupportedPlatformsMap.Windows_NT]: async () => WINDOWS_DEFAULT_CLI,
|
|
204
|
-
[SupportedPlatformsMap.Darwin]: async () => DARWIN_DEFAULT_CLI,
|
|
205
|
-
[SupportedPlatformsMap.Linux]: linuxCliResolver
|
|
206
|
-
};
|
|
207
|
-
async function getDefaultCliPath(targetOs = operatingSystemName) {
|
|
208
|
-
if (!isOperatingSystemSupported(targetOs)) {
|
|
209
|
-
return void 0;
|
|
210
|
-
}
|
|
211
|
-
const resolver = cliPathResolvers[targetOs];
|
|
212
|
-
const resolvedPath = await resolver();
|
|
213
|
-
return resolvedPath;
|
|
214
|
-
}
|
|
215
|
-
async function getFirstBinaryPath(command) {
|
|
216
|
-
const envPath = process4.env.PATH || "";
|
|
217
|
-
const pathDirs = envPath.split(path3.delimiter);
|
|
218
|
-
for (const dir of pathDirs) {
|
|
219
|
-
const fullPath = path3.join(dir, command);
|
|
220
|
-
try {
|
|
221
|
-
await fs3.access(fullPath, fs3.constants.X_OK);
|
|
222
|
-
return fullPath;
|
|
223
|
-
} catch {
|
|
224
|
-
continue;
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
return void 0;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
// src/config/resolver.ts
|
|
231
|
-
import fs4 from "fs-extra";
|
|
232
|
-
async function getConfig() {
|
|
233
|
-
if (await fs4.pathExists(defaultCustomConfigFilePath)) {
|
|
234
|
-
try {
|
|
235
|
-
const config = await fs4.readJSON(defaultCustomConfigFilePath);
|
|
236
|
-
const cliPath = typeof config.cliPath === "string" ? config.cliPath.trim() : "";
|
|
237
|
-
if (cliPath) {
|
|
238
|
-
logger_default.log("> \u5168\u5C40\u914D\u7F6E\u6587\u4EF6\u8DEF\u5F84\uFF1A", defaultCustomConfigFilePath);
|
|
239
|
-
logger_default.log("> \u81EA\u5B9A\u4E49 CLI \u8DEF\u5F84\uFF1A", cliPath);
|
|
240
|
-
return {
|
|
241
|
-
cliPath,
|
|
242
|
-
source: "custom"
|
|
243
|
-
};
|
|
244
|
-
}
|
|
245
|
-
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");
|
|
246
|
-
} catch (error) {
|
|
247
|
-
const reason = error instanceof Error ? error.message : String(error);
|
|
248
|
-
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}`);
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
const fallbackPath = await getDefaultCliPath();
|
|
252
|
-
if (fallbackPath) {
|
|
253
|
-
return {
|
|
254
|
-
cliPath: fallbackPath,
|
|
255
|
-
source: "default"
|
|
256
|
-
};
|
|
257
|
-
}
|
|
258
|
-
return {
|
|
259
|
-
cliPath: "",
|
|
260
|
-
source: "missing"
|
|
261
|
-
};
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
// src/cli/resolver.ts
|
|
265
|
-
import fs5 from "fs-extra";
|
|
266
|
-
async function resolveCliPath() {
|
|
267
|
-
const config = await getConfig();
|
|
268
|
-
if (!config.cliPath) {
|
|
269
|
-
return { cliPath: null, source: config.source };
|
|
270
|
-
}
|
|
271
|
-
const exists = await fs5.pathExists(config.cliPath);
|
|
272
|
-
return {
|
|
273
|
-
cliPath: exists ? config.cliPath : null,
|
|
274
|
-
source: config.source
|
|
275
|
-
};
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
// src/cli/run.ts
|
|
279
|
-
var MINIDEV_NAMESPACE = /* @__PURE__ */ new Set(["alipay", "ali", "minidev"]);
|
|
280
|
-
var ALIPAY_PLATFORM_ALIASES = /* @__PURE__ */ new Set(["alipay", "ali", "minidev"]);
|
|
281
|
-
var ARG_TRANSFORMS = [
|
|
282
|
-
createAlias({ find: "-p", replacement: "--project" }),
|
|
283
|
-
createPathCompat("--result-output"),
|
|
284
|
-
createPathCompat("-r"),
|
|
285
|
-
createPathCompat("--qr-output"),
|
|
286
|
-
createPathCompat("-o"),
|
|
287
|
-
createPathCompat("--info-output"),
|
|
288
|
-
createPathCompat("-i")
|
|
289
|
-
];
|
|
290
|
-
async function parse(argv) {
|
|
291
|
-
const head = argv[0];
|
|
292
|
-
if (head && MINIDEV_NAMESPACE.has(head)) {
|
|
293
|
-
await runMinidev(argv.slice(1));
|
|
294
|
-
return;
|
|
295
|
-
}
|
|
296
|
-
const formattedArgv = transformArgv(argv, ARG_TRANSFORMS);
|
|
297
|
-
if (shouldDelegateOpenToMinidev(formattedArgv)) {
|
|
298
|
-
await runMinidev(createMinidevOpenArgv(formattedArgv));
|
|
299
|
-
return;
|
|
300
|
-
}
|
|
301
|
-
if (!isOperatingSystemSupported(operatingSystemName)) {
|
|
302
|
-
logger_default.log(`\u5FAE\u4FE1web\u5F00\u53D1\u8005\u5DE5\u5177\u4E0D\u652F\u6301\u5F53\u524D\u5E73\u53F0\uFF1A${operatingSystemName} !`);
|
|
303
|
-
return;
|
|
304
|
-
}
|
|
305
|
-
if (head === "config") {
|
|
306
|
-
await promptForCliPath();
|
|
307
|
-
return;
|
|
308
|
-
}
|
|
309
|
-
const { cliPath, source } = await resolveCliPath();
|
|
310
|
-
if (!cliPath) {
|
|
311
|
-
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";
|
|
312
|
-
logger_default.log(message);
|
|
313
|
-
await promptForCliPath();
|
|
314
|
-
return;
|
|
315
|
-
}
|
|
316
|
-
await execute(cliPath, formattedArgv);
|
|
317
|
-
}
|
|
318
|
-
function shouldDelegateOpenToMinidev(argv) {
|
|
319
|
-
if (argv[0] !== "open") {
|
|
320
|
-
return false;
|
|
321
|
-
}
|
|
322
|
-
const platform = readOptionValue(argv, "--platform");
|
|
323
|
-
if (!platform) {
|
|
324
|
-
return false;
|
|
325
|
-
}
|
|
326
|
-
return ALIPAY_PLATFORM_ALIASES.has(platform);
|
|
327
|
-
}
|
|
328
|
-
function createMinidevOpenArgv(argv) {
|
|
329
|
-
const nextArgv = [...argv];
|
|
330
|
-
nextArgv[0] = "ide";
|
|
331
|
-
return removeOption(nextArgv, "--platform");
|
|
332
|
-
}
|
|
333
|
-
function readOptionValue(argv, optionName) {
|
|
334
|
-
const optionWithEqual = `${optionName}=`;
|
|
335
|
-
for (let index = 0; index < argv.length; index += 1) {
|
|
336
|
-
const token = argv[index];
|
|
337
|
-
if (!token) {
|
|
338
|
-
continue;
|
|
339
|
-
}
|
|
340
|
-
if (token === optionName) {
|
|
341
|
-
const value = argv[index + 1];
|
|
342
|
-
return typeof value === "string" ? value.trim().toLowerCase() : void 0;
|
|
343
|
-
}
|
|
344
|
-
if (token.startsWith(optionWithEqual)) {
|
|
345
|
-
const value = token.slice(optionWithEqual.length);
|
|
346
|
-
return value.trim().toLowerCase();
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
return void 0;
|
|
350
|
-
}
|
|
351
|
-
function removeOption(argv, optionName) {
|
|
352
|
-
const optionWithEqual = `${optionName}=`;
|
|
353
|
-
const nextArgv = [];
|
|
354
|
-
for (let index = 0; index < argv.length; index += 1) {
|
|
355
|
-
const token = argv[index];
|
|
356
|
-
if (!token) {
|
|
357
|
-
continue;
|
|
358
|
-
}
|
|
359
|
-
if (token === optionName) {
|
|
360
|
-
const nextToken = argv[index + 1];
|
|
361
|
-
if (nextToken && !nextToken.startsWith("-")) {
|
|
362
|
-
index += 1;
|
|
363
|
-
}
|
|
364
|
-
continue;
|
|
365
|
-
}
|
|
366
|
-
if (token.startsWith(optionWithEqual)) {
|
|
367
|
-
continue;
|
|
368
|
-
}
|
|
369
|
-
nextArgv.push(token);
|
|
370
|
-
}
|
|
371
|
-
return nextArgv;
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
export {
|
|
375
|
-
logger_default,
|
|
376
|
-
resolvePath,
|
|
377
|
-
transformArgv,
|
|
378
|
-
createAlias,
|
|
379
|
-
createPathCompat,
|
|
380
|
-
execute,
|
|
381
|
-
runMinidev,
|
|
382
|
-
defaultCustomConfigDirPath,
|
|
383
|
-
defaultCustomConfigFilePath,
|
|
384
|
-
createCustomConfig,
|
|
385
|
-
promptForCliPath,
|
|
386
|
-
SupportedPlatformsMap,
|
|
387
|
-
isOperatingSystemSupported,
|
|
388
|
-
operatingSystemName,
|
|
389
|
-
getDefaultCliPath,
|
|
390
|
-
getConfig,
|
|
391
|
-
resolveCliPath,
|
|
392
|
-
parse
|
|
393
|
-
};
|