weapp-ide-cli 3.1.0 → 4.0.0-alpha.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/README.md +84 -31
- package/dist/chunk-FJJOQAVP.js +302 -0
- package/dist/cli.cjs +236 -171
- package/dist/cli.js +1 -1
- package/dist/index.cjs +253 -174
- package/dist/index.d.cts +40 -7
- package/dist/index.d.ts +40 -7
- package/dist/index.js +19 -5
- package/package.json +2 -2
- package/dist/chunk-WCSD523G.js +0 -236
package/dist/index.cjs
CHANGED
|
@@ -30,42 +30,180 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var src_exports = {};
|
|
32
32
|
__export(src_exports, {
|
|
33
|
+
SupportedPlatformsMap: () => SupportedPlatformsMap,
|
|
33
34
|
createAlias: () => createAlias,
|
|
35
|
+
createCustomConfig: () => createCustomConfig,
|
|
34
36
|
createPathCompat: () => createPathCompat,
|
|
35
37
|
defaultCustomConfigDirPath: () => defaultCustomConfigDirPath,
|
|
36
38
|
defaultCustomConfigFilePath: () => defaultCustomConfigFilePath,
|
|
37
39
|
execute: () => execute,
|
|
38
|
-
|
|
40
|
+
getConfig: () => getConfig,
|
|
41
|
+
getDefaultCliPath: () => getDefaultCliPath,
|
|
42
|
+
isOperatingSystemSupported: () => isOperatingSystemSupported,
|
|
39
43
|
operatingSystemName: () => operatingSystemName,
|
|
40
44
|
parse: () => parse,
|
|
41
|
-
|
|
45
|
+
promptForCliPath: () => promptForCliPath,
|
|
46
|
+
resolveCliPath: () => resolveCliPath,
|
|
47
|
+
resolvePath: () => resolvePath,
|
|
48
|
+
transformArgv: () => transformArgv
|
|
42
49
|
});
|
|
43
50
|
module.exports = __toCommonJS(src_exports);
|
|
44
51
|
|
|
45
|
-
// src/
|
|
46
|
-
var
|
|
47
|
-
var
|
|
52
|
+
// src/cli/prompt.ts
|
|
53
|
+
var import_node_process2 = require("process");
|
|
54
|
+
var import_promises = require("readline/promises");
|
|
55
|
+
var import_fs_extra2 = __toESM(require("fs-extra"), 1);
|
|
56
|
+
|
|
57
|
+
// src/config/custom.ts
|
|
48
58
|
var import_fs_extra = __toESM(require("fs-extra"), 1);
|
|
59
|
+
|
|
60
|
+
// src/utils/path.ts
|
|
61
|
+
var import_node_process = __toESM(require("process"), 1);
|
|
49
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/config/paths.ts
|
|
71
|
+
var import_node_os = __toESM(require("os"), 1);
|
|
72
|
+
var import_pathe2 = __toESM(require("pathe"), 1);
|
|
73
|
+
var homedir = import_node_os.default.homedir();
|
|
74
|
+
var defaultCustomConfigDirPath = import_pathe2.default.join(homedir, ".weapp-ide-cli");
|
|
75
|
+
var defaultCustomConfigFilePath = import_pathe2.default.join(
|
|
76
|
+
defaultCustomConfigDirPath,
|
|
77
|
+
"config.json"
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
// src/config/custom.ts
|
|
81
|
+
var JSON_OPTIONS = {
|
|
82
|
+
encoding: "utf8",
|
|
83
|
+
spaces: 2
|
|
84
|
+
};
|
|
85
|
+
async function createCustomConfig(params) {
|
|
86
|
+
const trimmedCliPath = params.cliPath.trim();
|
|
87
|
+
if (!trimmedCliPath) {
|
|
88
|
+
throw new Error("cliPath cannot be empty");
|
|
89
|
+
}
|
|
90
|
+
const normalizedCliPath = resolvePath(trimmedCliPath);
|
|
91
|
+
await import_fs_extra.default.ensureDir(defaultCustomConfigDirPath);
|
|
92
|
+
await import_fs_extra.default.writeJSON(
|
|
93
|
+
defaultCustomConfigFilePath,
|
|
94
|
+
{
|
|
95
|
+
cliPath: normalizedCliPath
|
|
96
|
+
},
|
|
97
|
+
JSON_OPTIONS
|
|
98
|
+
);
|
|
99
|
+
return normalizedCliPath;
|
|
100
|
+
}
|
|
50
101
|
|
|
51
102
|
// src/logger.ts
|
|
52
103
|
var import_logger = __toESM(require("@weapp-core/logger"), 1);
|
|
53
104
|
var logger_default = import_logger.default;
|
|
54
105
|
|
|
55
|
-
// src/
|
|
56
|
-
|
|
106
|
+
// src/cli/prompt.ts
|
|
107
|
+
async function promptForCliPath() {
|
|
108
|
+
const rl = (0, import_promises.createInterface)({ input: import_node_process2.stdin, output: import_node_process2.stdout });
|
|
109
|
+
try {
|
|
110
|
+
logger_default.log("\u8BF7\u8BBE\u7F6E\u5FAE\u4FE1web\u5F00\u53D1\u8005\u5DE5\u5177 CLI \u7684\u8DEF\u5F84");
|
|
111
|
+
logger_default.log("> \u63D0\u793A\uFF1A\u547D\u4EE4\u884C\u5DE5\u5177\u9ED8\u8BA4\u6240\u5728\u4F4D\u7F6E\uFF1A");
|
|
112
|
+
logger_default.log("- MacOS: <\u5B89\u88C5\u8DEF\u5F84>/Contents/MacOS/cli");
|
|
113
|
+
logger_default.log("- Windows: <\u5B89\u88C5\u8DEF\u5F84>/cli.bat");
|
|
114
|
+
logger_default.log("- Linux: <\u5B89\u88C5\u8DEF\u5F84>/files/bin/bin/wechat-devtools-cli");
|
|
115
|
+
const cliPath = (await rl.question("\u8BF7\u8F93\u5165\u5FAE\u4FE1web\u5F00\u53D1\u8005\u5DE5\u5177 CLI \u8DEF\u5F84\uFF1A")).trim();
|
|
116
|
+
if (!cliPath) {
|
|
117
|
+
logger_default.error("\u8DEF\u5F84\u4E0D\u80FD\u4E3A\u7A7A\uFF0C\u5DF2\u53D6\u6D88\u672C\u6B21\u914D\u7F6E\u3002");
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
try {
|
|
121
|
+
const normalizedPath = await createCustomConfig({ cliPath });
|
|
122
|
+
logger_default.log(`\u5168\u5C40\u914D\u7F6E\u5B58\u50A8\u4F4D\u7F6E\uFF1A${defaultCustomConfigFilePath}`);
|
|
123
|
+
if (!await import_fs_extra2.default.pathExists(normalizedPath)) {
|
|
124
|
+
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");
|
|
125
|
+
}
|
|
126
|
+
return normalizedPath;
|
|
127
|
+
} catch (error) {
|
|
128
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
129
|
+
logger_default.error(`\u4FDD\u5B58\u914D\u7F6E\u5931\u8D25\uFF1A${reason}`);
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
} finally {
|
|
133
|
+
rl.close();
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// src/cli/resolver.ts
|
|
138
|
+
var import_fs_extra5 = __toESM(require("fs-extra"), 1);
|
|
139
|
+
|
|
140
|
+
// src/config/resolver.ts
|
|
141
|
+
var import_fs_extra4 = __toESM(require("fs-extra"), 1);
|
|
142
|
+
|
|
143
|
+
// src/runtime/platform.ts
|
|
144
|
+
var import_node_os2 = __toESM(require("os"), 1);
|
|
145
|
+
var import_node_process3 = __toESM(require("process"), 1);
|
|
146
|
+
var import_fs_extra3 = __toESM(require("fs-extra"), 1);
|
|
147
|
+
var import_pathe3 = __toESM(require("pathe"), 1);
|
|
57
148
|
var SupportedPlatformsMap = {
|
|
58
149
|
Windows_NT: "Windows_NT",
|
|
59
150
|
Darwin: "Darwin",
|
|
60
151
|
Linux: "Linux"
|
|
61
152
|
};
|
|
153
|
+
function isOperatingSystemSupported(osName = import_node_os2.default.type()) {
|
|
154
|
+
return osName === SupportedPlatformsMap.Windows_NT || osName === SupportedPlatformsMap.Darwin || osName === SupportedPlatformsMap.Linux;
|
|
155
|
+
}
|
|
156
|
+
var operatingSystemName = import_node_os2.default.type();
|
|
157
|
+
function createLinuxCliResolver() {
|
|
158
|
+
let resolvedPath;
|
|
159
|
+
let attempted = false;
|
|
160
|
+
let pending = null;
|
|
161
|
+
return async () => {
|
|
162
|
+
if (attempted) {
|
|
163
|
+
return resolvedPath;
|
|
164
|
+
}
|
|
165
|
+
if (!pending) {
|
|
166
|
+
pending = (async () => {
|
|
167
|
+
try {
|
|
168
|
+
const envPath = await getFirstBinaryPath("wechat-devtools-cli");
|
|
169
|
+
if (envPath) {
|
|
170
|
+
resolvedPath = envPath;
|
|
171
|
+
}
|
|
172
|
+
} catch (error) {
|
|
173
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
174
|
+
logger_default.warn(`\u83B7\u53D6 Linux wechat-devtools-cli \u8DEF\u5F84\u5931\u8D25\uFF1A${reason}`);
|
|
175
|
+
} finally {
|
|
176
|
+
attempted = true;
|
|
177
|
+
}
|
|
178
|
+
return resolvedPath;
|
|
179
|
+
})();
|
|
180
|
+
}
|
|
181
|
+
return pending;
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
var linuxCliResolver = createLinuxCliResolver();
|
|
185
|
+
var WINDOWS_DEFAULT_CLI = "C:\\Program Files (x86)\\Tencent\\\u5FAE\u4FE1web\u5F00\u53D1\u8005\u5DE5\u5177\\cli.bat";
|
|
186
|
+
var DARWIN_DEFAULT_CLI = "/Applications/wechatwebdevtools.app/Contents/MacOS/cli";
|
|
187
|
+
var cliPathResolvers = {
|
|
188
|
+
[SupportedPlatformsMap.Windows_NT]: async () => WINDOWS_DEFAULT_CLI,
|
|
189
|
+
[SupportedPlatformsMap.Darwin]: async () => DARWIN_DEFAULT_CLI,
|
|
190
|
+
[SupportedPlatformsMap.Linux]: linuxCliResolver
|
|
191
|
+
};
|
|
192
|
+
async function getDefaultCliPath(targetOs = operatingSystemName) {
|
|
193
|
+
if (!isOperatingSystemSupported(targetOs)) {
|
|
194
|
+
return void 0;
|
|
195
|
+
}
|
|
196
|
+
const resolver = cliPathResolvers[targetOs];
|
|
197
|
+
const resolvedPath = await resolver();
|
|
198
|
+
return resolvedPath;
|
|
199
|
+
}
|
|
62
200
|
async function getFirstBinaryPath(command) {
|
|
63
|
-
const envPath =
|
|
64
|
-
const pathDirs = envPath.split(
|
|
201
|
+
const envPath = import_node_process3.default.env.PATH || "";
|
|
202
|
+
const pathDirs = envPath.split(import_pathe3.default.delimiter);
|
|
65
203
|
for (const dir of pathDirs) {
|
|
66
|
-
const fullPath =
|
|
204
|
+
const fullPath = import_pathe3.default.join(dir, command);
|
|
67
205
|
try {
|
|
68
|
-
await
|
|
206
|
+
await import_fs_extra3.default.access(fullPath, import_fs_extra3.default.constants.X_OK);
|
|
69
207
|
return fullPath;
|
|
70
208
|
} catch {
|
|
71
209
|
continue;
|
|
@@ -73,170 +211,107 @@ async function getFirstBinaryPath(command) {
|
|
|
73
211
|
}
|
|
74
212
|
return void 0;
|
|
75
213
|
}
|
|
76
|
-
var operatingSystemName = import_node_os.default.type();
|
|
77
|
-
var defaultPathMap = {
|
|
78
|
-
[SupportedPlatformsMap.Windows_NT]: "C:\\Program Files (x86)\\Tencent\\\u5FAE\u4FE1web\u5F00\u53D1\u8005\u5DE5\u5177\\cli.bat",
|
|
79
|
-
[SupportedPlatformsMap.Darwin]: "/Applications/wechatwebdevtools.app/Contents/MacOS/cli"
|
|
80
|
-
};
|
|
81
|
-
var linuxPathInitialized = false;
|
|
82
|
-
async function getLinuxDevToolsPath() {
|
|
83
|
-
if (operatingSystemName !== SupportedPlatformsMap.Linux && linuxPathInitialized) {
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
try {
|
|
87
|
-
const linuxDevCliPath = await getFirstBinaryPath("wechat-devtools-cli");
|
|
88
|
-
if (linuxDevCliPath) {
|
|
89
|
-
linuxPathInitialized = true;
|
|
90
|
-
defaultPathMap[SupportedPlatformsMap.Linux] = linuxDevCliPath;
|
|
91
|
-
}
|
|
92
|
-
} catch (error) {
|
|
93
|
-
if (error instanceof Error) {
|
|
94
|
-
logger_default.error("\u83B7\u53D6Linux\u5F00\u53D1\u5DE5\u5177 wechat-devtools-cli \u8DEF\u5F84\u5931\u8D25:", error.message);
|
|
95
|
-
} else {
|
|
96
|
-
logger_default.error("\u83B7\u53D6Linux\u5F00\u53D1\u5DE5\u5177 wechat-devtools-cli \u8DEF\u5F84\u5931\u8D25:", error);
|
|
97
|
-
}
|
|
98
|
-
return defaultPathMap[SupportedPlatformsMap.Linux];
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
async function getDefaultPath() {
|
|
102
|
-
await getLinuxDevToolsPath();
|
|
103
|
-
return defaultPathMap[operatingSystemName];
|
|
104
|
-
}
|
|
105
|
-
var defaultCustomConfigDirPath = import_pathe.default.join(homedir, ".weapp-ide-cli");
|
|
106
|
-
var defaultCustomConfigFilePath = import_pathe.default.join(
|
|
107
|
-
defaultCustomConfigDirPath,
|
|
108
|
-
"config.json"
|
|
109
|
-
);
|
|
110
|
-
|
|
111
|
-
// src/parse.ts
|
|
112
|
-
var import_node_process3 = __toESM(require("process"), 1);
|
|
113
|
-
var import_node_readline = __toESM(require("readline"), 1);
|
|
114
|
-
var import_fs_extra3 = __toESM(require("fs-extra"), 1);
|
|
115
|
-
|
|
116
|
-
// src/compose.ts
|
|
117
|
-
function compose(...funcs) {
|
|
118
|
-
if (funcs.length === 0) {
|
|
119
|
-
return (arg) => arg;
|
|
120
|
-
}
|
|
121
|
-
if (funcs.length === 1) {
|
|
122
|
-
return funcs[0];
|
|
123
|
-
}
|
|
124
|
-
return funcs.reduce(
|
|
125
|
-
(a, b) => (...args) => a(b(...args))
|
|
126
|
-
);
|
|
127
|
-
}
|
|
128
214
|
|
|
129
|
-
// src/config.ts
|
|
130
|
-
var import_fs_extra2 = __toESM(require("fs-extra"), 1);
|
|
131
|
-
function createCustomConfig(params) {
|
|
132
|
-
return import_fs_extra2.default.outputJSON(
|
|
133
|
-
defaultCustomConfigFilePath,
|
|
134
|
-
{
|
|
135
|
-
cliPath: params.cliPath
|
|
136
|
-
},
|
|
137
|
-
{
|
|
138
|
-
encoding: "utf8",
|
|
139
|
-
spaces: 2
|
|
140
|
-
}
|
|
141
|
-
);
|
|
142
|
-
}
|
|
215
|
+
// src/config/resolver.ts
|
|
143
216
|
async function getConfig() {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
217
|
+
if (await import_fs_extra4.default.pathExists(defaultCustomConfigFilePath)) {
|
|
218
|
+
try {
|
|
219
|
+
const config = await import_fs_extra4.default.readJSON(defaultCustomConfigFilePath);
|
|
220
|
+
const cliPath = typeof config.cliPath === "string" ? config.cliPath.trim() : "";
|
|
221
|
+
if (cliPath) {
|
|
222
|
+
logger_default.log("> \u5168\u5C40\u914D\u7F6E\u6587\u4EF6\u8DEF\u5F84\uFF1A", defaultCustomConfigFilePath);
|
|
223
|
+
logger_default.log("> \u81EA\u5B9A\u4E49 CLI \u8DEF\u5F84\uFF1A", cliPath);
|
|
224
|
+
return {
|
|
225
|
+
cliPath,
|
|
226
|
+
source: "custom"
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
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");
|
|
230
|
+
} catch (error) {
|
|
231
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
232
|
+
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}`);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
const fallbackPath = await getDefaultCliPath();
|
|
236
|
+
if (fallbackPath) {
|
|
154
237
|
return {
|
|
155
|
-
cliPath:
|
|
238
|
+
cliPath: fallbackPath,
|
|
239
|
+
source: "default"
|
|
156
240
|
};
|
|
157
241
|
}
|
|
242
|
+
return {
|
|
243
|
+
cliPath: "",
|
|
244
|
+
source: "missing"
|
|
245
|
+
};
|
|
158
246
|
}
|
|
159
247
|
|
|
160
|
-
// src/
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
const task = execa(cliPath, argv);
|
|
166
|
-
task?.stdout?.pipe(import_node_process2.default.stdout);
|
|
167
|
-
await task;
|
|
168
|
-
}
|
|
169
|
-
function resolvePath(filePath) {
|
|
170
|
-
if (import_pathe2.default.isAbsolute(filePath)) {
|
|
171
|
-
return filePath;
|
|
172
|
-
} else {
|
|
173
|
-
return import_pathe2.default.resolve(import_node_process2.default.cwd(), filePath);
|
|
248
|
+
// src/cli/resolver.ts
|
|
249
|
+
async function resolveCliPath() {
|
|
250
|
+
const config = await getConfig();
|
|
251
|
+
if (!config.cliPath) {
|
|
252
|
+
return { cliPath: null, source: config.source };
|
|
174
253
|
}
|
|
254
|
+
const exists = await import_fs_extra5.default.pathExists(config.cliPath);
|
|
255
|
+
return {
|
|
256
|
+
cliPath: exists ? config.cliPath : null,
|
|
257
|
+
source: config.source
|
|
258
|
+
};
|
|
175
259
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
260
|
+
|
|
261
|
+
// src/utils/argv.ts
|
|
262
|
+
var import_node_process4 = __toESM(require("process"), 1);
|
|
263
|
+
function ensurePathArgument(argv, optionIndex) {
|
|
264
|
+
const paramIdx = optionIndex + 1;
|
|
265
|
+
const param = argv[paramIdx];
|
|
266
|
+
if (param && !param.startsWith("-")) {
|
|
267
|
+
argv[paramIdx] = resolvePath(param);
|
|
180
268
|
} else {
|
|
181
|
-
|
|
182
|
-
}
|
|
183
|
-
if (findIdx > -1) {
|
|
184
|
-
const paramIdx = findIdx + 1;
|
|
185
|
-
const param = argv[paramIdx];
|
|
186
|
-
if (param && param[0] !== "-") {
|
|
187
|
-
argv[paramIdx] = resolvePath(param);
|
|
188
|
-
} else {
|
|
189
|
-
argv.splice(paramIdx, 0, import_node_process2.default.cwd());
|
|
190
|
-
}
|
|
269
|
+
argv.splice(paramIdx, 0, import_node_process4.default.cwd());
|
|
191
270
|
}
|
|
192
271
|
return argv;
|
|
193
272
|
}
|
|
194
|
-
function
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
const param = argv[paramIdx];
|
|
199
|
-
if (param && param[0] !== "-") {
|
|
200
|
-
argv[paramIdx] = resolvePath(param);
|
|
201
|
-
} else {
|
|
202
|
-
argv.splice(paramIdx, 0, import_node_process2.default.cwd());
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
return argv;
|
|
273
|
+
function transformArgv(argv, transforms) {
|
|
274
|
+
return transforms.reduce((current, transform) => transform(current), [
|
|
275
|
+
...argv
|
|
276
|
+
]);
|
|
206
277
|
}
|
|
207
278
|
function createAlias(entry) {
|
|
208
|
-
return
|
|
209
|
-
|
|
279
|
+
return (input2) => {
|
|
280
|
+
const argv = [...input2];
|
|
281
|
+
let optionIndex = argv.indexOf(entry.find);
|
|
282
|
+
if (optionIndex > -1) {
|
|
283
|
+
argv.splice(optionIndex, 1, entry.replacement);
|
|
284
|
+
} else {
|
|
285
|
+
optionIndex = argv.indexOf(entry.replacement);
|
|
286
|
+
}
|
|
287
|
+
if (optionIndex === -1) {
|
|
288
|
+
return argv;
|
|
289
|
+
}
|
|
290
|
+
return ensurePathArgument(argv, optionIndex);
|
|
210
291
|
};
|
|
211
292
|
}
|
|
212
293
|
function createPathCompat(option) {
|
|
213
|
-
return
|
|
214
|
-
|
|
294
|
+
return (input2) => {
|
|
295
|
+
const argv = [...input2];
|
|
296
|
+
const optionIndex = argv.indexOf(option);
|
|
297
|
+
if (optionIndex === -1) {
|
|
298
|
+
return argv;
|
|
299
|
+
}
|
|
300
|
+
return ensurePathArgument(argv, optionIndex);
|
|
215
301
|
};
|
|
216
302
|
}
|
|
217
303
|
|
|
218
|
-
// src/
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
logger_default.log("> \u63D0\u793A\uFF1A\u547D\u4EE4\u884C\u5DE5\u5177\u9ED8\u8BA4\u6240\u5728\u4F4D\u7F6E\uFF1A");
|
|
226
|
-
logger_default.log("- MacOS: <\u5B89\u88C5\u8DEF\u5F84>/Contents/MacOS/cli");
|
|
227
|
-
logger_default.log("- Windows: <\u5B89\u88C5\u8DEF\u5F84>/cli.bat");
|
|
228
|
-
logger_default.log("- Linux: <\u5B89\u88C5\u8DEF\u5F84>/files/bin/bin/wechat-devtools-cli");
|
|
229
|
-
return new Promise((resolve, _reject) => {
|
|
230
|
-
rl.question("\u8BF7\u8F93\u5165\u5FAE\u4FE1web\u5F00\u53D1\u8005\u5DE5\u5177cli\u8DEF\u5F84\uFF1A", async (cliPath) => {
|
|
231
|
-
await createCustomConfig({
|
|
232
|
-
cliPath
|
|
233
|
-
});
|
|
234
|
-
logger_default.log(`\u5168\u5C40\u914D\u7F6E\u5B58\u50A8\u4F4D\u7F6E\uFF1A${defaultCustomConfigFilePath}`);
|
|
235
|
-
resolve(cliPath);
|
|
236
|
-
});
|
|
237
|
-
});
|
|
304
|
+
// src/utils/exec.ts
|
|
305
|
+
var import_node_process5 = __toESM(require("process"), 1);
|
|
306
|
+
async function execute(cliPath, argv) {
|
|
307
|
+
const { execa } = await import("execa");
|
|
308
|
+
const task = execa(cliPath, argv);
|
|
309
|
+
task?.stdout?.pipe(import_node_process5.default.stdout);
|
|
310
|
+
await task;
|
|
238
311
|
}
|
|
239
|
-
|
|
312
|
+
|
|
313
|
+
// src/cli/run.ts
|
|
314
|
+
var ARG_TRANSFORMS = [
|
|
240
315
|
createAlias({ find: "-p", replacement: "--project" }),
|
|
241
316
|
createPathCompat("--result-output"),
|
|
242
317
|
createPathCompat("-r"),
|
|
@@ -244,38 +319,42 @@ var parseArgv = compose(
|
|
|
244
319
|
createPathCompat("-o"),
|
|
245
320
|
createPathCompat("--info-output"),
|
|
246
321
|
createPathCompat("-i")
|
|
247
|
-
|
|
322
|
+
];
|
|
248
323
|
async function parse(argv) {
|
|
249
|
-
|
|
250
|
-
if (isSupported) {
|
|
251
|
-
const { cliPath } = await getConfig();
|
|
252
|
-
const isExisted = await import_fs_extra3.default.exists(cliPath);
|
|
253
|
-
if (isExisted) {
|
|
254
|
-
if (argv[0] === "config") {
|
|
255
|
-
await rlSetConfig();
|
|
256
|
-
return;
|
|
257
|
-
}
|
|
258
|
-
const formattedArgv = parseArgv(argv);
|
|
259
|
-
await execute(cliPath, formattedArgv);
|
|
260
|
-
} else {
|
|
261
|
-
logger_default.log(
|
|
262
|
-
"\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"
|
|
263
|
-
);
|
|
264
|
-
await rlSetConfig();
|
|
265
|
-
}
|
|
266
|
-
} else {
|
|
324
|
+
if (!isOperatingSystemSupported(operatingSystemName)) {
|
|
267
325
|
logger_default.log(`\u5FAE\u4FE1web\u5F00\u53D1\u8005\u5DE5\u5177\u4E0D\u652F\u6301\u5F53\u524D\u5E73\u53F0\uFF1A${operatingSystemName} !`);
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
if (argv[0] === "config") {
|
|
329
|
+
await promptForCliPath();
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
const { cliPath, source } = await resolveCliPath();
|
|
333
|
+
if (!cliPath) {
|
|
334
|
+
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";
|
|
335
|
+
logger_default.log(message);
|
|
336
|
+
await promptForCliPath();
|
|
337
|
+
return;
|
|
268
338
|
}
|
|
339
|
+
const formattedArgv = transformArgv(argv, ARG_TRANSFORMS);
|
|
340
|
+
await execute(cliPath, formattedArgv);
|
|
269
341
|
}
|
|
270
342
|
// Annotate the CommonJS export names for ESM import in node:
|
|
271
343
|
0 && (module.exports = {
|
|
344
|
+
SupportedPlatformsMap,
|
|
272
345
|
createAlias,
|
|
346
|
+
createCustomConfig,
|
|
273
347
|
createPathCompat,
|
|
274
348
|
defaultCustomConfigDirPath,
|
|
275
349
|
defaultCustomConfigFilePath,
|
|
276
350
|
execute,
|
|
277
|
-
|
|
351
|
+
getConfig,
|
|
352
|
+
getDefaultCliPath,
|
|
353
|
+
isOperatingSystemSupported,
|
|
278
354
|
operatingSystemName,
|
|
279
355
|
parse,
|
|
280
|
-
|
|
356
|
+
promptForCliPath,
|
|
357
|
+
resolveCliPath,
|
|
358
|
+
resolvePath,
|
|
359
|
+
transformArgv
|
|
281
360
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,21 +1,54 @@
|
|
|
1
|
-
declare
|
|
2
|
-
|
|
3
|
-
declare
|
|
4
|
-
|
|
1
|
+
declare function promptForCliPath(): Promise<string | null>;
|
|
2
|
+
|
|
3
|
+
declare function resolveCliPath(): Promise<{
|
|
4
|
+
cliPath: string | null;
|
|
5
|
+
source: ConfigSource;
|
|
6
|
+
}>;
|
|
5
7
|
|
|
6
8
|
declare function parse(argv: string[]): Promise<void>;
|
|
7
9
|
|
|
8
10
|
interface BaseConfig {
|
|
9
11
|
cliPath: string;
|
|
10
12
|
}
|
|
13
|
+
type ConfigSource = 'custom' | 'default' | 'missing';
|
|
14
|
+
interface ResolvedConfig extends BaseConfig {
|
|
15
|
+
source: ConfigSource;
|
|
16
|
+
}
|
|
11
17
|
interface AliasEntry {
|
|
12
18
|
find: string;
|
|
13
19
|
replacement: string;
|
|
14
20
|
}
|
|
15
21
|
|
|
22
|
+
declare function createCustomConfig(params: BaseConfig): Promise<string>;
|
|
23
|
+
|
|
24
|
+
declare const defaultCustomConfigDirPath: string;
|
|
25
|
+
declare const defaultCustomConfigFilePath: string;
|
|
26
|
+
|
|
27
|
+
declare function getConfig(): Promise<ResolvedConfig>;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* 官方微信开发者工具只支持 Windows、macOS, Linux只有社区版 https://github.com/msojocs/wechat-web-devtools-linux
|
|
31
|
+
*/
|
|
32
|
+
declare const SupportedPlatformsMap: {
|
|
33
|
+
readonly Windows_NT: "Windows_NT";
|
|
34
|
+
readonly Darwin: "Darwin";
|
|
35
|
+
readonly Linux: "Linux";
|
|
36
|
+
};
|
|
37
|
+
type SupportedPlatform = (typeof SupportedPlatformsMap)[keyof typeof SupportedPlatformsMap];
|
|
38
|
+
declare function isOperatingSystemSupported(osName?: string): osName is SupportedPlatform;
|
|
39
|
+
declare const operatingSystemName: string;
|
|
40
|
+
declare function getDefaultCliPath(targetOs?: string): Promise<string | undefined>;
|
|
41
|
+
|
|
42
|
+
type ArgvTransform = (argv: readonly string[]) => string[];
|
|
43
|
+
/**
|
|
44
|
+
* Apply a list of argv transforms in order while keeping the original argv untouched.
|
|
45
|
+
*/
|
|
46
|
+
declare function transformArgv(argv: readonly string[], transforms: readonly ArgvTransform[]): string[];
|
|
47
|
+
declare function createAlias(entry: AliasEntry): ArgvTransform;
|
|
48
|
+
declare function createPathCompat(option: string): ArgvTransform;
|
|
49
|
+
|
|
16
50
|
declare function execute(cliPath: string, argv: string[]): Promise<void>;
|
|
51
|
+
|
|
17
52
|
declare function resolvePath(filePath: string): string;
|
|
18
|
-
declare function createAlias(entry: AliasEntry): (argv: string[]) => string[];
|
|
19
|
-
declare function createPathCompat(option: string): (argv: string[]) => string[];
|
|
20
53
|
|
|
21
|
-
export { type BaseConfig, createAlias, createPathCompat, defaultCustomConfigDirPath, defaultCustomConfigFilePath, execute,
|
|
54
|
+
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, transformArgv };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,21 +1,54 @@
|
|
|
1
|
-
declare
|
|
2
|
-
|
|
3
|
-
declare
|
|
4
|
-
|
|
1
|
+
declare function promptForCliPath(): Promise<string | null>;
|
|
2
|
+
|
|
3
|
+
declare function resolveCliPath(): Promise<{
|
|
4
|
+
cliPath: string | null;
|
|
5
|
+
source: ConfigSource;
|
|
6
|
+
}>;
|
|
5
7
|
|
|
6
8
|
declare function parse(argv: string[]): Promise<void>;
|
|
7
9
|
|
|
8
10
|
interface BaseConfig {
|
|
9
11
|
cliPath: string;
|
|
10
12
|
}
|
|
13
|
+
type ConfigSource = 'custom' | 'default' | 'missing';
|
|
14
|
+
interface ResolvedConfig extends BaseConfig {
|
|
15
|
+
source: ConfigSource;
|
|
16
|
+
}
|
|
11
17
|
interface AliasEntry {
|
|
12
18
|
find: string;
|
|
13
19
|
replacement: string;
|
|
14
20
|
}
|
|
15
21
|
|
|
22
|
+
declare function createCustomConfig(params: BaseConfig): Promise<string>;
|
|
23
|
+
|
|
24
|
+
declare const defaultCustomConfigDirPath: string;
|
|
25
|
+
declare const defaultCustomConfigFilePath: string;
|
|
26
|
+
|
|
27
|
+
declare function getConfig(): Promise<ResolvedConfig>;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* 官方微信开发者工具只支持 Windows、macOS, Linux只有社区版 https://github.com/msojocs/wechat-web-devtools-linux
|
|
31
|
+
*/
|
|
32
|
+
declare const SupportedPlatformsMap: {
|
|
33
|
+
readonly Windows_NT: "Windows_NT";
|
|
34
|
+
readonly Darwin: "Darwin";
|
|
35
|
+
readonly Linux: "Linux";
|
|
36
|
+
};
|
|
37
|
+
type SupportedPlatform = (typeof SupportedPlatformsMap)[keyof typeof SupportedPlatformsMap];
|
|
38
|
+
declare function isOperatingSystemSupported(osName?: string): osName is SupportedPlatform;
|
|
39
|
+
declare const operatingSystemName: string;
|
|
40
|
+
declare function getDefaultCliPath(targetOs?: string): Promise<string | undefined>;
|
|
41
|
+
|
|
42
|
+
type ArgvTransform = (argv: readonly string[]) => string[];
|
|
43
|
+
/**
|
|
44
|
+
* Apply a list of argv transforms in order while keeping the original argv untouched.
|
|
45
|
+
*/
|
|
46
|
+
declare function transformArgv(argv: readonly string[], transforms: readonly ArgvTransform[]): string[];
|
|
47
|
+
declare function createAlias(entry: AliasEntry): ArgvTransform;
|
|
48
|
+
declare function createPathCompat(option: string): ArgvTransform;
|
|
49
|
+
|
|
16
50
|
declare function execute(cliPath: string, argv: string[]): Promise<void>;
|
|
51
|
+
|
|
17
52
|
declare function resolvePath(filePath: string): string;
|
|
18
|
-
declare function createAlias(entry: AliasEntry): (argv: string[]) => string[];
|
|
19
|
-
declare function createPathCompat(option: string): (argv: string[]) => string[];
|
|
20
53
|
|
|
21
|
-
export { type BaseConfig, createAlias, createPathCompat, defaultCustomConfigDirPath, defaultCustomConfigFilePath, execute,
|
|
54
|
+
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, transformArgv };
|
package/dist/index.js
CHANGED
|
@@ -1,22 +1,36 @@
|
|
|
1
1
|
import {
|
|
2
|
+
SupportedPlatformsMap,
|
|
2
3
|
createAlias,
|
|
4
|
+
createCustomConfig,
|
|
3
5
|
createPathCompat,
|
|
4
6
|
defaultCustomConfigDirPath,
|
|
5
7
|
defaultCustomConfigFilePath,
|
|
6
8
|
execute,
|
|
7
|
-
|
|
9
|
+
getConfig,
|
|
10
|
+
getDefaultCliPath,
|
|
11
|
+
isOperatingSystemSupported,
|
|
8
12
|
operatingSystemName,
|
|
9
13
|
parse,
|
|
10
|
-
|
|
11
|
-
|
|
14
|
+
promptForCliPath,
|
|
15
|
+
resolveCliPath,
|
|
16
|
+
resolvePath,
|
|
17
|
+
transformArgv
|
|
18
|
+
} from "./chunk-FJJOQAVP.js";
|
|
12
19
|
export {
|
|
20
|
+
SupportedPlatformsMap,
|
|
13
21
|
createAlias,
|
|
22
|
+
createCustomConfig,
|
|
14
23
|
createPathCompat,
|
|
15
24
|
defaultCustomConfigDirPath,
|
|
16
25
|
defaultCustomConfigFilePath,
|
|
17
26
|
execute,
|
|
18
|
-
|
|
27
|
+
getConfig,
|
|
28
|
+
getDefaultCliPath,
|
|
29
|
+
isOperatingSystemSupported,
|
|
19
30
|
operatingSystemName,
|
|
20
31
|
parse,
|
|
21
|
-
|
|
32
|
+
promptForCliPath,
|
|
33
|
+
resolveCliPath,
|
|
34
|
+
resolvePath,
|
|
35
|
+
transformArgv
|
|
22
36
|
};
|