weapp-ide-cli 1.0.0 → 2.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/LICENSE +21 -0
- package/README.md +51 -53
- package/bin/weapp.js +2 -2
- package/dist/chunk-AIRPF73I.js +201 -0
- package/dist/cli.cjs +225 -0
- package/dist/cli.d.cts +2 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +12 -103
- package/dist/index.cjs +246 -0
- package/dist/index.d.cts +21 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +22 -21
- package/package.json +66 -56
- package/dist/types/cli.d.ts +0 -1
- package/dist/types/compose.d.ts +0 -1
- package/dist/types/config.d.ts +0 -3
- package/dist/types/defaults.d.ts +0 -4
- package/dist/types/index.d.ts +0 -3
- package/dist/types/types.d.ts +0 -7
- package/dist/types/utils.d.ts +0 -6
- package/dist/utils-a2548256.js +0 -135
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 ice breaker
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,53 +1,51 @@
|
|
|
1
|
-
# weapp-ide-cli
|
|
2
|
-
|
|
3
|
-
微信开发者工具的命令行(v2) 的一个二次封装的包裹实现,来让开发者更加方便的使用微信开发者工具。
|
|
4
|
-
|
|
5
|
-
> 要使用命令行,注意首先需要在开发者工具的设置 -> 安全设置中开启服务端口。
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
# 在相对的路径,打开微信开发者工具
|
|
28
|
-
# 比如 uni-app 就可以在项目目录执行
|
|
29
|
-
weapp open -p dist/dev/mp-weixin
|
|
30
|
-
# 工具会把相对路径转化为绝对路径,然后打开(绝对路径不转化)
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
## 常用命令
|
|
34
|
-
|
|
35
|
-
1. `weapp login` 在命令行进行微信扫码登录
|
|
36
|
-
2. `weapp open -p` 启动工具进行调试开发
|
|
37
|
-
3. `weapp preview` 开始预览
|
|
38
|
-
4. `weapp upload` 上传代码
|
|
39
|
-
5. `weapp quit` 关闭开发者工具
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
全部的命令请查看 https://developers.weixin.qq.com/miniprogram/dev/devtools/cli.html
|
|
1
|
+
# weapp-ide-cli
|
|
2
|
+
|
|
3
|
+
微信开发者工具的命令行(v2) 的一个二次封装的包裹实现,来让开发者更加方便的使用微信开发者工具。
|
|
4
|
+
|
|
5
|
+
> 要使用命令行,注意首先需要在开发者工具的设置 -> 安全设置中开启服务端口。
|
|
6
|
+
|
|
7
|
+
## 快速安装
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm i -g weapp-ide-cli
|
|
11
|
+
# or
|
|
12
|
+
yarn global add weapp-ide-cli
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
### 执行命令
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
weapp open
|
|
19
|
+
# 等价
|
|
20
|
+
weapp-ide-cli open
|
|
21
|
+
|
|
22
|
+
# 在当前命令行所在位置,打开微信开发者工具
|
|
23
|
+
weapp open -p
|
|
24
|
+
# 等价
|
|
25
|
+
weapp open --project
|
|
26
|
+
|
|
27
|
+
# 在相对的路径,打开微信开发者工具
|
|
28
|
+
# 比如 uni-app 就可以在项目目录执行
|
|
29
|
+
weapp open -p dist/dev/mp-weixin
|
|
30
|
+
# 工具会把相对路径转化为绝对路径,然后打开(绝对路径不转化)
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## 常用命令
|
|
34
|
+
|
|
35
|
+
1. `weapp login` 在命令行进行微信扫码登录
|
|
36
|
+
2. `weapp open -p` 启动工具进行调试开发
|
|
37
|
+
3. `weapp preview` 开始预览
|
|
38
|
+
4. `weapp upload` 上传代码
|
|
39
|
+
5. `weapp quit` 关闭开发者工具
|
|
40
|
+
|
|
41
|
+
### 自定义配置
|
|
42
|
+
|
|
43
|
+
`weapp config` 可以对微信开发者工具的 `cli` 目录进行配置,而配置文件就存放在用户的 `${homedir}/.weapp-ide-cli/config.json` 中,您可以随时进行更改。
|
|
44
|
+
|
|
45
|
+
> 比如 windows 存放位置就在 `C:\Users\${你的用户名}\.weapp-ide-cli/config.json`
|
|
46
|
+
|
|
47
|
+
### 更多命令
|
|
48
|
+
|
|
49
|
+
这个工具本质是一个 `cli` 二次处理工具,所以绝大部分命令都是透传的。
|
|
50
|
+
|
|
51
|
+
全部的命令请查看 <https://developers.weixin.qq.com/miniprogram/dev/devtools/cli.html>
|
package/bin/weapp.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import '../dist/cli.js'
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
// src/defaults.ts
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
var homedir = os.homedir();
|
|
5
|
+
var SupportedPlatformsMap = {
|
|
6
|
+
Windows_NT: "Windows_NT",
|
|
7
|
+
Darwin: "Darwin"
|
|
8
|
+
};
|
|
9
|
+
var defaultPathMap = {
|
|
10
|
+
[SupportedPlatformsMap.Windows_NT]: "C:\\Program Files (x86)\\Tencent\\\u5FAE\u4FE1web\u5F00\u53D1\u8005\u5DE5\u5177\\cli.bat",
|
|
11
|
+
[SupportedPlatformsMap.Darwin]: "/Applications/wechatwebdevtools.app/Contents/MacOS/cli"
|
|
12
|
+
};
|
|
13
|
+
var operatingSystemName = os.type();
|
|
14
|
+
var defaultCustomConfigDirPath = path.join(homedir, ".weapp-ide-cli");
|
|
15
|
+
var defaultCustomConfigFilePath = path.join(
|
|
16
|
+
defaultCustomConfigDirPath,
|
|
17
|
+
"config.json"
|
|
18
|
+
);
|
|
19
|
+
var defaultPath = defaultPathMap[operatingSystemName];
|
|
20
|
+
|
|
21
|
+
// src/logger.ts
|
|
22
|
+
import { createConsola } from "consola";
|
|
23
|
+
var logger_default = createConsola();
|
|
24
|
+
|
|
25
|
+
// src/utils.ts
|
|
26
|
+
import process from "node:process";
|
|
27
|
+
import path2 from "pathe";
|
|
28
|
+
import { execa } from "execa";
|
|
29
|
+
async function execute(cliPath, argv) {
|
|
30
|
+
const task = execa(cliPath, argv);
|
|
31
|
+
task?.stdout?.pipe(process.stdout);
|
|
32
|
+
await task;
|
|
33
|
+
}
|
|
34
|
+
function resolvePath(filePath) {
|
|
35
|
+
if (path2.isAbsolute(filePath)) {
|
|
36
|
+
return filePath;
|
|
37
|
+
} else {
|
|
38
|
+
return path2.resolve(process.cwd(), filePath);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function alias(argv, entry) {
|
|
42
|
+
let findIdx = argv.indexOf(entry.find);
|
|
43
|
+
if (findIdx > -1) {
|
|
44
|
+
argv[findIdx] = entry.replacement;
|
|
45
|
+
} else {
|
|
46
|
+
findIdx = argv.indexOf(entry.replacement);
|
|
47
|
+
}
|
|
48
|
+
if (findIdx > -1) {
|
|
49
|
+
const paramIdx = findIdx + 1;
|
|
50
|
+
const param = argv[paramIdx];
|
|
51
|
+
if (param && param[0] !== "-") {
|
|
52
|
+
argv[paramIdx] = resolvePath(param);
|
|
53
|
+
} else {
|
|
54
|
+
argv.splice(paramIdx, 0, process.cwd());
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return argv;
|
|
58
|
+
}
|
|
59
|
+
function pathCompat(argv, option) {
|
|
60
|
+
const findIdx = argv.indexOf(option);
|
|
61
|
+
if (findIdx > -1) {
|
|
62
|
+
const paramIdx = findIdx + 1;
|
|
63
|
+
const param = argv[paramIdx];
|
|
64
|
+
if (param && param[0] !== "-") {
|
|
65
|
+
argv[paramIdx] = resolvePath(param);
|
|
66
|
+
} else {
|
|
67
|
+
argv.splice(paramIdx, 0, process.cwd());
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return argv;
|
|
71
|
+
}
|
|
72
|
+
function createAlias(entry) {
|
|
73
|
+
return function(argv) {
|
|
74
|
+
return alias(argv, entry);
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
function createPathCompat(option) {
|
|
78
|
+
return function(argv) {
|
|
79
|
+
return pathCompat(argv, option);
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// src/parse.ts
|
|
84
|
+
import readline from "node:readline";
|
|
85
|
+
import process2 from "node:process";
|
|
86
|
+
import fs2 from "fs-extra";
|
|
87
|
+
|
|
88
|
+
// src/config.ts
|
|
89
|
+
import fs from "fs-extra";
|
|
90
|
+
async function createCustomConfig(params) {
|
|
91
|
+
const isExisted = await fs.exists(defaultCustomConfigDirPath);
|
|
92
|
+
if (!isExisted) {
|
|
93
|
+
await fs.mkdir(defaultCustomConfigDirPath, { recursive: true });
|
|
94
|
+
}
|
|
95
|
+
await fs.writeFile(
|
|
96
|
+
defaultCustomConfigFilePath,
|
|
97
|
+
JSON.stringify(
|
|
98
|
+
{
|
|
99
|
+
cliPath: params.cliPath
|
|
100
|
+
},
|
|
101
|
+
null,
|
|
102
|
+
2
|
|
103
|
+
),
|
|
104
|
+
{
|
|
105
|
+
encoding: "utf8"
|
|
106
|
+
}
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
async function getConfig() {
|
|
110
|
+
const isExisted = await fs.exists(defaultCustomConfigFilePath);
|
|
111
|
+
if (isExisted) {
|
|
112
|
+
const content = await fs.readFile(defaultCustomConfigFilePath, {
|
|
113
|
+
encoding: "utf8"
|
|
114
|
+
});
|
|
115
|
+
const config = JSON.parse(content);
|
|
116
|
+
logger_default.log("> \u81EA\u5B9A\u4E49cli\u8DEF\u5F84\uFF1A", config.cliPath);
|
|
117
|
+
return config;
|
|
118
|
+
} else {
|
|
119
|
+
return {
|
|
120
|
+
cliPath: defaultPath
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// src/compose.ts
|
|
126
|
+
function compose(...funcs) {
|
|
127
|
+
if (funcs.length === 0) {
|
|
128
|
+
return (arg) => arg;
|
|
129
|
+
}
|
|
130
|
+
if (funcs.length === 1) {
|
|
131
|
+
return funcs[0];
|
|
132
|
+
}
|
|
133
|
+
return funcs.reduce(
|
|
134
|
+
(a, b) => (...args) => a(b(...args))
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// src/parse.ts
|
|
139
|
+
var rl = readline.createInterface({
|
|
140
|
+
input: process2.stdin,
|
|
141
|
+
output: process2.stdout
|
|
142
|
+
});
|
|
143
|
+
var isSupported = Boolean(defaultPath);
|
|
144
|
+
function rlSetConfig() {
|
|
145
|
+
logger_default.log("\u8BF7\u8BBE\u7F6E\u5FAE\u4FE1web\u5F00\u53D1\u8005\u5DE5\u5177 cli \u7684\u8DEF\u5F84");
|
|
146
|
+
logger_default.log("> \u63D0\u793A\uFF1A\u547D\u4EE4\u884C\u5DE5\u5177\u9ED8\u8BA4\u6240\u5728\u4F4D\u7F6E\uFF1A");
|
|
147
|
+
logger_default.log("- MacOS: <\u5B89\u88C5\u8DEF\u5F84>/Contents/MacOS/cli");
|
|
148
|
+
logger_default.log("- Windows: <\u5B89\u88C5\u8DEF\u5F84>/cli.bat");
|
|
149
|
+
return new Promise((resolve, _reject) => {
|
|
150
|
+
rl.question("\u8BF7\u8F93\u5165\u5FAE\u4FE1web\u5F00\u53D1\u8005\u5DE5\u5177cli\u8DEF\u5F84\uFF1A", async (cliPath) => {
|
|
151
|
+
await createCustomConfig({
|
|
152
|
+
cliPath
|
|
153
|
+
});
|
|
154
|
+
logger_default.log(`\u5168\u5C40\u914D\u7F6E\u5B58\u50A8\u4F4D\u7F6E\uFF1A${defaultCustomConfigFilePath}`);
|
|
155
|
+
resolve(cliPath);
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
var parseArgv = compose(
|
|
160
|
+
createAlias({ find: "-p", replacement: "--project" }),
|
|
161
|
+
createPathCompat("--result-output"),
|
|
162
|
+
createPathCompat("-r"),
|
|
163
|
+
createPathCompat("--qr-output"),
|
|
164
|
+
createPathCompat("-o"),
|
|
165
|
+
createPathCompat("--info-output"),
|
|
166
|
+
createPathCompat("-i")
|
|
167
|
+
);
|
|
168
|
+
async function parse(argv) {
|
|
169
|
+
if (isSupported) {
|
|
170
|
+
const { cliPath } = await getConfig();
|
|
171
|
+
const isExisted = await fs2.exists(cliPath);
|
|
172
|
+
if (isExisted) {
|
|
173
|
+
if (argv[0] === "config") {
|
|
174
|
+
await rlSetConfig();
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
const formattedArgv = parseArgv(argv);
|
|
178
|
+
await execute(cliPath, formattedArgv);
|
|
179
|
+
} else {
|
|
180
|
+
logger_default.log(
|
|
181
|
+
"\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"
|
|
182
|
+
);
|
|
183
|
+
await rlSetConfig();
|
|
184
|
+
}
|
|
185
|
+
} else {
|
|
186
|
+
logger_default.log(`\u5FAE\u4FE1web\u5F00\u53D1\u8005\u5DE5\u5177\u4E0D\u652F\u6301\u5F53\u524D\u5E73\u53F0\uFF1A${operatingSystemName} !`);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export {
|
|
191
|
+
operatingSystemName,
|
|
192
|
+
defaultCustomConfigDirPath,
|
|
193
|
+
defaultCustomConfigFilePath,
|
|
194
|
+
defaultPath,
|
|
195
|
+
logger_default,
|
|
196
|
+
execute,
|
|
197
|
+
resolvePath,
|
|
198
|
+
createAlias,
|
|
199
|
+
createPathCompat,
|
|
200
|
+
parse
|
|
201
|
+
};
|
package/dist/cli.cjs
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
|
|
25
|
+
// src/cli.ts
|
|
26
|
+
var import_node_process3 = __toESM(require("process"), 1);
|
|
27
|
+
|
|
28
|
+
// src/parse.ts
|
|
29
|
+
var import_node_readline = __toESM(require("readline"), 1);
|
|
30
|
+
var import_node_process2 = __toESM(require("process"), 1);
|
|
31
|
+
var import_fs_extra2 = __toESM(require("fs-extra"), 1);
|
|
32
|
+
|
|
33
|
+
// src/defaults.ts
|
|
34
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
35
|
+
var import_node_os = __toESM(require("os"), 1);
|
|
36
|
+
var homedir = import_node_os.default.homedir();
|
|
37
|
+
var SupportedPlatformsMap = {
|
|
38
|
+
Windows_NT: "Windows_NT",
|
|
39
|
+
Darwin: "Darwin"
|
|
40
|
+
};
|
|
41
|
+
var defaultPathMap = {
|
|
42
|
+
[SupportedPlatformsMap.Windows_NT]: "C:\\Program Files (x86)\\Tencent\\\u5FAE\u4FE1web\u5F00\u53D1\u8005\u5DE5\u5177\\cli.bat",
|
|
43
|
+
[SupportedPlatformsMap.Darwin]: "/Applications/wechatwebdevtools.app/Contents/MacOS/cli"
|
|
44
|
+
};
|
|
45
|
+
var operatingSystemName = import_node_os.default.type();
|
|
46
|
+
var defaultCustomConfigDirPath = import_node_path.default.join(homedir, ".weapp-ide-cli");
|
|
47
|
+
var defaultCustomConfigFilePath = import_node_path.default.join(
|
|
48
|
+
defaultCustomConfigDirPath,
|
|
49
|
+
"config.json"
|
|
50
|
+
);
|
|
51
|
+
var defaultPath = defaultPathMap[operatingSystemName];
|
|
52
|
+
|
|
53
|
+
// src/config.ts
|
|
54
|
+
var import_fs_extra = __toESM(require("fs-extra"), 1);
|
|
55
|
+
|
|
56
|
+
// src/logger.ts
|
|
57
|
+
var import_consola = require("consola");
|
|
58
|
+
var logger_default = (0, import_consola.createConsola)();
|
|
59
|
+
|
|
60
|
+
// src/config.ts
|
|
61
|
+
async function createCustomConfig(params) {
|
|
62
|
+
const isExisted = await import_fs_extra.default.exists(defaultCustomConfigDirPath);
|
|
63
|
+
if (!isExisted) {
|
|
64
|
+
await import_fs_extra.default.mkdir(defaultCustomConfigDirPath, { recursive: true });
|
|
65
|
+
}
|
|
66
|
+
await import_fs_extra.default.writeFile(
|
|
67
|
+
defaultCustomConfigFilePath,
|
|
68
|
+
JSON.stringify(
|
|
69
|
+
{
|
|
70
|
+
cliPath: params.cliPath
|
|
71
|
+
},
|
|
72
|
+
null,
|
|
73
|
+
2
|
|
74
|
+
),
|
|
75
|
+
{
|
|
76
|
+
encoding: "utf8"
|
|
77
|
+
}
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
async function getConfig() {
|
|
81
|
+
const isExisted = await import_fs_extra.default.exists(defaultCustomConfigFilePath);
|
|
82
|
+
if (isExisted) {
|
|
83
|
+
const content = await import_fs_extra.default.readFile(defaultCustomConfigFilePath, {
|
|
84
|
+
encoding: "utf8"
|
|
85
|
+
});
|
|
86
|
+
const config = JSON.parse(content);
|
|
87
|
+
logger_default.log("> \u81EA\u5B9A\u4E49cli\u8DEF\u5F84\uFF1A", config.cliPath);
|
|
88
|
+
return config;
|
|
89
|
+
} else {
|
|
90
|
+
return {
|
|
91
|
+
cliPath: defaultPath
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// src/utils.ts
|
|
97
|
+
var import_node_process = __toESM(require("process"), 1);
|
|
98
|
+
var import_pathe = __toESM(require("pathe"), 1);
|
|
99
|
+
var import_execa = require("execa");
|
|
100
|
+
async function execute(cliPath, argv2) {
|
|
101
|
+
const task = (0, import_execa.execa)(cliPath, argv2);
|
|
102
|
+
task?.stdout?.pipe(import_node_process.default.stdout);
|
|
103
|
+
await task;
|
|
104
|
+
}
|
|
105
|
+
function resolvePath(filePath) {
|
|
106
|
+
if (import_pathe.default.isAbsolute(filePath)) {
|
|
107
|
+
return filePath;
|
|
108
|
+
} else {
|
|
109
|
+
return import_pathe.default.resolve(import_node_process.default.cwd(), filePath);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
function alias(argv2, entry) {
|
|
113
|
+
let findIdx = argv2.indexOf(entry.find);
|
|
114
|
+
if (findIdx > -1) {
|
|
115
|
+
argv2[findIdx] = entry.replacement;
|
|
116
|
+
} else {
|
|
117
|
+
findIdx = argv2.indexOf(entry.replacement);
|
|
118
|
+
}
|
|
119
|
+
if (findIdx > -1) {
|
|
120
|
+
const paramIdx = findIdx + 1;
|
|
121
|
+
const param = argv2[paramIdx];
|
|
122
|
+
if (param && param[0] !== "-") {
|
|
123
|
+
argv2[paramIdx] = resolvePath(param);
|
|
124
|
+
} else {
|
|
125
|
+
argv2.splice(paramIdx, 0, import_node_process.default.cwd());
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return argv2;
|
|
129
|
+
}
|
|
130
|
+
function pathCompat(argv2, option) {
|
|
131
|
+
const findIdx = argv2.indexOf(option);
|
|
132
|
+
if (findIdx > -1) {
|
|
133
|
+
const paramIdx = findIdx + 1;
|
|
134
|
+
const param = argv2[paramIdx];
|
|
135
|
+
if (param && param[0] !== "-") {
|
|
136
|
+
argv2[paramIdx] = resolvePath(param);
|
|
137
|
+
} else {
|
|
138
|
+
argv2.splice(paramIdx, 0, import_node_process.default.cwd());
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return argv2;
|
|
142
|
+
}
|
|
143
|
+
function createAlias(entry) {
|
|
144
|
+
return function(argv2) {
|
|
145
|
+
return alias(argv2, entry);
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
function createPathCompat(option) {
|
|
149
|
+
return function(argv2) {
|
|
150
|
+
return pathCompat(argv2, option);
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// src/compose.ts
|
|
155
|
+
function compose(...funcs) {
|
|
156
|
+
if (funcs.length === 0) {
|
|
157
|
+
return (arg) => arg;
|
|
158
|
+
}
|
|
159
|
+
if (funcs.length === 1) {
|
|
160
|
+
return funcs[0];
|
|
161
|
+
}
|
|
162
|
+
return funcs.reduce(
|
|
163
|
+
(a, b) => (...args) => a(b(...args))
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// src/parse.ts
|
|
168
|
+
var rl = import_node_readline.default.createInterface({
|
|
169
|
+
input: import_node_process2.default.stdin,
|
|
170
|
+
output: import_node_process2.default.stdout
|
|
171
|
+
});
|
|
172
|
+
var isSupported = Boolean(defaultPath);
|
|
173
|
+
function rlSetConfig() {
|
|
174
|
+
logger_default.log("\u8BF7\u8BBE\u7F6E\u5FAE\u4FE1web\u5F00\u53D1\u8005\u5DE5\u5177 cli \u7684\u8DEF\u5F84");
|
|
175
|
+
logger_default.log("> \u63D0\u793A\uFF1A\u547D\u4EE4\u884C\u5DE5\u5177\u9ED8\u8BA4\u6240\u5728\u4F4D\u7F6E\uFF1A");
|
|
176
|
+
logger_default.log("- MacOS: <\u5B89\u88C5\u8DEF\u5F84>/Contents/MacOS/cli");
|
|
177
|
+
logger_default.log("- Windows: <\u5B89\u88C5\u8DEF\u5F84>/cli.bat");
|
|
178
|
+
return new Promise((resolve, _reject) => {
|
|
179
|
+
rl.question("\u8BF7\u8F93\u5165\u5FAE\u4FE1web\u5F00\u53D1\u8005\u5DE5\u5177cli\u8DEF\u5F84\uFF1A", async (cliPath) => {
|
|
180
|
+
await createCustomConfig({
|
|
181
|
+
cliPath
|
|
182
|
+
});
|
|
183
|
+
logger_default.log(`\u5168\u5C40\u914D\u7F6E\u5B58\u50A8\u4F4D\u7F6E\uFF1A${defaultCustomConfigFilePath}`);
|
|
184
|
+
resolve(cliPath);
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
var parseArgv = compose(
|
|
189
|
+
createAlias({ find: "-p", replacement: "--project" }),
|
|
190
|
+
createPathCompat("--result-output"),
|
|
191
|
+
createPathCompat("-r"),
|
|
192
|
+
createPathCompat("--qr-output"),
|
|
193
|
+
createPathCompat("-o"),
|
|
194
|
+
createPathCompat("--info-output"),
|
|
195
|
+
createPathCompat("-i")
|
|
196
|
+
);
|
|
197
|
+
async function parse(argv2) {
|
|
198
|
+
if (isSupported) {
|
|
199
|
+
const { cliPath } = await getConfig();
|
|
200
|
+
const isExisted = await import_fs_extra2.default.exists(cliPath);
|
|
201
|
+
if (isExisted) {
|
|
202
|
+
if (argv2[0] === "config") {
|
|
203
|
+
await rlSetConfig();
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
const formattedArgv = parseArgv(argv2);
|
|
207
|
+
await execute(cliPath, formattedArgv);
|
|
208
|
+
} else {
|
|
209
|
+
logger_default.log(
|
|
210
|
+
"\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"
|
|
211
|
+
);
|
|
212
|
+
await rlSetConfig();
|
|
213
|
+
}
|
|
214
|
+
} else {
|
|
215
|
+
logger_default.log(`\u5FAE\u4FE1web\u5F00\u53D1\u8005\u5DE5\u5177\u4E0D\u652F\u6301\u5F53\u524D\u5E73\u53F0\uFF1A${operatingSystemName} !`);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// src/cli.ts
|
|
220
|
+
var argv = import_node_process3.default.argv.slice(2);
|
|
221
|
+
parse(argv).catch((err) => {
|
|
222
|
+
logger_default.error(err);
|
|
223
|
+
}).finally(() => {
|
|
224
|
+
import_node_process3.default.exit();
|
|
225
|
+
});
|
package/dist/cli.d.cts
ADDED
package/dist/cli.d.ts
ADDED
package/dist/cli.js
CHANGED
|
@@ -1,104 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
|
14
|
-
|
|
15
|
-
function createCustomConfig(params) {
|
|
16
|
-
return utils.__awaiter(this, void 0, void 0, function* () {
|
|
17
|
-
const isExisted = yield utils.exist(utils.defaultCustomConfigDirPath);
|
|
18
|
-
if (!isExisted) {
|
|
19
|
-
yield fs__default["default"].mkdir(utils.defaultCustomConfigDirPath, { recursive: true });
|
|
20
|
-
}
|
|
21
|
-
yield fs__default["default"].writeFile(utils.defaultCustomConfigFilePath, JSON.stringify({
|
|
22
|
-
cliPath: params.cliPath
|
|
23
|
-
}, null, 2), {
|
|
24
|
-
encoding: 'utf8'
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
function getConfig() {
|
|
29
|
-
return utils.__awaiter(this, void 0, void 0, function* () {
|
|
30
|
-
const isExisted = yield utils.exist(utils.defaultCustomConfigFilePath);
|
|
31
|
-
if (isExisted) {
|
|
32
|
-
const content = yield fs__default["default"].readFile(utils.defaultCustomConfigFilePath, {
|
|
33
|
-
encoding: 'utf8'
|
|
34
|
-
});
|
|
35
|
-
const config = JSON.parse(content);
|
|
36
|
-
console.log('> 自定义cli路径:', config.cliPath);
|
|
37
|
-
return config;
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
return {
|
|
41
|
-
cliPath: utils.defaultPath
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function compose(...funcs) {
|
|
48
|
-
if (funcs.length === 0) {
|
|
49
|
-
return (arg) => arg;
|
|
50
|
-
}
|
|
51
|
-
if (funcs.length === 1) {
|
|
52
|
-
return funcs[0];
|
|
53
|
-
}
|
|
54
|
-
return funcs.reduce((a, b) => (...args) => a(b(...args)));
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const rl = readline__default["default"].createInterface({
|
|
58
|
-
input: process.stdin,
|
|
59
|
-
output: process.stdout
|
|
60
|
-
});
|
|
61
|
-
const isSupported = Boolean(utils.defaultPath);
|
|
62
|
-
const argv = process.argv.slice(2);
|
|
63
|
-
function rlSetConfig() {
|
|
64
|
-
console.log('请设置微信web开发者工具 cli 的路径');
|
|
65
|
-
console.log('> 提示:命令行工具默认所在位置:');
|
|
66
|
-
console.log('- MacOS: <安装路径>/Contents/MacOS/cli');
|
|
67
|
-
console.log('- Windows: <安装路径>/cli.bat');
|
|
68
|
-
return new Promise((resolve, reject) => {
|
|
69
|
-
rl.question('请输入微信web开发者工具cli路径:', (cliPath) => utils.__awaiter(this, void 0, void 0, function* () {
|
|
70
|
-
yield createCustomConfig({
|
|
71
|
-
cliPath
|
|
72
|
-
});
|
|
73
|
-
console.log(`全局配置存储位置:${utils.defaultCustomConfigFilePath}`);
|
|
74
|
-
resolve(cliPath);
|
|
75
|
-
}));
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
const parseArgv = compose(utils.createAlias({ find: '-p', replacement: '--project' }), utils.createPathCompat('--result-output'), utils.createPathCompat('-r'), utils.createPathCompat('--qr-output'), utils.createPathCompat('-o'), utils.createPathCompat('--info-output'), utils.createPathCompat('-i'));
|
|
79
|
-
function main() {
|
|
80
|
-
return utils.__awaiter(this, void 0, void 0, function* () {
|
|
81
|
-
if (isSupported) {
|
|
82
|
-
const { cliPath } = yield getConfig();
|
|
83
|
-
const isExisted = yield utils.exist(cliPath);
|
|
84
|
-
if (isExisted) {
|
|
85
|
-
if (argv[0] === 'config') {
|
|
86
|
-
yield rlSetConfig();
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
const formattedArgv = parseArgv(argv);
|
|
90
|
-
yield utils.execute(cliPath, formattedArgv);
|
|
91
|
-
}
|
|
92
|
-
else {
|
|
93
|
-
console.log('在当前自定义路径中,未找到微信web开发者命令行工具,请重新指定路径');
|
|
94
|
-
yield rlSetConfig();
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
console.log(`微信web开发者工具不支持当前平台:${utils.operatingSystemName} !`);
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
main().finally(() => {
|
|
103
|
-
process.exit();
|
|
1
|
+
import {
|
|
2
|
+
logger_default,
|
|
3
|
+
parse
|
|
4
|
+
} from "./chunk-AIRPF73I.js";
|
|
5
|
+
|
|
6
|
+
// src/cli.ts
|
|
7
|
+
import process from "node:process";
|
|
8
|
+
var argv = process.argv.slice(2);
|
|
9
|
+
parse(argv).catch((err) => {
|
|
10
|
+
logger_default.error(err);
|
|
11
|
+
}).finally(() => {
|
|
12
|
+
process.exit();
|
|
104
13
|
});
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var src_exports = {};
|
|
32
|
+
__export(src_exports, {
|
|
33
|
+
createAlias: () => createAlias,
|
|
34
|
+
createPathCompat: () => createPathCompat,
|
|
35
|
+
defaultCustomConfigDirPath: () => defaultCustomConfigDirPath,
|
|
36
|
+
defaultCustomConfigFilePath: () => defaultCustomConfigFilePath,
|
|
37
|
+
defaultPath: () => defaultPath,
|
|
38
|
+
execute: () => execute,
|
|
39
|
+
operatingSystemName: () => operatingSystemName,
|
|
40
|
+
parse: () => parse,
|
|
41
|
+
resolvePath: () => resolvePath
|
|
42
|
+
});
|
|
43
|
+
module.exports = __toCommonJS(src_exports);
|
|
44
|
+
|
|
45
|
+
// src/parse.ts
|
|
46
|
+
var import_node_readline = __toESM(require("readline"), 1);
|
|
47
|
+
var import_node_process2 = __toESM(require("process"), 1);
|
|
48
|
+
var import_fs_extra2 = __toESM(require("fs-extra"), 1);
|
|
49
|
+
|
|
50
|
+
// src/defaults.ts
|
|
51
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
52
|
+
var import_node_os = __toESM(require("os"), 1);
|
|
53
|
+
var homedir = import_node_os.default.homedir();
|
|
54
|
+
var SupportedPlatformsMap = {
|
|
55
|
+
Windows_NT: "Windows_NT",
|
|
56
|
+
Darwin: "Darwin"
|
|
57
|
+
};
|
|
58
|
+
var defaultPathMap = {
|
|
59
|
+
[SupportedPlatformsMap.Windows_NT]: "C:\\Program Files (x86)\\Tencent\\\u5FAE\u4FE1web\u5F00\u53D1\u8005\u5DE5\u5177\\cli.bat",
|
|
60
|
+
[SupportedPlatformsMap.Darwin]: "/Applications/wechatwebdevtools.app/Contents/MacOS/cli"
|
|
61
|
+
};
|
|
62
|
+
var operatingSystemName = import_node_os.default.type();
|
|
63
|
+
var defaultCustomConfigDirPath = import_node_path.default.join(homedir, ".weapp-ide-cli");
|
|
64
|
+
var defaultCustomConfigFilePath = import_node_path.default.join(
|
|
65
|
+
defaultCustomConfigDirPath,
|
|
66
|
+
"config.json"
|
|
67
|
+
);
|
|
68
|
+
var defaultPath = defaultPathMap[operatingSystemName];
|
|
69
|
+
|
|
70
|
+
// src/config.ts
|
|
71
|
+
var import_fs_extra = __toESM(require("fs-extra"), 1);
|
|
72
|
+
|
|
73
|
+
// src/logger.ts
|
|
74
|
+
var import_consola = require("consola");
|
|
75
|
+
var logger_default = (0, import_consola.createConsola)();
|
|
76
|
+
|
|
77
|
+
// src/config.ts
|
|
78
|
+
async function createCustomConfig(params) {
|
|
79
|
+
const isExisted = await import_fs_extra.default.exists(defaultCustomConfigDirPath);
|
|
80
|
+
if (!isExisted) {
|
|
81
|
+
await import_fs_extra.default.mkdir(defaultCustomConfigDirPath, { recursive: true });
|
|
82
|
+
}
|
|
83
|
+
await import_fs_extra.default.writeFile(
|
|
84
|
+
defaultCustomConfigFilePath,
|
|
85
|
+
JSON.stringify(
|
|
86
|
+
{
|
|
87
|
+
cliPath: params.cliPath
|
|
88
|
+
},
|
|
89
|
+
null,
|
|
90
|
+
2
|
|
91
|
+
),
|
|
92
|
+
{
|
|
93
|
+
encoding: "utf8"
|
|
94
|
+
}
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
async function getConfig() {
|
|
98
|
+
const isExisted = await import_fs_extra.default.exists(defaultCustomConfigFilePath);
|
|
99
|
+
if (isExisted) {
|
|
100
|
+
const content = await import_fs_extra.default.readFile(defaultCustomConfigFilePath, {
|
|
101
|
+
encoding: "utf8"
|
|
102
|
+
});
|
|
103
|
+
const config = JSON.parse(content);
|
|
104
|
+
logger_default.log("> \u81EA\u5B9A\u4E49cli\u8DEF\u5F84\uFF1A", config.cliPath);
|
|
105
|
+
return config;
|
|
106
|
+
} else {
|
|
107
|
+
return {
|
|
108
|
+
cliPath: defaultPath
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// src/utils.ts
|
|
114
|
+
var import_node_process = __toESM(require("process"), 1);
|
|
115
|
+
var import_pathe = __toESM(require("pathe"), 1);
|
|
116
|
+
var import_execa = require("execa");
|
|
117
|
+
async function execute(cliPath, argv) {
|
|
118
|
+
const task = (0, import_execa.execa)(cliPath, argv);
|
|
119
|
+
task?.stdout?.pipe(import_node_process.default.stdout);
|
|
120
|
+
await task;
|
|
121
|
+
}
|
|
122
|
+
function resolvePath(filePath) {
|
|
123
|
+
if (import_pathe.default.isAbsolute(filePath)) {
|
|
124
|
+
return filePath;
|
|
125
|
+
} else {
|
|
126
|
+
return import_pathe.default.resolve(import_node_process.default.cwd(), filePath);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
function alias(argv, entry) {
|
|
130
|
+
let findIdx = argv.indexOf(entry.find);
|
|
131
|
+
if (findIdx > -1) {
|
|
132
|
+
argv[findIdx] = entry.replacement;
|
|
133
|
+
} else {
|
|
134
|
+
findIdx = argv.indexOf(entry.replacement);
|
|
135
|
+
}
|
|
136
|
+
if (findIdx > -1) {
|
|
137
|
+
const paramIdx = findIdx + 1;
|
|
138
|
+
const param = argv[paramIdx];
|
|
139
|
+
if (param && param[0] !== "-") {
|
|
140
|
+
argv[paramIdx] = resolvePath(param);
|
|
141
|
+
} else {
|
|
142
|
+
argv.splice(paramIdx, 0, import_node_process.default.cwd());
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return argv;
|
|
146
|
+
}
|
|
147
|
+
function pathCompat(argv, option) {
|
|
148
|
+
const findIdx = argv.indexOf(option);
|
|
149
|
+
if (findIdx > -1) {
|
|
150
|
+
const paramIdx = findIdx + 1;
|
|
151
|
+
const param = argv[paramIdx];
|
|
152
|
+
if (param && param[0] !== "-") {
|
|
153
|
+
argv[paramIdx] = resolvePath(param);
|
|
154
|
+
} else {
|
|
155
|
+
argv.splice(paramIdx, 0, import_node_process.default.cwd());
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return argv;
|
|
159
|
+
}
|
|
160
|
+
function createAlias(entry) {
|
|
161
|
+
return function(argv) {
|
|
162
|
+
return alias(argv, entry);
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
function createPathCompat(option) {
|
|
166
|
+
return function(argv) {
|
|
167
|
+
return pathCompat(argv, option);
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// src/compose.ts
|
|
172
|
+
function compose(...funcs) {
|
|
173
|
+
if (funcs.length === 0) {
|
|
174
|
+
return (arg) => arg;
|
|
175
|
+
}
|
|
176
|
+
if (funcs.length === 1) {
|
|
177
|
+
return funcs[0];
|
|
178
|
+
}
|
|
179
|
+
return funcs.reduce(
|
|
180
|
+
(a, b) => (...args) => a(b(...args))
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// src/parse.ts
|
|
185
|
+
var rl = import_node_readline.default.createInterface({
|
|
186
|
+
input: import_node_process2.default.stdin,
|
|
187
|
+
output: import_node_process2.default.stdout
|
|
188
|
+
});
|
|
189
|
+
var isSupported = Boolean(defaultPath);
|
|
190
|
+
function rlSetConfig() {
|
|
191
|
+
logger_default.log("\u8BF7\u8BBE\u7F6E\u5FAE\u4FE1web\u5F00\u53D1\u8005\u5DE5\u5177 cli \u7684\u8DEF\u5F84");
|
|
192
|
+
logger_default.log("> \u63D0\u793A\uFF1A\u547D\u4EE4\u884C\u5DE5\u5177\u9ED8\u8BA4\u6240\u5728\u4F4D\u7F6E\uFF1A");
|
|
193
|
+
logger_default.log("- MacOS: <\u5B89\u88C5\u8DEF\u5F84>/Contents/MacOS/cli");
|
|
194
|
+
logger_default.log("- Windows: <\u5B89\u88C5\u8DEF\u5F84>/cli.bat");
|
|
195
|
+
return new Promise((resolve, _reject) => {
|
|
196
|
+
rl.question("\u8BF7\u8F93\u5165\u5FAE\u4FE1web\u5F00\u53D1\u8005\u5DE5\u5177cli\u8DEF\u5F84\uFF1A", async (cliPath) => {
|
|
197
|
+
await createCustomConfig({
|
|
198
|
+
cliPath
|
|
199
|
+
});
|
|
200
|
+
logger_default.log(`\u5168\u5C40\u914D\u7F6E\u5B58\u50A8\u4F4D\u7F6E\uFF1A${defaultCustomConfigFilePath}`);
|
|
201
|
+
resolve(cliPath);
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
var parseArgv = compose(
|
|
206
|
+
createAlias({ find: "-p", replacement: "--project" }),
|
|
207
|
+
createPathCompat("--result-output"),
|
|
208
|
+
createPathCompat("-r"),
|
|
209
|
+
createPathCompat("--qr-output"),
|
|
210
|
+
createPathCompat("-o"),
|
|
211
|
+
createPathCompat("--info-output"),
|
|
212
|
+
createPathCompat("-i")
|
|
213
|
+
);
|
|
214
|
+
async function parse(argv) {
|
|
215
|
+
if (isSupported) {
|
|
216
|
+
const { cliPath } = await getConfig();
|
|
217
|
+
const isExisted = await import_fs_extra2.default.exists(cliPath);
|
|
218
|
+
if (isExisted) {
|
|
219
|
+
if (argv[0] === "config") {
|
|
220
|
+
await rlSetConfig();
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
const formattedArgv = parseArgv(argv);
|
|
224
|
+
await execute(cliPath, formattedArgv);
|
|
225
|
+
} else {
|
|
226
|
+
logger_default.log(
|
|
227
|
+
"\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"
|
|
228
|
+
);
|
|
229
|
+
await rlSetConfig();
|
|
230
|
+
}
|
|
231
|
+
} else {
|
|
232
|
+
logger_default.log(`\u5FAE\u4FE1web\u5F00\u53D1\u8005\u5DE5\u5177\u4E0D\u652F\u6301\u5F53\u524D\u5E73\u53F0\uFF1A${operatingSystemName} !`);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
236
|
+
0 && (module.exports = {
|
|
237
|
+
createAlias,
|
|
238
|
+
createPathCompat,
|
|
239
|
+
defaultCustomConfigDirPath,
|
|
240
|
+
defaultCustomConfigFilePath,
|
|
241
|
+
defaultPath,
|
|
242
|
+
execute,
|
|
243
|
+
operatingSystemName,
|
|
244
|
+
parse,
|
|
245
|
+
resolvePath
|
|
246
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
interface BaseConfig {
|
|
2
|
+
cliPath: string;
|
|
3
|
+
}
|
|
4
|
+
interface AliasEntry {
|
|
5
|
+
find: string;
|
|
6
|
+
replacement: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
declare function parse(argv: string[]): Promise<void>;
|
|
10
|
+
|
|
11
|
+
declare const operatingSystemName: string;
|
|
12
|
+
declare const defaultCustomConfigDirPath: string;
|
|
13
|
+
declare const defaultCustomConfigFilePath: string;
|
|
14
|
+
declare const defaultPath: string;
|
|
15
|
+
|
|
16
|
+
declare function execute(cliPath: string, argv: string[]): Promise<void>;
|
|
17
|
+
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
|
+
|
|
21
|
+
export { type BaseConfig, createAlias, createPathCompat, defaultCustomConfigDirPath, defaultCustomConfigFilePath, defaultPath, execute, operatingSystemName, parse, resolvePath };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
interface BaseConfig {
|
|
2
|
+
cliPath: string;
|
|
3
|
+
}
|
|
4
|
+
interface AliasEntry {
|
|
5
|
+
find: string;
|
|
6
|
+
replacement: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
declare function parse(argv: string[]): Promise<void>;
|
|
10
|
+
|
|
11
|
+
declare const operatingSystemName: string;
|
|
12
|
+
declare const defaultCustomConfigDirPath: string;
|
|
13
|
+
declare const defaultCustomConfigFilePath: string;
|
|
14
|
+
declare const defaultPath: string;
|
|
15
|
+
|
|
16
|
+
declare function execute(cliPath: string, argv: string[]): Promise<void>;
|
|
17
|
+
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
|
+
|
|
21
|
+
export { type BaseConfig, createAlias, createPathCompat, defaultCustomConfigDirPath, defaultCustomConfigFilePath, defaultPath, execute, operatingSystemName, parse, resolvePath };
|
package/dist/index.js
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
import {
|
|
2
|
+
createAlias,
|
|
3
|
+
createPathCompat,
|
|
4
|
+
defaultCustomConfigDirPath,
|
|
5
|
+
defaultCustomConfigFilePath,
|
|
6
|
+
defaultPath,
|
|
7
|
+
execute,
|
|
8
|
+
operatingSystemName,
|
|
9
|
+
parse,
|
|
10
|
+
resolvePath
|
|
11
|
+
} from "./chunk-AIRPF73I.js";
|
|
12
|
+
export {
|
|
13
|
+
createAlias,
|
|
14
|
+
createPathCompat,
|
|
15
|
+
defaultCustomConfigDirPath,
|
|
16
|
+
defaultCustomConfigFilePath,
|
|
17
|
+
defaultPath,
|
|
18
|
+
execute,
|
|
19
|
+
operatingSystemName,
|
|
20
|
+
parse,
|
|
21
|
+
resolvePath
|
|
22
|
+
};
|
package/package.json
CHANGED
|
@@ -1,56 +1,66 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "weapp-ide-cli",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
"
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
"
|
|
15
|
-
},
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
"
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
"
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
"
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "weapp-ide-cli",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "2.0.0-alpha.0",
|
|
5
|
+
"description": "让微信开发者工具,用起来更加方便!",
|
|
6
|
+
"author": "SonOfMagic <qq1324318532@gmail.com>",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"homepage": "https://github.com/sonofmagic/weapp-tailwindcss",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/sonofmagic/weapp-tailwindcss.git"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/sonofmagic/weapp-tailwindcss/issues"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"weapp",
|
|
18
|
+
"weapp-cli",
|
|
19
|
+
"wechat",
|
|
20
|
+
"cli",
|
|
21
|
+
"uni-app",
|
|
22
|
+
"taro",
|
|
23
|
+
"ide",
|
|
24
|
+
"weapp-ide",
|
|
25
|
+
"mini",
|
|
26
|
+
"miniprogram"
|
|
27
|
+
],
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"import": "./dist/index.js",
|
|
32
|
+
"require": "./dist/index.cjs"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"main": "./dist/index.cjs",
|
|
36
|
+
"module": "./dist/index.js",
|
|
37
|
+
"types": "./dist/index.d.ts",
|
|
38
|
+
"bin": {
|
|
39
|
+
"weapp": "bin/weapp.js",
|
|
40
|
+
"weapp-ide-cli": "bin/weapp.js"
|
|
41
|
+
},
|
|
42
|
+
"files": [
|
|
43
|
+
"bin",
|
|
44
|
+
"dist"
|
|
45
|
+
],
|
|
46
|
+
"publishConfig": {
|
|
47
|
+
"access": "public",
|
|
48
|
+
"registry": "https://registry.npmjs.org/"
|
|
49
|
+
},
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"consola": "^3.2.3",
|
|
52
|
+
"execa": "9.3.0",
|
|
53
|
+
"fs-extra": "^11.2.0",
|
|
54
|
+
"pathe": "^1.1.2"
|
|
55
|
+
},
|
|
56
|
+
"scripts": {
|
|
57
|
+
"dev": "tsup --watch --sourcemap",
|
|
58
|
+
"build": "tsup",
|
|
59
|
+
"release": "node scripts/release.js",
|
|
60
|
+
"test:dev": "vitest",
|
|
61
|
+
"test": "vitest run",
|
|
62
|
+
"weapp": "tsx src/cli.ts",
|
|
63
|
+
"debug": "tsx src/cli.ts config",
|
|
64
|
+
"raw": "node bin/weapp.js"
|
|
65
|
+
}
|
|
66
|
+
}
|
package/dist/types/cli.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/types/compose.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function compose<TArgs extends any[]>(...funcs: TArgs): any;
|
package/dist/types/config.d.ts
DELETED
package/dist/types/defaults.d.ts
DELETED
package/dist/types/index.d.ts
DELETED
package/dist/types/types.d.ts
DELETED
package/dist/types/utils.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { IAliasEntry } from './types';
|
|
2
|
-
export declare function exist(filepath: string, mode?: number): Promise<boolean>;
|
|
3
|
-
export declare function execute(cliPath: string, argv: string[]): Promise<void>;
|
|
4
|
-
export declare function resolvePath(filePath: string): string;
|
|
5
|
-
export declare function createAlias(entry: IAliasEntry): (argv: string[]) => string[];
|
|
6
|
-
export declare function createPathCompat(option: string): (argv: string[]) => string[];
|
package/dist/utils-a2548256.js
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var path = require('path');
|
|
4
|
-
var os = require('os');
|
|
5
|
-
var execa = require('execa');
|
|
6
|
-
var fs = require('fs/promises');
|
|
7
|
-
|
|
8
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
9
|
-
|
|
10
|
-
var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
|
|
11
|
-
var os__default = /*#__PURE__*/_interopDefaultLegacy(os);
|
|
12
|
-
var execa__default = /*#__PURE__*/_interopDefaultLegacy(execa);
|
|
13
|
-
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
|
14
|
-
|
|
15
|
-
const homedir = os__default["default"].homedir();
|
|
16
|
-
const SupportedPlatformsMap = {
|
|
17
|
-
Windows_NT: 'Windows_NT',
|
|
18
|
-
Darwin: 'Darwin'
|
|
19
|
-
};
|
|
20
|
-
const defaultPathMap = {
|
|
21
|
-
[SupportedPlatformsMap.Windows_NT]: 'C:\\Program Files (x86)\\Tencent\\微信web开发者工具\\cli.bat',
|
|
22
|
-
[SupportedPlatformsMap.Darwin]: '/Applications/wechatwebdevtools.app/Contents/MacOS/cli'
|
|
23
|
-
};
|
|
24
|
-
const operatingSystemName = os__default["default"].type();
|
|
25
|
-
const defaultCustomConfigDirPath = path__default["default"].join(homedir, '.weapp-ide-cli');
|
|
26
|
-
const defaultCustomConfigFilePath = path__default["default"].join(defaultCustomConfigDirPath, 'config.json');
|
|
27
|
-
const defaultPath = defaultPathMap[operatingSystemName];
|
|
28
|
-
|
|
29
|
-
/******************************************************************************
|
|
30
|
-
Copyright (c) Microsoft Corporation.
|
|
31
|
-
|
|
32
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
33
|
-
purpose with or without fee is hereby granted.
|
|
34
|
-
|
|
35
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
36
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
37
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
38
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
39
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
40
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
41
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
42
|
-
***************************************************************************** */
|
|
43
|
-
|
|
44
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
45
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
46
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
47
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
48
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
49
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
50
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function exist(filepath, mode) {
|
|
55
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
-
try {
|
|
57
|
-
yield fs__default["default"].access(filepath, mode);
|
|
58
|
-
return true;
|
|
59
|
-
}
|
|
60
|
-
catch (error) {
|
|
61
|
-
return false;
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
function execute(cliPath, argv) {
|
|
66
|
-
var _a;
|
|
67
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
-
const task = execa__default["default"](cliPath, argv);
|
|
69
|
-
(_a = task === null || task === void 0 ? void 0 : task.stdout) === null || _a === void 0 ? void 0 : _a.pipe(process.stdout);
|
|
70
|
-
yield task;
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
function resolvePath(filePath) {
|
|
74
|
-
if (path__default["default"].isAbsolute(filePath)) {
|
|
75
|
-
return filePath;
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
return path__default["default"].resolve(process.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
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
findIdx = argv.indexOf(entry.replacement);
|
|
88
|
-
}
|
|
89
|
-
if (findIdx > -1) {
|
|
90
|
-
const paramIdx = findIdx + 1;
|
|
91
|
-
const param = argv[paramIdx];
|
|
92
|
-
if (param && param[0] !== '-') {
|
|
93
|
-
argv[paramIdx] = resolvePath(param);
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
96
|
-
argv.splice(paramIdx, 0, process.cwd());
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
return argv;
|
|
100
|
-
}
|
|
101
|
-
function pathCompat(argv, option) {
|
|
102
|
-
const findIdx = argv.indexOf(option);
|
|
103
|
-
if (findIdx > -1) {
|
|
104
|
-
const paramIdx = findIdx + 1;
|
|
105
|
-
const param = argv[paramIdx];
|
|
106
|
-
if (param && param[0] !== '-') {
|
|
107
|
-
argv[paramIdx] = resolvePath(param);
|
|
108
|
-
}
|
|
109
|
-
else {
|
|
110
|
-
argv.splice(paramIdx, 0, process.cwd());
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
return argv;
|
|
114
|
-
}
|
|
115
|
-
function createAlias(entry) {
|
|
116
|
-
return function (argv) {
|
|
117
|
-
return alias(argv, entry);
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
function createPathCompat(option) {
|
|
121
|
-
return function (argv) {
|
|
122
|
-
return pathCompat(argv, option);
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
exports.__awaiter = __awaiter;
|
|
127
|
-
exports.createAlias = createAlias;
|
|
128
|
-
exports.createPathCompat = createPathCompat;
|
|
129
|
-
exports.defaultCustomConfigDirPath = defaultCustomConfigDirPath;
|
|
130
|
-
exports.defaultCustomConfigFilePath = defaultCustomConfigFilePath;
|
|
131
|
-
exports.defaultPath = defaultPath;
|
|
132
|
-
exports.execute = execute;
|
|
133
|
-
exports.exist = exist;
|
|
134
|
-
exports.operatingSystemName = operatingSystemName;
|
|
135
|
-
exports.resolvePath = resolvePath;
|