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/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "weapp-ide-cli",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "4.0.0-alpha.0",
|
|
5
5
|
"description": "让微信开发者工具,用起来更加方便!",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
63
|
"execa": "9.6.0",
|
|
64
|
-
"fs-extra": "^11.3.
|
|
64
|
+
"fs-extra": "^11.3.2",
|
|
65
65
|
"pathe": "^2.0.3",
|
|
66
66
|
"@weapp-core/logger": "^2.0.0"
|
|
67
67
|
},
|
package/dist/chunk-WCSD523G.js
DELETED
|
@@ -1,236 +0,0 @@
|
|
|
1
|
-
// src/logger.ts
|
|
2
|
-
import logger from "@weapp-core/logger";
|
|
3
|
-
var logger_default = logger;
|
|
4
|
-
|
|
5
|
-
// src/defaults.ts
|
|
6
|
-
import os from "os";
|
|
7
|
-
import process from "process";
|
|
8
|
-
import fs from "fs-extra";
|
|
9
|
-
import path from "pathe";
|
|
10
|
-
var homedir = os.homedir();
|
|
11
|
-
var SupportedPlatformsMap = {
|
|
12
|
-
Windows_NT: "Windows_NT",
|
|
13
|
-
Darwin: "Darwin",
|
|
14
|
-
Linux: "Linux"
|
|
15
|
-
};
|
|
16
|
-
async function getFirstBinaryPath(command) {
|
|
17
|
-
const envPath = process.env.PATH || "";
|
|
18
|
-
const pathDirs = envPath.split(path.delimiter);
|
|
19
|
-
for (const dir of pathDirs) {
|
|
20
|
-
const fullPath = path.join(dir, command);
|
|
21
|
-
try {
|
|
22
|
-
await fs.access(fullPath, fs.constants.X_OK);
|
|
23
|
-
return fullPath;
|
|
24
|
-
} catch {
|
|
25
|
-
continue;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
return void 0;
|
|
29
|
-
}
|
|
30
|
-
var operatingSystemName = os.type();
|
|
31
|
-
var defaultPathMap = {
|
|
32
|
-
[SupportedPlatformsMap.Windows_NT]: "C:\\Program Files (x86)\\Tencent\\\u5FAE\u4FE1web\u5F00\u53D1\u8005\u5DE5\u5177\\cli.bat",
|
|
33
|
-
[SupportedPlatformsMap.Darwin]: "/Applications/wechatwebdevtools.app/Contents/MacOS/cli"
|
|
34
|
-
};
|
|
35
|
-
var linuxPathInitialized = false;
|
|
36
|
-
async function getLinuxDevToolsPath() {
|
|
37
|
-
if (operatingSystemName !== SupportedPlatformsMap.Linux && linuxPathInitialized) {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
try {
|
|
41
|
-
const linuxDevCliPath = await getFirstBinaryPath("wechat-devtools-cli");
|
|
42
|
-
if (linuxDevCliPath) {
|
|
43
|
-
linuxPathInitialized = true;
|
|
44
|
-
defaultPathMap[SupportedPlatformsMap.Linux] = linuxDevCliPath;
|
|
45
|
-
}
|
|
46
|
-
} catch (error) {
|
|
47
|
-
if (error instanceof Error) {
|
|
48
|
-
logger_default.error("\u83B7\u53D6Linux\u5F00\u53D1\u5DE5\u5177 wechat-devtools-cli \u8DEF\u5F84\u5931\u8D25:", error.message);
|
|
49
|
-
} else {
|
|
50
|
-
logger_default.error("\u83B7\u53D6Linux\u5F00\u53D1\u5DE5\u5177 wechat-devtools-cli \u8DEF\u5F84\u5931\u8D25:", error);
|
|
51
|
-
}
|
|
52
|
-
return defaultPathMap[SupportedPlatformsMap.Linux];
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
async function getDefaultPath() {
|
|
56
|
-
await getLinuxDevToolsPath();
|
|
57
|
-
return defaultPathMap[operatingSystemName];
|
|
58
|
-
}
|
|
59
|
-
var defaultCustomConfigDirPath = path.join(homedir, ".weapp-ide-cli");
|
|
60
|
-
var defaultCustomConfigFilePath = path.join(
|
|
61
|
-
defaultCustomConfigDirPath,
|
|
62
|
-
"config.json"
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
// src/utils.ts
|
|
66
|
-
import process2 from "process";
|
|
67
|
-
import path2 from "pathe";
|
|
68
|
-
async function execute(cliPath, argv) {
|
|
69
|
-
const { execa } = await import("execa");
|
|
70
|
-
const task = execa(cliPath, argv);
|
|
71
|
-
task?.stdout?.pipe(process2.stdout);
|
|
72
|
-
await task;
|
|
73
|
-
}
|
|
74
|
-
function resolvePath(filePath) {
|
|
75
|
-
if (path2.isAbsolute(filePath)) {
|
|
76
|
-
return filePath;
|
|
77
|
-
} else {
|
|
78
|
-
return path2.resolve(process2.cwd(), filePath);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
function alias(argv, entry) {
|
|
82
|
-
let findIdx = argv.indexOf(entry.find);
|
|
83
|
-
if (findIdx > -1) {
|
|
84
|
-
argv[findIdx] = entry.replacement;
|
|
85
|
-
} else {
|
|
86
|
-
findIdx = argv.indexOf(entry.replacement);
|
|
87
|
-
}
|
|
88
|
-
if (findIdx > -1) {
|
|
89
|
-
const paramIdx = findIdx + 1;
|
|
90
|
-
const param = argv[paramIdx];
|
|
91
|
-
if (param && param[0] !== "-") {
|
|
92
|
-
argv[paramIdx] = resolvePath(param);
|
|
93
|
-
} else {
|
|
94
|
-
argv.splice(paramIdx, 0, process2.cwd());
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
return argv;
|
|
98
|
-
}
|
|
99
|
-
function pathCompat(argv, option) {
|
|
100
|
-
const findIdx = argv.indexOf(option);
|
|
101
|
-
if (findIdx > -1) {
|
|
102
|
-
const paramIdx = findIdx + 1;
|
|
103
|
-
const param = argv[paramIdx];
|
|
104
|
-
if (param && param[0] !== "-") {
|
|
105
|
-
argv[paramIdx] = resolvePath(param);
|
|
106
|
-
} else {
|
|
107
|
-
argv.splice(paramIdx, 0, process2.cwd());
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
return argv;
|
|
111
|
-
}
|
|
112
|
-
function createAlias(entry) {
|
|
113
|
-
return function(argv) {
|
|
114
|
-
return alias(argv, entry);
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
function createPathCompat(option) {
|
|
118
|
-
return function(argv) {
|
|
119
|
-
return pathCompat(argv, option);
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// src/parse.ts
|
|
124
|
-
import process3 from "process";
|
|
125
|
-
import readline from "readline";
|
|
126
|
-
import fs3 from "fs-extra";
|
|
127
|
-
|
|
128
|
-
// src/compose.ts
|
|
129
|
-
function compose(...funcs) {
|
|
130
|
-
if (funcs.length === 0) {
|
|
131
|
-
return (arg) => arg;
|
|
132
|
-
}
|
|
133
|
-
if (funcs.length === 1) {
|
|
134
|
-
return funcs[0];
|
|
135
|
-
}
|
|
136
|
-
return funcs.reduce(
|
|
137
|
-
(a, b) => (...args) => a(b(...args))
|
|
138
|
-
);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
// src/config.ts
|
|
142
|
-
import fs2 from "fs-extra";
|
|
143
|
-
function createCustomConfig(params) {
|
|
144
|
-
return fs2.outputJSON(
|
|
145
|
-
defaultCustomConfigFilePath,
|
|
146
|
-
{
|
|
147
|
-
cliPath: params.cliPath
|
|
148
|
-
},
|
|
149
|
-
{
|
|
150
|
-
encoding: "utf8",
|
|
151
|
-
spaces: 2
|
|
152
|
-
}
|
|
153
|
-
);
|
|
154
|
-
}
|
|
155
|
-
async function getConfig() {
|
|
156
|
-
const isExisted = await fs2.exists(defaultCustomConfigFilePath);
|
|
157
|
-
if (isExisted) {
|
|
158
|
-
const content = await fs2.readFile(defaultCustomConfigFilePath, {
|
|
159
|
-
encoding: "utf8"
|
|
160
|
-
});
|
|
161
|
-
const config = JSON.parse(content);
|
|
162
|
-
logger_default.log("> \u5168\u5C40\u914D\u7F6E\u6587\u4EF6\u8DEF\u5F84\uFF1A", defaultCustomConfigFilePath);
|
|
163
|
-
logger_default.log("> \u81EA\u5B9A\u4E49cli\u8DEF\u5F84\uFF1A", config.cliPath);
|
|
164
|
-
return config;
|
|
165
|
-
} else {
|
|
166
|
-
return {
|
|
167
|
-
cliPath: await getDefaultPath()
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
// src/parse.ts
|
|
173
|
-
function rlSetConfig() {
|
|
174
|
-
const rl = readline.createInterface({
|
|
175
|
-
input: process3.stdin,
|
|
176
|
-
output: process3.stdout
|
|
177
|
-
});
|
|
178
|
-
logger_default.log("\u8BF7\u8BBE\u7F6E\u5FAE\u4FE1web\u5F00\u53D1\u8005\u5DE5\u5177 cli \u7684\u8DEF\u5F84");
|
|
179
|
-
logger_default.log("> \u63D0\u793A\uFF1A\u547D\u4EE4\u884C\u5DE5\u5177\u9ED8\u8BA4\u6240\u5728\u4F4D\u7F6E\uFF1A");
|
|
180
|
-
logger_default.log("- MacOS: <\u5B89\u88C5\u8DEF\u5F84>/Contents/MacOS/cli");
|
|
181
|
-
logger_default.log("- Windows: <\u5B89\u88C5\u8DEF\u5F84>/cli.bat");
|
|
182
|
-
logger_default.log("- Linux: <\u5B89\u88C5\u8DEF\u5F84>/files/bin/bin/wechat-devtools-cli");
|
|
183
|
-
return new Promise((resolve, _reject) => {
|
|
184
|
-
rl.question("\u8BF7\u8F93\u5165\u5FAE\u4FE1web\u5F00\u53D1\u8005\u5DE5\u5177cli\u8DEF\u5F84\uFF1A", async (cliPath) => {
|
|
185
|
-
await createCustomConfig({
|
|
186
|
-
cliPath
|
|
187
|
-
});
|
|
188
|
-
logger_default.log(`\u5168\u5C40\u914D\u7F6E\u5B58\u50A8\u4F4D\u7F6E\uFF1A${defaultCustomConfigFilePath}`);
|
|
189
|
-
resolve(cliPath);
|
|
190
|
-
});
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
var parseArgv = compose(
|
|
194
|
-
createAlias({ find: "-p", replacement: "--project" }),
|
|
195
|
-
createPathCompat("--result-output"),
|
|
196
|
-
createPathCompat("-r"),
|
|
197
|
-
createPathCompat("--qr-output"),
|
|
198
|
-
createPathCompat("-o"),
|
|
199
|
-
createPathCompat("--info-output"),
|
|
200
|
-
createPathCompat("-i")
|
|
201
|
-
);
|
|
202
|
-
async function parse(argv) {
|
|
203
|
-
const isSupported = Boolean(await getDefaultPath());
|
|
204
|
-
if (isSupported) {
|
|
205
|
-
const { cliPath } = await getConfig();
|
|
206
|
-
const isExisted = await fs3.exists(cliPath);
|
|
207
|
-
if (isExisted) {
|
|
208
|
-
if (argv[0] === "config") {
|
|
209
|
-
await rlSetConfig();
|
|
210
|
-
return;
|
|
211
|
-
}
|
|
212
|
-
const formattedArgv = parseArgv(argv);
|
|
213
|
-
await execute(cliPath, formattedArgv);
|
|
214
|
-
} else {
|
|
215
|
-
logger_default.log(
|
|
216
|
-
"\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"
|
|
217
|
-
);
|
|
218
|
-
await rlSetConfig();
|
|
219
|
-
}
|
|
220
|
-
} else {
|
|
221
|
-
logger_default.log(`\u5FAE\u4FE1web\u5F00\u53D1\u8005\u5DE5\u5177\u4E0D\u652F\u6301\u5F53\u524D\u5E73\u53F0\uFF1A${operatingSystemName} !`);
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
export {
|
|
226
|
-
logger_default,
|
|
227
|
-
operatingSystemName,
|
|
228
|
-
getDefaultPath,
|
|
229
|
-
defaultCustomConfigDirPath,
|
|
230
|
-
defaultCustomConfigFilePath,
|
|
231
|
-
execute,
|
|
232
|
-
resolvePath,
|
|
233
|
-
createAlias,
|
|
234
|
-
createPathCompat,
|
|
235
|
-
parse
|
|
236
|
-
};
|