@zrhsh/wukong-cli 0.3.0 → 0.4.1
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 +97 -147
- package/dist/cli.js +61 -34
- package/dist/cli.js.map +1 -1
- package/package.json +2 -2
- package/scripts/install.js +56 -22
package/README.md
CHANGED
|
@@ -1,104 +1,104 @@
|
|
|
1
1
|
# Wukong CLI
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
用于 Oceanet/NRP 系统的 TypeScript CLI 工具,支持 OAuth Device PKCE Flow 认证和自动 token 刷新。
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## 功能特性
|
|
6
6
|
|
|
7
|
-
- 🔐
|
|
8
|
-
- 🔄
|
|
9
|
-
- 🌍
|
|
10
|
-
- 🐛
|
|
11
|
-
- 💾
|
|
12
|
-
- 🛠️ **HTTP
|
|
13
|
-
- ⚙️
|
|
14
|
-
- 🔍
|
|
7
|
+
- 🔐 **安全认证** - OAuth Device PKCE Flow,无需输入密码
|
|
8
|
+
- 🔄 **自动刷新** - Token 过期前自动刷新
|
|
9
|
+
- 🌍 **多环境支持** - 支持 dev、beta、uat 和 prod 环境
|
|
10
|
+
- 🐛 **调试模式** - 使用 `--debug` 标志显示 HTTP 请求和响应
|
|
11
|
+
- 💾 **安全存储** - 使用平台原生凭据管理器,支持文件回退
|
|
12
|
+
- 🛠️ **HTTP 客户端** - 内置 HTTP 客户端,自动处理认证
|
|
13
|
+
- ⚙️ **智能配置** - 内置默认配置,支持用户自定义
|
|
14
|
+
- 🔍 **结构化错误** - 清晰的错误消息和可操作的修复建议
|
|
15
15
|
|
|
16
|
-
##
|
|
16
|
+
## 快速开始
|
|
17
17
|
|
|
18
18
|
```bash
|
|
19
|
-
#
|
|
19
|
+
# 安装
|
|
20
20
|
npm install -g @zrhsh/wukong-cli
|
|
21
21
|
|
|
22
|
-
#
|
|
22
|
+
# 初始化配置
|
|
23
23
|
wukong-cli init
|
|
24
24
|
|
|
25
|
-
#
|
|
25
|
+
# 登录
|
|
26
26
|
wukong-cli auth login
|
|
27
27
|
|
|
28
|
-
#
|
|
28
|
+
# 查看状态
|
|
29
29
|
wukong-cli auth status
|
|
30
30
|
|
|
31
|
-
#
|
|
31
|
+
# 发送 API 请求
|
|
32
32
|
wukong-cli http get "/oceanet-auth/web/userInfo"
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
-
##
|
|
35
|
+
## 开发
|
|
36
36
|
|
|
37
37
|
```bash
|
|
38
|
-
#
|
|
38
|
+
# 克隆仓库
|
|
39
39
|
git clone <repository-url>
|
|
40
40
|
cd wukong-ts-cli
|
|
41
41
|
|
|
42
|
-
#
|
|
42
|
+
# 安装依赖(自动构建项目)
|
|
43
43
|
npm install
|
|
44
44
|
|
|
45
|
-
#
|
|
45
|
+
# 开发模式(直接运行 TypeScript)
|
|
46
46
|
npm run dev <args>
|
|
47
47
|
|
|
48
|
-
#
|
|
48
|
+
# 生产环境构建
|
|
49
49
|
npm run build
|
|
50
50
|
|
|
51
|
-
#
|
|
51
|
+
# 全局链接用于测试
|
|
52
52
|
npm run link
|
|
53
53
|
|
|
54
|
-
#
|
|
54
|
+
# 运行测试
|
|
55
55
|
npm test
|
|
56
56
|
|
|
57
|
-
#
|
|
57
|
+
# 发布前验证
|
|
58
58
|
npm run verify
|
|
59
59
|
```
|
|
60
60
|
|
|
61
61
|
**注意**:项目配置了自动构建脚本(`prepare` 和 `prepack`),在 `npm install` 和 `npm publish` 时会自动构建。如果遇到 `MODULE_NOT_FOUND` 错误,请运行 `npm run build` 手动构建。
|
|
62
62
|
|
|
63
|
-
##
|
|
63
|
+
## 弃用通知
|
|
64
64
|
|
|
65
|
-
⚠️ **Device Flow API
|
|
65
|
+
⚠️ **Device Flow API**:某些内部 API 已标记为弃用,将在 v1.0.0 中移除。这不会影响终端用户的使用。详见 [弃用文档](./docs/deprecation/)。
|
|
66
66
|
|
|
67
|
-
##
|
|
67
|
+
## 命令
|
|
68
68
|
|
|
69
|
-
###
|
|
69
|
+
### 配置命令
|
|
70
70
|
|
|
71
71
|
```bash
|
|
72
|
-
wukong-cli init #
|
|
72
|
+
wukong-cli init # 初始化配置文件
|
|
73
73
|
```
|
|
74
74
|
|
|
75
|
-
###
|
|
75
|
+
### 认证命令
|
|
76
76
|
|
|
77
77
|
```bash
|
|
78
|
-
wukong-cli auth login # OAuth Device PKCE Flow
|
|
79
|
-
wukong-cli auth status #
|
|
80
|
-
wukong-cli auth refresh #
|
|
81
|
-
wukong-cli auth logout #
|
|
78
|
+
wukong-cli auth login # OAuth Device PKCE Flow 登录
|
|
79
|
+
wukong-cli auth status # 显示认证状态
|
|
80
|
+
wukong-cli auth refresh # 刷新访问令牌
|
|
81
|
+
wukong-cli auth logout # 登出并清除令牌
|
|
82
82
|
```
|
|
83
83
|
|
|
84
|
-
### HTTP
|
|
84
|
+
### HTTP 命令
|
|
85
85
|
|
|
86
86
|
```bash
|
|
87
|
-
wukong-cli http get "/endpoint" # GET
|
|
88
|
-
wukong-cli http post "/endpoint" -d '{"key":"value"}' # POST
|
|
89
|
-
wukong-cli http put "/endpoint" -d '{"key":"value"}' # PUT
|
|
90
|
-
wukong-cli http delete "/endpoint" # DELETE
|
|
87
|
+
wukong-cli http get "/endpoint" # GET 请求
|
|
88
|
+
wukong-cli http post "/endpoint" -d '{"key":"value"}' # POST 请求
|
|
89
|
+
wukong-cli http put "/endpoint" -d '{"key":"value"}' # PUT 请求
|
|
90
|
+
wukong-cli http delete "/endpoint" # DELETE 请求
|
|
91
91
|
```
|
|
92
92
|
|
|
93
|
-
###
|
|
93
|
+
### 全局选项
|
|
94
94
|
|
|
95
95
|
```bash
|
|
96
|
-
--debug #
|
|
97
|
-
-V, --version #
|
|
98
|
-
-h, --help #
|
|
96
|
+
--debug # 启用调试模式(显示 HTTP 请求)
|
|
97
|
+
-V, --version # 显示版本号
|
|
98
|
+
-h, --help # 显示帮助信息
|
|
99
99
|
```
|
|
100
100
|
|
|
101
|
-
##
|
|
101
|
+
## 环境切换
|
|
102
102
|
|
|
103
103
|
```bash
|
|
104
104
|
# PowerShell
|
|
@@ -114,28 +114,28 @@ set WUKONG_CLI_ENV=beta
|
|
|
114
114
|
wukong-cli auth login
|
|
115
115
|
```
|
|
116
116
|
|
|
117
|
-
##
|
|
117
|
+
## 配置
|
|
118
118
|
|
|
119
|
-
Wukong CLI
|
|
119
|
+
Wukong CLI 使用智能配置,内置默认值:
|
|
120
120
|
|
|
121
|
-
-
|
|
122
|
-
-
|
|
123
|
-
-
|
|
124
|
-
-
|
|
121
|
+
- **无需配置**:CLI 开箱即用,使用内置的环境默认配置
|
|
122
|
+
- **自定义配置**:可选的 `wukong-cli.json` 用于自定义端点
|
|
123
|
+
- **智能回退**:环境未配置时使用内置默认值
|
|
124
|
+
- **清晰错误**:结构化错误消息指导您修复配置问题
|
|
125
125
|
|
|
126
|
-
###
|
|
126
|
+
### 配置文件位置
|
|
127
127
|
|
|
128
128
|
```bash
|
|
129
|
-
~/wukong-cli.json #
|
|
129
|
+
~/wukong-cli.json # 用户主目录
|
|
130
130
|
```
|
|
131
131
|
|
|
132
|
-
###
|
|
132
|
+
### 初始化配置
|
|
133
133
|
|
|
134
134
|
```bash
|
|
135
|
-
wukong-cli init #
|
|
135
|
+
wukong-cli init # 创建或重置配置文件
|
|
136
136
|
```
|
|
137
137
|
|
|
138
|
-
###
|
|
138
|
+
### 配置示例
|
|
139
139
|
|
|
140
140
|
```json
|
|
141
141
|
{
|
|
@@ -155,9 +155,9 @@ wukong-cli init # Creates or resets configuration file
|
|
|
155
155
|
}
|
|
156
156
|
```
|
|
157
157
|
|
|
158
|
-
###
|
|
158
|
+
### 配置错误
|
|
159
159
|
|
|
160
|
-
|
|
160
|
+
如果配置不完整,您会看到结构化错误消息:
|
|
161
161
|
|
|
162
162
|
```
|
|
163
163
|
[ERROR] Configuration Error
|
|
@@ -169,113 +169,63 @@ Missing fields: apiBaseUrl, clientId
|
|
|
169
169
|
Edit your wukong-cli.json or run 'wukong-cli init' to reset
|
|
170
170
|
```
|
|
171
171
|
|
|
172
|
-
##
|
|
172
|
+
## 文档
|
|
173
173
|
|
|
174
|
-
###
|
|
175
|
-
- 📖 [
|
|
176
|
-
- 📖 [
|
|
177
|
-
- 📖 [Configuration](docs/getting-started/configuration.md) - Environment configuration
|
|
174
|
+
### 入门指南
|
|
175
|
+
- 📖 [快速开始](docs/getting-started/quick-start.md) - 5分钟快速上手
|
|
176
|
+
- 📖 [完整安装配置指南](docs/getting-started/complete-guide.md) - 详细安装和配置步骤
|
|
178
177
|
|
|
179
|
-
###
|
|
180
|
-
- 📖 [
|
|
181
|
-
- 📖 [
|
|
182
|
-
- 📖 [
|
|
183
|
-
- 📖 [
|
|
178
|
+
### 用户指南
|
|
179
|
+
- 📖 [命令参考](docs/user-guide/commands.md) - 完整命令参考
|
|
180
|
+
- 📖 [认证详解](docs/user-guide/authentication.md) - OAuth Device PKCE Flow 详情
|
|
181
|
+
- 📖 [环境配置](docs/user-guide/environments.md) - 多环境配置
|
|
182
|
+
- 📖 [故障排查](docs/user-guide/troubleshooting.md) - 常见问题和解决方案
|
|
184
183
|
|
|
185
|
-
###
|
|
186
|
-
- 📖 [
|
|
187
|
-
- 📖 [
|
|
188
|
-
- 📖 [
|
|
189
|
-
- 📖 [
|
|
184
|
+
### 开发指南
|
|
185
|
+
- 📖 [开发环境设置](docs/development/setup.md) - 开发环境配置
|
|
186
|
+
- 📖 [编码规范](docs/development/coding-standards.md) - 编码规范和最佳实践
|
|
187
|
+
- 📖 [测试指南](docs/development/testing.md) - 测试策略
|
|
188
|
+
- 📖 [贡献指南](docs/development/contributing.md) - 贡献指南
|
|
190
189
|
|
|
191
|
-
###
|
|
192
|
-
- 📖 [
|
|
193
|
-
- 📖 [
|
|
194
|
-
- 📖 [
|
|
190
|
+
### 架构设计
|
|
191
|
+
- 📖 [架构概览](docs/architecture/README.md) - 系统架构文档
|
|
192
|
+
- 📖 [SOLID 改进](docs/architecture/solid-improvements.md) - SOLID 原则应用
|
|
193
|
+
- 📖 [配置系统架构](docs/architecture/configuration.md) - 配置系统设计
|
|
194
|
+
- 📖 [HTTP 客户端](docs/architecture/http-client.md) - HTTP 客户端架构
|
|
195
195
|
|
|
196
|
-
###
|
|
197
|
-
- 📖 [
|
|
196
|
+
### 发布管理
|
|
197
|
+
- 📖 [发布指南](docs/publishing/README.md) - 版本管理和发布流程
|
|
198
|
+
- 📖 [发布说明](docs/publishing/release-notes.md) - 版本更新记录
|
|
198
199
|
|
|
199
|
-
##
|
|
200
|
+
## 项目信息
|
|
200
201
|
|
|
201
|
-
-
|
|
202
|
-
-
|
|
203
|
-
-
|
|
204
|
-
-
|
|
202
|
+
- **版本**: 0.3.0
|
|
203
|
+
- **包名**: @zrhsh/wukong-cli
|
|
204
|
+
- **组织**: @zrhsh
|
|
205
|
+
- **许可证**: MIT
|
|
205
206
|
- **Node.js**: v18+
|
|
206
207
|
- **TypeScript**: 5.x+
|
|
207
208
|
|
|
208
|
-
##
|
|
209
|
+
## 贡献
|
|
209
210
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
# Development installation from source
|
|
215
|
-
git clone <repository-url>
|
|
216
|
-
cd wukong-ts-cli
|
|
217
|
-
npm install
|
|
218
|
-
npm run build
|
|
219
|
-
npm run link
|
|
220
|
-
```
|
|
221
|
-
|
|
222
|
-
## Development
|
|
223
|
-
|
|
224
|
-
```bash
|
|
225
|
-
# Clone repository
|
|
226
|
-
git clone <repository-url>
|
|
227
|
-
cd wukong-ts-cli
|
|
228
|
-
|
|
229
|
-
# Install dependencies
|
|
230
|
-
npm install
|
|
231
|
-
|
|
232
|
-
# Development mode
|
|
233
|
-
npm run dev auth login
|
|
234
|
-
|
|
235
|
-
# Build
|
|
236
|
-
npm run build
|
|
237
|
-
|
|
238
|
-
# Test
|
|
239
|
-
npm run link
|
|
240
|
-
wukong-cli --version
|
|
241
|
-
|
|
242
|
-
# Unit tests
|
|
243
|
-
npm test
|
|
244
|
-
|
|
245
|
-
# E2E tests - Automated (无需用户交互,CI/CD 推荐)
|
|
246
|
-
npm run test:e2e:automated # 默认环境自动化测试
|
|
247
|
-
npm run test:e2e:automated:dev # 开发环境自动化测试
|
|
248
|
-
npm run test:e2e:automated:beta # 测试环境自动化测试
|
|
249
|
-
npm run test:e2e:automated:prod # 生产环境自动化测试
|
|
250
|
-
|
|
251
|
-
# E2E tests - Interactive (需要用户OAuth授权)
|
|
252
|
-
npm run test:e2e:interactive # 默认环境交互式测试
|
|
253
|
-
npm run test:e2e:interactive:dev # 开发环境交互式测试
|
|
254
|
-
npm run test:e2e:interactive:beta # 测试环境交互式测试
|
|
255
|
-
npm run test:e2e:interactive:prod # 生产环境交互式测试
|
|
256
|
-
npm run test:e2e:interactive:run # 带用户引导的交互式测试
|
|
257
|
-
```
|
|
258
|
-
|
|
259
|
-
## Contributing
|
|
260
|
-
|
|
261
|
-
Contributions are welcome! Please see:
|
|
262
|
-
- 📖 [Contributing Guide](docs/development/contributing.md)
|
|
263
|
-
- 📖 [Coding Standards](docs/development/coding-standards.md)
|
|
211
|
+
欢迎贡献!请参阅:
|
|
212
|
+
- 📖 [贡献指南](docs/development/contributing.md)
|
|
213
|
+
- 📖 [编码规范](docs/development/coding-standards.md)
|
|
264
214
|
|
|
265
|
-
##
|
|
215
|
+
## 许可证
|
|
266
216
|
|
|
267
|
-
MIT License -
|
|
217
|
+
MIT License - 详见 [LICENSE](LICENSE) 文件
|
|
268
218
|
|
|
269
|
-
##
|
|
219
|
+
## 支持
|
|
270
220
|
|
|
271
|
-
-
|
|
272
|
-
-
|
|
273
|
-
-
|
|
221
|
+
- **问题反馈**: (GitHub Issues URL)
|
|
222
|
+
- **文档**: (docs/ 目录)
|
|
223
|
+
- **调试模式**: 使用 `--debug` 标志查看详细日志
|
|
274
224
|
|
|
275
|
-
##
|
|
225
|
+
## 版本历史
|
|
276
226
|
|
|
277
|
-
|
|
227
|
+
详见 [发布说明](docs/publishing/release-notes.md)。
|
|
278
228
|
|
|
279
229
|
---
|
|
280
230
|
|
|
281
|
-
|
|
231
|
+
**当前版本**: 0.3.0 | **包名**: @zrhsh/wukong-cli | **组织**: @zrhsh
|
package/dist/cli.js
CHANGED
|
@@ -398,7 +398,12 @@ import { join, dirname } from "path";
|
|
|
398
398
|
import { homedir } from "os";
|
|
399
399
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
400
400
|
function getUserConfigPath() {
|
|
401
|
-
return
|
|
401
|
+
return CONFIG_FILE_PATH;
|
|
402
|
+
}
|
|
403
|
+
function ensureConfigDir() {
|
|
404
|
+
if (!existsSync(CONFIG_DIR)) {
|
|
405
|
+
mkdirSync(CONFIG_DIR, { recursive: true });
|
|
406
|
+
}
|
|
402
407
|
}
|
|
403
408
|
function createDefaultConfig() {
|
|
404
409
|
const configPath = getUserConfigPath();
|
|
@@ -413,10 +418,7 @@ function createDefaultConfig() {
|
|
|
413
418
|
}
|
|
414
419
|
const templateContent = readFileSync(templatePath, "utf-8");
|
|
415
420
|
const defaultConfig = JSON.parse(templateContent);
|
|
416
|
-
|
|
417
|
-
if (!existsSync(dir)) {
|
|
418
|
-
mkdirSync(dir, { recursive: true });
|
|
419
|
-
}
|
|
421
|
+
ensureConfigDir();
|
|
420
422
|
writeFileSync(configPath, JSON.stringify(defaultConfig, null, 2), "utf-8");
|
|
421
423
|
} catch (error) {
|
|
422
424
|
}
|
|
@@ -515,12 +517,15 @@ function getDefaultEnvironment() {
|
|
|
515
517
|
}
|
|
516
518
|
return DEFAULT_ENVIRONMENT;
|
|
517
519
|
}
|
|
520
|
+
var CONFIG_DIR, CONFIG_FILE_PATH;
|
|
518
521
|
var init_config_loader = __esm({
|
|
519
522
|
"src/config/config-loader.ts"() {
|
|
520
523
|
"use strict";
|
|
521
524
|
init_esm_shims();
|
|
522
525
|
init_environments();
|
|
523
526
|
init_config_file_error();
|
|
527
|
+
CONFIG_DIR = join(homedir(), ".wukong-cli");
|
|
528
|
+
CONFIG_FILE_PATH = join(CONFIG_DIR, "wukong-cli.json");
|
|
524
529
|
}
|
|
525
530
|
});
|
|
526
531
|
|
|
@@ -1619,7 +1624,7 @@ var AuthenticatingHttpClient = class {
|
|
|
1619
1624
|
const config2 = getOceanetConfig();
|
|
1620
1625
|
const baseUrl2 = options.baseUrl || config2.API_BASE_URL;
|
|
1621
1626
|
const retryUrl = endpoint.startsWith("http") ? endpoint : `${baseUrl2}${endpoint}`;
|
|
1622
|
-
const retryResponse = await fetch(
|
|
1627
|
+
const retryResponse = await retoken.fetch(
|
|
1623
1628
|
retryUrl,
|
|
1624
1629
|
{
|
|
1625
1630
|
method: options.method || "GET",
|
|
@@ -2022,6 +2027,16 @@ function buildUrl2(url, baseUrl) {
|
|
|
2022
2027
|
const base = baseUrl || config.API_BASE_URL;
|
|
2023
2028
|
return `${base}${cleanUrl}`;
|
|
2024
2029
|
}
|
|
2030
|
+
function parseParams(params) {
|
|
2031
|
+
if (!params || Object.keys(params).length === 0) {
|
|
2032
|
+
return "";
|
|
2033
|
+
}
|
|
2034
|
+
const searchParams = new URLSearchParams();
|
|
2035
|
+
for (const [key, value] of Object.entries(params)) {
|
|
2036
|
+
searchParams.append(key, value);
|
|
2037
|
+
}
|
|
2038
|
+
return `?${searchParams.toString()}`;
|
|
2039
|
+
}
|
|
2025
2040
|
async function executeRequest(method, url, options) {
|
|
2026
2041
|
const spinner = ora4("Sending request...").start();
|
|
2027
2042
|
try {
|
|
@@ -2033,32 +2048,37 @@ async function executeRequest(method, url, options) {
|
|
|
2033
2048
|
}
|
|
2034
2049
|
const fullUrl = buildUrl2(url, options.baseUrl);
|
|
2035
2050
|
const customHeaders = parseHeaders(options.headers);
|
|
2036
|
-
const
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
...customHeaders
|
|
2040
|
-
};
|
|
2041
|
-
let body;
|
|
2042
|
-
if (options.data) {
|
|
2043
|
-
body = options.data;
|
|
2044
|
-
if (!customHeaders["Content-Type"]) {
|
|
2045
|
-
headers["Content-Type"] = "application/json";
|
|
2046
|
-
}
|
|
2047
|
-
}
|
|
2051
|
+
const client = getClient();
|
|
2052
|
+
const requestData = options.data ? JSON.parse(options.data) : void 0;
|
|
2053
|
+
debugRequest(method, fullUrl, { ...customHeaders, "Authorization": "Bearer ***" }, requestData);
|
|
2048
2054
|
spinner.text = `${method} ${chalk5.cyan(fullUrl)}`;
|
|
2049
|
-
debugRequest(method, fullUrl, headers, options.data ? JSON.parse(options.data) : void 0);
|
|
2050
2055
|
const startTime = Date.now();
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
+
let data;
|
|
2057
|
+
switch (method.toUpperCase()) {
|
|
2058
|
+
case "GET":
|
|
2059
|
+
const getUrl = fullUrl + parseParams(options.params);
|
|
2060
|
+
data = await client.get(getUrl);
|
|
2061
|
+
break;
|
|
2062
|
+
case "POST":
|
|
2063
|
+
data = await client.post(fullUrl, requestData, customHeaders);
|
|
2064
|
+
break;
|
|
2065
|
+
case "PUT":
|
|
2066
|
+
data = await client.put(fullUrl, requestData, customHeaders);
|
|
2067
|
+
break;
|
|
2068
|
+
case "DELETE":
|
|
2069
|
+
data = await client.delete(fullUrl);
|
|
2070
|
+
break;
|
|
2071
|
+
case "PATCH":
|
|
2072
|
+
data = await client.patch(fullUrl, requestData, customHeaders);
|
|
2073
|
+
break;
|
|
2074
|
+
default:
|
|
2075
|
+
throw new Error(`Unsupported method: ${method}`);
|
|
2076
|
+
}
|
|
2056
2077
|
const duration = Date.now() - startTime;
|
|
2057
|
-
|
|
2058
|
-
debugResponse(response.status, response.statusText, data, duration);
|
|
2078
|
+
debugResponse(200, "OK", data, duration);
|
|
2059
2079
|
spinner.succeed("Response received");
|
|
2060
2080
|
console.log("");
|
|
2061
|
-
console.log(chalk5.dim("Status:"),
|
|
2081
|
+
console.log(chalk5.dim("Status:"), "200 OK");
|
|
2062
2082
|
console.log("");
|
|
2063
2083
|
console.log(chalk5.dim("Response:"));
|
|
2064
2084
|
console.log(JSON.stringify(data, null, 2));
|
|
@@ -2096,11 +2116,13 @@ httpCommand.command("delete <url>").description("Send DELETE request").option("-
|
|
|
2096
2116
|
// src/commands/init.ts
|
|
2097
2117
|
init_esm_shims();
|
|
2098
2118
|
import { Command as Command3 } from "commander";
|
|
2099
|
-
import { writeFileSync as writeFileSync3, existsSync as existsSync3, readFileSync as readFileSync3 } from "fs";
|
|
2119
|
+
import { writeFileSync as writeFileSync3, existsSync as existsSync3, readFileSync as readFileSync3, mkdirSync as mkdirSync3 } from "fs";
|
|
2100
2120
|
import { join as join3, dirname as dirname3 } from "path";
|
|
2101
2121
|
import { homedir as homedir3 } from "os";
|
|
2102
2122
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
2103
2123
|
import chalk6 from "chalk";
|
|
2124
|
+
var CONFIG_DIR2 = join3(homedir3(), ".wukong-cli");
|
|
2125
|
+
var CONFIG_FILE_PATH2 = join3(CONFIG_DIR2, "wukong-cli.json");
|
|
2104
2126
|
function getProjectRoot2() {
|
|
2105
2127
|
let currentDir = dirname3(fileURLToPath3(import.meta.url));
|
|
2106
2128
|
while (currentDir !== dirname3(currentDir)) {
|
|
@@ -2111,8 +2133,12 @@ function getProjectRoot2() {
|
|
|
2111
2133
|
}
|
|
2112
2134
|
return process.cwd();
|
|
2113
2135
|
}
|
|
2136
|
+
function ensureConfigDir2() {
|
|
2137
|
+
if (!existsSync3(CONFIG_DIR2)) {
|
|
2138
|
+
mkdirSync3(CONFIG_DIR2, { recursive: true });
|
|
2139
|
+
}
|
|
2140
|
+
}
|
|
2114
2141
|
async function executeInit() {
|
|
2115
|
-
const configPath = join3(homedir3(), "wukong-cli.json");
|
|
2116
2142
|
const templatePath = join3(getProjectRoot2(), "wukong-cli.json.template");
|
|
2117
2143
|
if (!existsSync3(templatePath)) {
|
|
2118
2144
|
console.error(chalk6.red("\u274C Template configuration file not found"));
|
|
@@ -2120,14 +2146,15 @@ async function executeInit() {
|
|
|
2120
2146
|
process.exit(1);
|
|
2121
2147
|
}
|
|
2122
2148
|
try {
|
|
2149
|
+
ensureConfigDir2();
|
|
2123
2150
|
const templateContent = readFileSync3(templatePath, "utf-8");
|
|
2124
|
-
const configExists = existsSync3(
|
|
2151
|
+
const configExists = existsSync3(CONFIG_FILE_PATH2);
|
|
2125
2152
|
if (configExists) {
|
|
2126
2153
|
console.log(chalk6.yellow("\u26A0\uFE0F Existing configuration file will be overwritten"));
|
|
2127
2154
|
}
|
|
2128
|
-
writeFileSync3(
|
|
2155
|
+
writeFileSync3(CONFIG_FILE_PATH2, templateContent, "utf-8");
|
|
2129
2156
|
console.log(chalk6.green("\u2705 Configuration file created successfully"));
|
|
2130
|
-
console.log(chalk6.gray(`Location: ${
|
|
2157
|
+
console.log(chalk6.gray(`Location: ${CONFIG_FILE_PATH2}`));
|
|
2131
2158
|
if (configExists) {
|
|
2132
2159
|
console.log(chalk6.yellow("Previous configuration has been overwritten"));
|
|
2133
2160
|
}
|
|
@@ -2144,13 +2171,13 @@ async function executeInit() {
|
|
|
2144
2171
|
process.exit(1);
|
|
2145
2172
|
}
|
|
2146
2173
|
}
|
|
2147
|
-
var initCommand = new Command3("init").description("Initialize configuration file (creates or overwrites
|
|
2174
|
+
var initCommand = new Command3("init").description("Initialize configuration file (creates or overwrites ~/.wukong-cli/wukong-cli.json)").action(async () => {
|
|
2148
2175
|
await executeInit();
|
|
2149
2176
|
});
|
|
2150
2177
|
|
|
2151
2178
|
// src/cli.ts
|
|
2152
2179
|
var program = new Command4();
|
|
2153
|
-
program.name("wukong-cli").description("Wukong CLI - TypeScript implementation").version("0.
|
|
2180
|
+
program.name("wukong-cli").description("Wukong CLI - TypeScript implementation").version("0.4.1").option("-d, --debug", "Enable debug mode (show HTTP requests)").hook("preAction", (thisCommand) => {
|
|
2154
2181
|
const options = thisCommand.opts();
|
|
2155
2182
|
if (options.debug === true) {
|
|
2156
2183
|
setDebugMode(true, true);
|