weapp-ide-cli 3.0.0 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-R555UIVO.js → chunk-WCSD523G.js} +66 -25
- package/dist/cli.cjs +62 -21
- package/dist/cli.js +1 -1
- package/dist/index.cjs +68 -27
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3 -3
- package/package.json +2 -2
|
@@ -1,41 +1,81 @@
|
|
|
1
|
+
// src/logger.ts
|
|
2
|
+
import logger from "@weapp-core/logger";
|
|
3
|
+
var logger_default = logger;
|
|
4
|
+
|
|
1
5
|
// src/defaults.ts
|
|
2
6
|
import os from "os";
|
|
7
|
+
import process from "process";
|
|
8
|
+
import fs from "fs-extra";
|
|
3
9
|
import path from "pathe";
|
|
4
10
|
var homedir = os.homedir();
|
|
5
11
|
var SupportedPlatformsMap = {
|
|
6
12
|
Windows_NT: "Windows_NT",
|
|
7
|
-
Darwin: "Darwin"
|
|
13
|
+
Darwin: "Darwin",
|
|
14
|
+
Linux: "Linux"
|
|
8
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();
|
|
9
31
|
var defaultPathMap = {
|
|
10
32
|
[SupportedPlatformsMap.Windows_NT]: "C:\\Program Files (x86)\\Tencent\\\u5FAE\u4FE1web\u5F00\u53D1\u8005\u5DE5\u5177\\cli.bat",
|
|
11
33
|
[SupportedPlatformsMap.Darwin]: "/Applications/wechatwebdevtools.app/Contents/MacOS/cli"
|
|
12
34
|
};
|
|
13
|
-
var
|
|
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
|
+
}
|
|
14
59
|
var defaultCustomConfigDirPath = path.join(homedir, ".weapp-ide-cli");
|
|
15
60
|
var defaultCustomConfigFilePath = path.join(
|
|
16
61
|
defaultCustomConfigDirPath,
|
|
17
62
|
"config.json"
|
|
18
63
|
);
|
|
19
|
-
var defaultPath = defaultPathMap[operatingSystemName];
|
|
20
|
-
|
|
21
|
-
// src/logger.ts
|
|
22
|
-
import logger from "@weapp-core/logger";
|
|
23
|
-
var logger_default = logger;
|
|
24
64
|
|
|
25
65
|
// src/utils.ts
|
|
26
|
-
import
|
|
66
|
+
import process2 from "process";
|
|
27
67
|
import path2 from "pathe";
|
|
28
68
|
async function execute(cliPath, argv) {
|
|
29
69
|
const { execa } = await import("execa");
|
|
30
70
|
const task = execa(cliPath, argv);
|
|
31
|
-
task?.stdout?.pipe(
|
|
71
|
+
task?.stdout?.pipe(process2.stdout);
|
|
32
72
|
await task;
|
|
33
73
|
}
|
|
34
74
|
function resolvePath(filePath) {
|
|
35
75
|
if (path2.isAbsolute(filePath)) {
|
|
36
76
|
return filePath;
|
|
37
77
|
} else {
|
|
38
|
-
return path2.resolve(
|
|
78
|
+
return path2.resolve(process2.cwd(), filePath);
|
|
39
79
|
}
|
|
40
80
|
}
|
|
41
81
|
function alias(argv, entry) {
|
|
@@ -51,7 +91,7 @@ function alias(argv, entry) {
|
|
|
51
91
|
if (param && param[0] !== "-") {
|
|
52
92
|
argv[paramIdx] = resolvePath(param);
|
|
53
93
|
} else {
|
|
54
|
-
argv.splice(paramIdx, 0,
|
|
94
|
+
argv.splice(paramIdx, 0, process2.cwd());
|
|
55
95
|
}
|
|
56
96
|
}
|
|
57
97
|
return argv;
|
|
@@ -64,7 +104,7 @@ function pathCompat(argv, option) {
|
|
|
64
104
|
if (param && param[0] !== "-") {
|
|
65
105
|
argv[paramIdx] = resolvePath(param);
|
|
66
106
|
} else {
|
|
67
|
-
argv.splice(paramIdx, 0,
|
|
107
|
+
argv.splice(paramIdx, 0, process2.cwd());
|
|
68
108
|
}
|
|
69
109
|
}
|
|
70
110
|
return argv;
|
|
@@ -81,9 +121,9 @@ function createPathCompat(option) {
|
|
|
81
121
|
}
|
|
82
122
|
|
|
83
123
|
// src/parse.ts
|
|
84
|
-
import
|
|
124
|
+
import process3 from "process";
|
|
85
125
|
import readline from "readline";
|
|
86
|
-
import
|
|
126
|
+
import fs3 from "fs-extra";
|
|
87
127
|
|
|
88
128
|
// src/compose.ts
|
|
89
129
|
function compose(...funcs) {
|
|
@@ -99,9 +139,9 @@ function compose(...funcs) {
|
|
|
99
139
|
}
|
|
100
140
|
|
|
101
141
|
// src/config.ts
|
|
102
|
-
import
|
|
142
|
+
import fs2 from "fs-extra";
|
|
103
143
|
function createCustomConfig(params) {
|
|
104
|
-
return
|
|
144
|
+
return fs2.outputJSON(
|
|
105
145
|
defaultCustomConfigFilePath,
|
|
106
146
|
{
|
|
107
147
|
cliPath: params.cliPath
|
|
@@ -113,9 +153,9 @@ function createCustomConfig(params) {
|
|
|
113
153
|
);
|
|
114
154
|
}
|
|
115
155
|
async function getConfig() {
|
|
116
|
-
const isExisted = await
|
|
156
|
+
const isExisted = await fs2.exists(defaultCustomConfigFilePath);
|
|
117
157
|
if (isExisted) {
|
|
118
|
-
const content = await
|
|
158
|
+
const content = await fs2.readFile(defaultCustomConfigFilePath, {
|
|
119
159
|
encoding: "utf8"
|
|
120
160
|
});
|
|
121
161
|
const config = JSON.parse(content);
|
|
@@ -124,22 +164,22 @@ async function getConfig() {
|
|
|
124
164
|
return config;
|
|
125
165
|
} else {
|
|
126
166
|
return {
|
|
127
|
-
cliPath:
|
|
167
|
+
cliPath: await getDefaultPath()
|
|
128
168
|
};
|
|
129
169
|
}
|
|
130
170
|
}
|
|
131
171
|
|
|
132
172
|
// src/parse.ts
|
|
133
|
-
var isSupported = Boolean(defaultPath);
|
|
134
173
|
function rlSetConfig() {
|
|
135
174
|
const rl = readline.createInterface({
|
|
136
|
-
input:
|
|
137
|
-
output:
|
|
175
|
+
input: process3.stdin,
|
|
176
|
+
output: process3.stdout
|
|
138
177
|
});
|
|
139
178
|
logger_default.log("\u8BF7\u8BBE\u7F6E\u5FAE\u4FE1web\u5F00\u53D1\u8005\u5DE5\u5177 cli \u7684\u8DEF\u5F84");
|
|
140
179
|
logger_default.log("> \u63D0\u793A\uFF1A\u547D\u4EE4\u884C\u5DE5\u5177\u9ED8\u8BA4\u6240\u5728\u4F4D\u7F6E\uFF1A");
|
|
141
180
|
logger_default.log("- MacOS: <\u5B89\u88C5\u8DEF\u5F84>/Contents/MacOS/cli");
|
|
142
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");
|
|
143
183
|
return new Promise((resolve, _reject) => {
|
|
144
184
|
rl.question("\u8BF7\u8F93\u5165\u5FAE\u4FE1web\u5F00\u53D1\u8005\u5DE5\u5177cli\u8DEF\u5F84\uFF1A", async (cliPath) => {
|
|
145
185
|
await createCustomConfig({
|
|
@@ -160,9 +200,10 @@ var parseArgv = compose(
|
|
|
160
200
|
createPathCompat("-i")
|
|
161
201
|
);
|
|
162
202
|
async function parse(argv) {
|
|
203
|
+
const isSupported = Boolean(await getDefaultPath());
|
|
163
204
|
if (isSupported) {
|
|
164
205
|
const { cliPath } = await getConfig();
|
|
165
|
-
const isExisted = await
|
|
206
|
+
const isExisted = await fs3.exists(cliPath);
|
|
166
207
|
if (isExisted) {
|
|
167
208
|
if (argv[0] === "config") {
|
|
168
209
|
await rlSetConfig();
|
|
@@ -182,11 +223,11 @@ async function parse(argv) {
|
|
|
182
223
|
}
|
|
183
224
|
|
|
184
225
|
export {
|
|
226
|
+
logger_default,
|
|
185
227
|
operatingSystemName,
|
|
228
|
+
getDefaultPath,
|
|
186
229
|
defaultCustomConfigDirPath,
|
|
187
230
|
defaultCustomConfigFilePath,
|
|
188
|
-
defaultPath,
|
|
189
|
-
logger_default,
|
|
190
231
|
execute,
|
|
191
232
|
resolvePath,
|
|
192
233
|
createAlias,
|
package/dist/cli.cjs
CHANGED
|
@@ -23,16 +23,16 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
23
23
|
));
|
|
24
24
|
|
|
25
25
|
// src/cli.ts
|
|
26
|
-
var
|
|
26
|
+
var import_node_process4 = __toESM(require("process"), 1);
|
|
27
27
|
|
|
28
28
|
// src/logger.ts
|
|
29
29
|
var import_logger = __toESM(require("@weapp-core/logger"), 1);
|
|
30
30
|
var logger_default = import_logger.default;
|
|
31
31
|
|
|
32
32
|
// src/parse.ts
|
|
33
|
-
var
|
|
33
|
+
var import_node_process3 = __toESM(require("process"), 1);
|
|
34
34
|
var import_node_readline = __toESM(require("readline"), 1);
|
|
35
|
-
var
|
|
35
|
+
var import_fs_extra3 = __toESM(require("fs-extra"), 1);
|
|
36
36
|
|
|
37
37
|
// src/compose.ts
|
|
38
38
|
function compose(...funcs) {
|
|
@@ -48,31 +48,71 @@ function compose(...funcs) {
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
// src/config.ts
|
|
51
|
-
var
|
|
51
|
+
var import_fs_extra2 = __toESM(require("fs-extra"), 1);
|
|
52
52
|
|
|
53
53
|
// src/defaults.ts
|
|
54
54
|
var import_node_os = __toESM(require("os"), 1);
|
|
55
|
+
var import_node_process = __toESM(require("process"), 1);
|
|
56
|
+
var import_fs_extra = __toESM(require("fs-extra"), 1);
|
|
55
57
|
var import_pathe = __toESM(require("pathe"), 1);
|
|
56
58
|
var homedir = import_node_os.default.homedir();
|
|
57
59
|
var SupportedPlatformsMap = {
|
|
58
60
|
Windows_NT: "Windows_NT",
|
|
59
|
-
Darwin: "Darwin"
|
|
61
|
+
Darwin: "Darwin",
|
|
62
|
+
Linux: "Linux"
|
|
60
63
|
};
|
|
64
|
+
async function getFirstBinaryPath(command) {
|
|
65
|
+
const envPath = import_node_process.default.env.PATH || "";
|
|
66
|
+
const pathDirs = envPath.split(import_pathe.default.delimiter);
|
|
67
|
+
for (const dir of pathDirs) {
|
|
68
|
+
const fullPath = import_pathe.default.join(dir, command);
|
|
69
|
+
try {
|
|
70
|
+
await import_fs_extra.default.access(fullPath, import_fs_extra.default.constants.X_OK);
|
|
71
|
+
return fullPath;
|
|
72
|
+
} catch {
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return void 0;
|
|
77
|
+
}
|
|
78
|
+
var operatingSystemName = import_node_os.default.type();
|
|
61
79
|
var defaultPathMap = {
|
|
62
80
|
[SupportedPlatformsMap.Windows_NT]: "C:\\Program Files (x86)\\Tencent\\\u5FAE\u4FE1web\u5F00\u53D1\u8005\u5DE5\u5177\\cli.bat",
|
|
63
81
|
[SupportedPlatformsMap.Darwin]: "/Applications/wechatwebdevtools.app/Contents/MacOS/cli"
|
|
64
82
|
};
|
|
65
|
-
var
|
|
83
|
+
var linuxPathInitialized = false;
|
|
84
|
+
async function getLinuxDevToolsPath() {
|
|
85
|
+
if (operatingSystemName !== SupportedPlatformsMap.Linux && linuxPathInitialized) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
try {
|
|
89
|
+
const linuxDevCliPath = await getFirstBinaryPath("wechat-devtools-cli");
|
|
90
|
+
if (linuxDevCliPath) {
|
|
91
|
+
linuxPathInitialized = true;
|
|
92
|
+
defaultPathMap[SupportedPlatformsMap.Linux] = linuxDevCliPath;
|
|
93
|
+
}
|
|
94
|
+
} catch (error) {
|
|
95
|
+
if (error instanceof Error) {
|
|
96
|
+
logger_default.error("\u83B7\u53D6Linux\u5F00\u53D1\u5DE5\u5177 wechat-devtools-cli \u8DEF\u5F84\u5931\u8D25:", error.message);
|
|
97
|
+
} else {
|
|
98
|
+
logger_default.error("\u83B7\u53D6Linux\u5F00\u53D1\u5DE5\u5177 wechat-devtools-cli \u8DEF\u5F84\u5931\u8D25:", error);
|
|
99
|
+
}
|
|
100
|
+
return defaultPathMap[SupportedPlatformsMap.Linux];
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
async function getDefaultPath() {
|
|
104
|
+
await getLinuxDevToolsPath();
|
|
105
|
+
return defaultPathMap[operatingSystemName];
|
|
106
|
+
}
|
|
66
107
|
var defaultCustomConfigDirPath = import_pathe.default.join(homedir, ".weapp-ide-cli");
|
|
67
108
|
var defaultCustomConfigFilePath = import_pathe.default.join(
|
|
68
109
|
defaultCustomConfigDirPath,
|
|
69
110
|
"config.json"
|
|
70
111
|
);
|
|
71
|
-
var defaultPath = defaultPathMap[operatingSystemName];
|
|
72
112
|
|
|
73
113
|
// src/config.ts
|
|
74
114
|
function createCustomConfig(params) {
|
|
75
|
-
return
|
|
115
|
+
return import_fs_extra2.default.outputJSON(
|
|
76
116
|
defaultCustomConfigFilePath,
|
|
77
117
|
{
|
|
78
118
|
cliPath: params.cliPath
|
|
@@ -84,9 +124,9 @@ function createCustomConfig(params) {
|
|
|
84
124
|
);
|
|
85
125
|
}
|
|
86
126
|
async function getConfig() {
|
|
87
|
-
const isExisted = await
|
|
127
|
+
const isExisted = await import_fs_extra2.default.exists(defaultCustomConfigFilePath);
|
|
88
128
|
if (isExisted) {
|
|
89
|
-
const content = await
|
|
129
|
+
const content = await import_fs_extra2.default.readFile(defaultCustomConfigFilePath, {
|
|
90
130
|
encoding: "utf8"
|
|
91
131
|
});
|
|
92
132
|
const config = JSON.parse(content);
|
|
@@ -95,25 +135,25 @@ async function getConfig() {
|
|
|
95
135
|
return config;
|
|
96
136
|
} else {
|
|
97
137
|
return {
|
|
98
|
-
cliPath:
|
|
138
|
+
cliPath: await getDefaultPath()
|
|
99
139
|
};
|
|
100
140
|
}
|
|
101
141
|
}
|
|
102
142
|
|
|
103
143
|
// src/utils.ts
|
|
104
|
-
var
|
|
144
|
+
var import_node_process2 = __toESM(require("process"), 1);
|
|
105
145
|
var import_pathe2 = __toESM(require("pathe"), 1);
|
|
106
146
|
async function execute(cliPath, argv2) {
|
|
107
147
|
const { execa } = await import("execa");
|
|
108
148
|
const task = execa(cliPath, argv2);
|
|
109
|
-
task?.stdout?.pipe(
|
|
149
|
+
task?.stdout?.pipe(import_node_process2.default.stdout);
|
|
110
150
|
await task;
|
|
111
151
|
}
|
|
112
152
|
function resolvePath(filePath) {
|
|
113
153
|
if (import_pathe2.default.isAbsolute(filePath)) {
|
|
114
154
|
return filePath;
|
|
115
155
|
} else {
|
|
116
|
-
return import_pathe2.default.resolve(
|
|
156
|
+
return import_pathe2.default.resolve(import_node_process2.default.cwd(), filePath);
|
|
117
157
|
}
|
|
118
158
|
}
|
|
119
159
|
function alias(argv2, entry) {
|
|
@@ -129,7 +169,7 @@ function alias(argv2, entry) {
|
|
|
129
169
|
if (param && param[0] !== "-") {
|
|
130
170
|
argv2[paramIdx] = resolvePath(param);
|
|
131
171
|
} else {
|
|
132
|
-
argv2.splice(paramIdx, 0,
|
|
172
|
+
argv2.splice(paramIdx, 0, import_node_process2.default.cwd());
|
|
133
173
|
}
|
|
134
174
|
}
|
|
135
175
|
return argv2;
|
|
@@ -142,7 +182,7 @@ function pathCompat(argv2, option) {
|
|
|
142
182
|
if (param && param[0] !== "-") {
|
|
143
183
|
argv2[paramIdx] = resolvePath(param);
|
|
144
184
|
} else {
|
|
145
|
-
argv2.splice(paramIdx, 0,
|
|
185
|
+
argv2.splice(paramIdx, 0, import_node_process2.default.cwd());
|
|
146
186
|
}
|
|
147
187
|
}
|
|
148
188
|
return argv2;
|
|
@@ -159,16 +199,16 @@ function createPathCompat(option) {
|
|
|
159
199
|
}
|
|
160
200
|
|
|
161
201
|
// src/parse.ts
|
|
162
|
-
var isSupported = Boolean(defaultPath);
|
|
163
202
|
function rlSetConfig() {
|
|
164
203
|
const rl = import_node_readline.default.createInterface({
|
|
165
|
-
input:
|
|
166
|
-
output:
|
|
204
|
+
input: import_node_process3.default.stdin,
|
|
205
|
+
output: import_node_process3.default.stdout
|
|
167
206
|
});
|
|
168
207
|
logger_default.log("\u8BF7\u8BBE\u7F6E\u5FAE\u4FE1web\u5F00\u53D1\u8005\u5DE5\u5177 cli \u7684\u8DEF\u5F84");
|
|
169
208
|
logger_default.log("> \u63D0\u793A\uFF1A\u547D\u4EE4\u884C\u5DE5\u5177\u9ED8\u8BA4\u6240\u5728\u4F4D\u7F6E\uFF1A");
|
|
170
209
|
logger_default.log("- MacOS: <\u5B89\u88C5\u8DEF\u5F84>/Contents/MacOS/cli");
|
|
171
210
|
logger_default.log("- Windows: <\u5B89\u88C5\u8DEF\u5F84>/cli.bat");
|
|
211
|
+
logger_default.log("- Linux: <\u5B89\u88C5\u8DEF\u5F84>/files/bin/bin/wechat-devtools-cli");
|
|
172
212
|
return new Promise((resolve, _reject) => {
|
|
173
213
|
rl.question("\u8BF7\u8F93\u5165\u5FAE\u4FE1web\u5F00\u53D1\u8005\u5DE5\u5177cli\u8DEF\u5F84\uFF1A", async (cliPath) => {
|
|
174
214
|
await createCustomConfig({
|
|
@@ -189,9 +229,10 @@ var parseArgv = compose(
|
|
|
189
229
|
createPathCompat("-i")
|
|
190
230
|
);
|
|
191
231
|
async function parse(argv2) {
|
|
232
|
+
const isSupported = Boolean(await getDefaultPath());
|
|
192
233
|
if (isSupported) {
|
|
193
234
|
const { cliPath } = await getConfig();
|
|
194
|
-
const isExisted = await
|
|
235
|
+
const isExisted = await import_fs_extra3.default.exists(cliPath);
|
|
195
236
|
if (isExisted) {
|
|
196
237
|
if (argv2[0] === "config") {
|
|
197
238
|
await rlSetConfig();
|
|
@@ -211,7 +252,7 @@ async function parse(argv2) {
|
|
|
211
252
|
}
|
|
212
253
|
|
|
213
254
|
// src/cli.ts
|
|
214
|
-
var argv =
|
|
255
|
+
var argv = import_node_process4.default.argv.slice(2);
|
|
215
256
|
parse(argv).catch((err) => {
|
|
216
257
|
logger_default.error(err);
|
|
217
258
|
});
|
package/dist/cli.js
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -34,8 +34,8 @@ __export(src_exports, {
|
|
|
34
34
|
createPathCompat: () => createPathCompat,
|
|
35
35
|
defaultCustomConfigDirPath: () => defaultCustomConfigDirPath,
|
|
36
36
|
defaultCustomConfigFilePath: () => defaultCustomConfigFilePath,
|
|
37
|
-
defaultPath: () => defaultPath,
|
|
38
37
|
execute: () => execute,
|
|
38
|
+
getDefaultPath: () => getDefaultPath,
|
|
39
39
|
operatingSystemName: () => operatingSystemName,
|
|
40
40
|
parse: () => parse,
|
|
41
41
|
resolvePath: () => resolvePath
|
|
@@ -44,28 +44,74 @@ module.exports = __toCommonJS(src_exports);
|
|
|
44
44
|
|
|
45
45
|
// src/defaults.ts
|
|
46
46
|
var import_node_os = __toESM(require("os"), 1);
|
|
47
|
+
var import_node_process = __toESM(require("process"), 1);
|
|
48
|
+
var import_fs_extra = __toESM(require("fs-extra"), 1);
|
|
47
49
|
var import_pathe = __toESM(require("pathe"), 1);
|
|
50
|
+
|
|
51
|
+
// src/logger.ts
|
|
52
|
+
var import_logger = __toESM(require("@weapp-core/logger"), 1);
|
|
53
|
+
var logger_default = import_logger.default;
|
|
54
|
+
|
|
55
|
+
// src/defaults.ts
|
|
48
56
|
var homedir = import_node_os.default.homedir();
|
|
49
57
|
var SupportedPlatformsMap = {
|
|
50
58
|
Windows_NT: "Windows_NT",
|
|
51
|
-
Darwin: "Darwin"
|
|
59
|
+
Darwin: "Darwin",
|
|
60
|
+
Linux: "Linux"
|
|
52
61
|
};
|
|
62
|
+
async function getFirstBinaryPath(command) {
|
|
63
|
+
const envPath = import_node_process.default.env.PATH || "";
|
|
64
|
+
const pathDirs = envPath.split(import_pathe.default.delimiter);
|
|
65
|
+
for (const dir of pathDirs) {
|
|
66
|
+
const fullPath = import_pathe.default.join(dir, command);
|
|
67
|
+
try {
|
|
68
|
+
await import_fs_extra.default.access(fullPath, import_fs_extra.default.constants.X_OK);
|
|
69
|
+
return fullPath;
|
|
70
|
+
} catch {
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return void 0;
|
|
75
|
+
}
|
|
76
|
+
var operatingSystemName = import_node_os.default.type();
|
|
53
77
|
var defaultPathMap = {
|
|
54
78
|
[SupportedPlatformsMap.Windows_NT]: "C:\\Program Files (x86)\\Tencent\\\u5FAE\u4FE1web\u5F00\u53D1\u8005\u5DE5\u5177\\cli.bat",
|
|
55
79
|
[SupportedPlatformsMap.Darwin]: "/Applications/wechatwebdevtools.app/Contents/MacOS/cli"
|
|
56
80
|
};
|
|
57
|
-
var
|
|
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
|
+
}
|
|
58
105
|
var defaultCustomConfigDirPath = import_pathe.default.join(homedir, ".weapp-ide-cli");
|
|
59
106
|
var defaultCustomConfigFilePath = import_pathe.default.join(
|
|
60
107
|
defaultCustomConfigDirPath,
|
|
61
108
|
"config.json"
|
|
62
109
|
);
|
|
63
|
-
var defaultPath = defaultPathMap[operatingSystemName];
|
|
64
110
|
|
|
65
111
|
// src/parse.ts
|
|
66
|
-
var
|
|
112
|
+
var import_node_process3 = __toESM(require("process"), 1);
|
|
67
113
|
var import_node_readline = __toESM(require("readline"), 1);
|
|
68
|
-
var
|
|
114
|
+
var import_fs_extra3 = __toESM(require("fs-extra"), 1);
|
|
69
115
|
|
|
70
116
|
// src/compose.ts
|
|
71
117
|
function compose(...funcs) {
|
|
@@ -81,15 +127,9 @@ function compose(...funcs) {
|
|
|
81
127
|
}
|
|
82
128
|
|
|
83
129
|
// src/config.ts
|
|
84
|
-
var
|
|
85
|
-
|
|
86
|
-
// src/logger.ts
|
|
87
|
-
var import_logger = __toESM(require("@weapp-core/logger"), 1);
|
|
88
|
-
var logger_default = import_logger.default;
|
|
89
|
-
|
|
90
|
-
// src/config.ts
|
|
130
|
+
var import_fs_extra2 = __toESM(require("fs-extra"), 1);
|
|
91
131
|
function createCustomConfig(params) {
|
|
92
|
-
return
|
|
132
|
+
return import_fs_extra2.default.outputJSON(
|
|
93
133
|
defaultCustomConfigFilePath,
|
|
94
134
|
{
|
|
95
135
|
cliPath: params.cliPath
|
|
@@ -101,9 +141,9 @@ function createCustomConfig(params) {
|
|
|
101
141
|
);
|
|
102
142
|
}
|
|
103
143
|
async function getConfig() {
|
|
104
|
-
const isExisted = await
|
|
144
|
+
const isExisted = await import_fs_extra2.default.exists(defaultCustomConfigFilePath);
|
|
105
145
|
if (isExisted) {
|
|
106
|
-
const content = await
|
|
146
|
+
const content = await import_fs_extra2.default.readFile(defaultCustomConfigFilePath, {
|
|
107
147
|
encoding: "utf8"
|
|
108
148
|
});
|
|
109
149
|
const config = JSON.parse(content);
|
|
@@ -112,25 +152,25 @@ async function getConfig() {
|
|
|
112
152
|
return config;
|
|
113
153
|
} else {
|
|
114
154
|
return {
|
|
115
|
-
cliPath:
|
|
155
|
+
cliPath: await getDefaultPath()
|
|
116
156
|
};
|
|
117
157
|
}
|
|
118
158
|
}
|
|
119
159
|
|
|
120
160
|
// src/utils.ts
|
|
121
|
-
var
|
|
161
|
+
var import_node_process2 = __toESM(require("process"), 1);
|
|
122
162
|
var import_pathe2 = __toESM(require("pathe"), 1);
|
|
123
163
|
async function execute(cliPath, argv) {
|
|
124
164
|
const { execa } = await import("execa");
|
|
125
165
|
const task = execa(cliPath, argv);
|
|
126
|
-
task?.stdout?.pipe(
|
|
166
|
+
task?.stdout?.pipe(import_node_process2.default.stdout);
|
|
127
167
|
await task;
|
|
128
168
|
}
|
|
129
169
|
function resolvePath(filePath) {
|
|
130
170
|
if (import_pathe2.default.isAbsolute(filePath)) {
|
|
131
171
|
return filePath;
|
|
132
172
|
} else {
|
|
133
|
-
return import_pathe2.default.resolve(
|
|
173
|
+
return import_pathe2.default.resolve(import_node_process2.default.cwd(), filePath);
|
|
134
174
|
}
|
|
135
175
|
}
|
|
136
176
|
function alias(argv, entry) {
|
|
@@ -146,7 +186,7 @@ function alias(argv, entry) {
|
|
|
146
186
|
if (param && param[0] !== "-") {
|
|
147
187
|
argv[paramIdx] = resolvePath(param);
|
|
148
188
|
} else {
|
|
149
|
-
argv.splice(paramIdx, 0,
|
|
189
|
+
argv.splice(paramIdx, 0, import_node_process2.default.cwd());
|
|
150
190
|
}
|
|
151
191
|
}
|
|
152
192
|
return argv;
|
|
@@ -159,7 +199,7 @@ function pathCompat(argv, option) {
|
|
|
159
199
|
if (param && param[0] !== "-") {
|
|
160
200
|
argv[paramIdx] = resolvePath(param);
|
|
161
201
|
} else {
|
|
162
|
-
argv.splice(paramIdx, 0,
|
|
202
|
+
argv.splice(paramIdx, 0, import_node_process2.default.cwd());
|
|
163
203
|
}
|
|
164
204
|
}
|
|
165
205
|
return argv;
|
|
@@ -176,16 +216,16 @@ function createPathCompat(option) {
|
|
|
176
216
|
}
|
|
177
217
|
|
|
178
218
|
// src/parse.ts
|
|
179
|
-
var isSupported = Boolean(defaultPath);
|
|
180
219
|
function rlSetConfig() {
|
|
181
220
|
const rl = import_node_readline.default.createInterface({
|
|
182
|
-
input:
|
|
183
|
-
output:
|
|
221
|
+
input: import_node_process3.default.stdin,
|
|
222
|
+
output: import_node_process3.default.stdout
|
|
184
223
|
});
|
|
185
224
|
logger_default.log("\u8BF7\u8BBE\u7F6E\u5FAE\u4FE1web\u5F00\u53D1\u8005\u5DE5\u5177 cli \u7684\u8DEF\u5F84");
|
|
186
225
|
logger_default.log("> \u63D0\u793A\uFF1A\u547D\u4EE4\u884C\u5DE5\u5177\u9ED8\u8BA4\u6240\u5728\u4F4D\u7F6E\uFF1A");
|
|
187
226
|
logger_default.log("- MacOS: <\u5B89\u88C5\u8DEF\u5F84>/Contents/MacOS/cli");
|
|
188
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");
|
|
189
229
|
return new Promise((resolve, _reject) => {
|
|
190
230
|
rl.question("\u8BF7\u8F93\u5165\u5FAE\u4FE1web\u5F00\u53D1\u8005\u5DE5\u5177cli\u8DEF\u5F84\uFF1A", async (cliPath) => {
|
|
191
231
|
await createCustomConfig({
|
|
@@ -206,9 +246,10 @@ var parseArgv = compose(
|
|
|
206
246
|
createPathCompat("-i")
|
|
207
247
|
);
|
|
208
248
|
async function parse(argv) {
|
|
249
|
+
const isSupported = Boolean(await getDefaultPath());
|
|
209
250
|
if (isSupported) {
|
|
210
251
|
const { cliPath } = await getConfig();
|
|
211
|
-
const isExisted = await
|
|
252
|
+
const isExisted = await import_fs_extra3.default.exists(cliPath);
|
|
212
253
|
if (isExisted) {
|
|
213
254
|
if (argv[0] === "config") {
|
|
214
255
|
await rlSetConfig();
|
|
@@ -232,8 +273,8 @@ async function parse(argv) {
|
|
|
232
273
|
createPathCompat,
|
|
233
274
|
defaultCustomConfigDirPath,
|
|
234
275
|
defaultCustomConfigFilePath,
|
|
235
|
-
defaultPath,
|
|
236
276
|
execute,
|
|
277
|
+
getDefaultPath,
|
|
237
278
|
operatingSystemName,
|
|
238
279
|
parse,
|
|
239
280
|
resolvePath
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
declare const operatingSystemName: string;
|
|
2
|
+
declare function getDefaultPath(): Promise<string>;
|
|
2
3
|
declare const defaultCustomConfigDirPath: string;
|
|
3
4
|
declare const defaultCustomConfigFilePath: string;
|
|
4
|
-
declare const defaultPath: string;
|
|
5
5
|
|
|
6
6
|
declare function parse(argv: string[]): Promise<void>;
|
|
7
7
|
|
|
@@ -18,4 +18,4 @@ declare function resolvePath(filePath: string): string;
|
|
|
18
18
|
declare function createAlias(entry: AliasEntry): (argv: string[]) => string[];
|
|
19
19
|
declare function createPathCompat(option: string): (argv: string[]) => string[];
|
|
20
20
|
|
|
21
|
-
export { type BaseConfig, createAlias, createPathCompat, defaultCustomConfigDirPath, defaultCustomConfigFilePath,
|
|
21
|
+
export { type BaseConfig, createAlias, createPathCompat, defaultCustomConfigDirPath, defaultCustomConfigFilePath, execute, getDefaultPath, operatingSystemName, parse, resolvePath };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
declare const operatingSystemName: string;
|
|
2
|
+
declare function getDefaultPath(): Promise<string>;
|
|
2
3
|
declare const defaultCustomConfigDirPath: string;
|
|
3
4
|
declare const defaultCustomConfigFilePath: string;
|
|
4
|
-
declare const defaultPath: string;
|
|
5
5
|
|
|
6
6
|
declare function parse(argv: string[]): Promise<void>;
|
|
7
7
|
|
|
@@ -18,4 +18,4 @@ declare function resolvePath(filePath: string): string;
|
|
|
18
18
|
declare function createAlias(entry: AliasEntry): (argv: string[]) => string[];
|
|
19
19
|
declare function createPathCompat(option: string): (argv: string[]) => string[];
|
|
20
20
|
|
|
21
|
-
export { type BaseConfig, createAlias, createPathCompat, defaultCustomConfigDirPath, defaultCustomConfigFilePath,
|
|
21
|
+
export { type BaseConfig, createAlias, createPathCompat, defaultCustomConfigDirPath, defaultCustomConfigFilePath, execute, getDefaultPath, operatingSystemName, parse, resolvePath };
|
package/dist/index.js
CHANGED
|
@@ -3,19 +3,19 @@ import {
|
|
|
3
3
|
createPathCompat,
|
|
4
4
|
defaultCustomConfigDirPath,
|
|
5
5
|
defaultCustomConfigFilePath,
|
|
6
|
-
defaultPath,
|
|
7
6
|
execute,
|
|
7
|
+
getDefaultPath,
|
|
8
8
|
operatingSystemName,
|
|
9
9
|
parse,
|
|
10
10
|
resolvePath
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-WCSD523G.js";
|
|
12
12
|
export {
|
|
13
13
|
createAlias,
|
|
14
14
|
createPathCompat,
|
|
15
15
|
defaultCustomConfigDirPath,
|
|
16
16
|
defaultCustomConfigFilePath,
|
|
17
|
-
defaultPath,
|
|
18
17
|
execute,
|
|
18
|
+
getDefaultPath,
|
|
19
19
|
operatingSystemName,
|
|
20
20
|
parse,
|
|
21
21
|
resolvePath
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "weapp-ide-cli",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "3.
|
|
4
|
+
"version": "3.1.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.1",
|
|
65
65
|
"pathe": "^2.0.3",
|
|
66
66
|
"@weapp-core/logger": "^2.0.0"
|
|
67
67
|
},
|