sino-bc-cli 1.0.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.
Files changed (60) hide show
  1. package/README.md +311 -0
  2. package/dist/SKILL.md +466 -0
  3. package/dist/commands/bc-mcp.command.d.ts +53 -0
  4. package/dist/commands/bc-mcp.command.js +208 -0
  5. package/dist/commands/bc-mcp.command.js.map +1 -0
  6. package/dist/commands/homepage.command.d.ts +19 -0
  7. package/dist/commands/homepage.command.js +96 -0
  8. package/dist/commands/homepage.command.js.map +1 -0
  9. package/dist/commands/index.d.ts +10 -0
  10. package/dist/commands/index.js +23 -0
  11. package/dist/commands/index.js.map +1 -0
  12. package/dist/commands/nexus-swagger.command.d.ts +19 -0
  13. package/dist/commands/nexus-swagger.command.js +95 -0
  14. package/dist/commands/nexus-swagger.command.js.map +1 -0
  15. package/dist/constants/api-doc.d.ts +6 -0
  16. package/dist/constants/api-doc.js +80 -0
  17. package/dist/constants/api-doc.js.map +1 -0
  18. package/dist/constants/gateway.d.ts +31 -0
  19. package/dist/constants/gateway.js +109 -0
  20. package/dist/constants/gateway.js.map +1 -0
  21. package/dist/constants/index.d.ts +38 -0
  22. package/dist/constants/index.js +52 -0
  23. package/dist/constants/index.js.map +1 -0
  24. package/dist/core/cli-app.d.ts +51 -0
  25. package/dist/core/cli-app.js +281 -0
  26. package/dist/core/cli-app.js.map +1 -0
  27. package/dist/core/command-registry.d.ts +71 -0
  28. package/dist/core/command-registry.js +195 -0
  29. package/dist/core/command-registry.js.map +1 -0
  30. package/dist/core/index.d.ts +2 -0
  31. package/dist/core/index.js +9 -0
  32. package/dist/core/index.js.map +1 -0
  33. package/dist/index.d.ts +12 -0
  34. package/dist/index.js +34 -0
  35. package/dist/index.js.map +1 -0
  36. package/dist/types/index.d.ts +120 -0
  37. package/dist/types/index.js +46 -0
  38. package/dist/types/index.js.map +1 -0
  39. package/dist/utils/browser.d.ts +36 -0
  40. package/dist/utils/browser.js +143 -0
  41. package/dist/utils/browser.js.map +1 -0
  42. package/dist/utils/common.d.ts +97 -0
  43. package/dist/utils/common.js +198 -0
  44. package/dist/utils/common.js.map +1 -0
  45. package/dist/utils/crypto.d.ts +53 -0
  46. package/dist/utils/crypto.js +153 -0
  47. package/dist/utils/crypto.js.map +1 -0
  48. package/dist/utils/http.d.ts +58 -0
  49. package/dist/utils/http.js +187 -0
  50. package/dist/utils/http.js.map +1 -0
  51. package/dist/utils/index.d.ts +6 -0
  52. package/dist/utils/index.js +16 -0
  53. package/dist/utils/index.js.map +1 -0
  54. package/dist/utils/logger.d.ts +56 -0
  55. package/dist/utils/logger.js +161 -0
  56. package/dist/utils/logger.js.map +1 -0
  57. package/dist/utils/prompt.d.ts +18 -0
  58. package/dist/utils/prompt.js +77 -0
  59. package/dist/utils/prompt.js.map +1 -0
  60. package/package.json +63 -0
package/README.md ADDED
@@ -0,0 +1,311 @@
1
+ # sino-bc-cli
2
+
3
+ BeyondClick 命令行工具集合 - 提供快捷访问 BeyondClick 平台的命令行接口。
4
+
5
+ ---
6
+
7
+ ## 📚 技术栈说明
8
+
9
+ | 技术/依赖 | 版本要求 | 用途说明 |
10
+ | :------------- | :----------- | :------------------------------------------------------ |
11
+ | **Node.js** | `>= v24.0.0` | CLI 运行时环境,要求使用 v24 及以上版本 |
12
+ | **TypeScript** | `^v5.5.0` | 开发语言,提供静态类型检查和更好的可维护性 |
13
+ | **lodash** | `^4.17.21` | 工具函数库,提供对象/数组/字符串处理等高效方法 |
14
+ | **dayjs** | `^1.11.11` | 轻量级日期处理库,替代 Moment.js 处理日期时间格式化 |
15
+ | **axios** | `^1.7.0` | HTTP 客户端库,用于网络请求、连通性检测等 |
16
+ | **crypto-js** | `^4.2.0` | 加密算法库,提供 MD5、SHA-256、AES、Base64 等加解密能力 |
17
+ | **commander** | `^12.1.0` | 命令行参数解析框架(预留,当前采用自研注册器模式) |
18
+ | **chalk** | `^4.1.2` | 终端彩色输出库,用于美化日志和帮助信息 |
19
+ | **open** | `^8.4.2` | 跨平台文件/URL 打开工具(兼容备用方案) |
20
+
21
+ ### 开发依赖
22
+
23
+ | 依赖 | 版本 | 用途 |
24
+ | :----------------- | :-------- | :-------------------------------- |
25
+ | `@types/node` | `^22.0.0` | Node.js 类型声明 |
26
+ | `@types/lodash` | `^4.17.5` | lodash 类型声明 |
27
+ | `@types/crypto-js` | `^4.2.2` | crypto-js 类型声明 |
28
+ | `ts-node` | `^10.9.2` | 开发阶段直接运行 TypeScript 代码 |
29
+ | `rimraf` | `^5.0.7` | 跨平台目录清理工具,替代 `rm -rf` |
30
+
31
+ ---
32
+
33
+ ## 📁 项目结构说明
34
+
35
+ 项目采用 **模块化、低耦合、高内聚** 的分层设计,便于后续扩展和维护。
36
+
37
+ ```
38
+ sino-bc-cli/
39
+ ├── src/ # 源代码目录(TypeScript)
40
+ │ ├── index.ts # 🚀 CLI 入口文件,bin 关联点
41
+ │ │
42
+ │ ├── core/ # 🧠 核心模块层
43
+ │ │ ├── index.ts # 核心模块统一导出
44
+ │ │ ├── cli-app.ts # CLI 应用主类(参数解析、帮助展示、命令分发)
45
+ │ │ └── command-registry.ts # 命令注册器(注册、查找、执行、注销命令)
46
+ │ │
47
+ │ ├── commands/ # 📦 命令实现层(每命令一个文件,可独立扩展)
48
+ │ │ ├── index.ts # 命令批量注册入口
49
+ │ │ ├── homepage.command.ts # /homepage 命令实现(打开业务平台主页)
50
+ │ │ └── nexus-swagger.command.ts # /nexus-swagger 命令实现(打开 Nexus Swagger 文档页)
51
+ │ │
52
+ │ ├── utils/ # 🛠 工具类层(高内聚的可复用工具)
53
+ │ │ ├── index.ts # 工具模块统一导出
54
+ │ │ ├── logger.ts # 日志工具(多级别彩色输出 + 时间戳)
55
+ │ │ ├── browser.ts # 浏览器工具(跨平台 URL 打开,兼容 Win/macOS/Linux)
56
+ │ │ ├── crypto.ts # 加密工具(MD5、SHA-256、AES、Base64、签名生成)
57
+ │ │ ├── http.ts # HTTP 工具(axios 封装:请求/响应拦截、自动重试)
58
+ │ │ └── common.ts # 通用工具(日期、深拷贝、防抖节流、ID 生成等)
59
+ │ │
60
+ │ ├── types/ # 📝 类型定义层
61
+ │ │ └── index.ts # 全局接口、枚举定义(ICommand、LogLevel 等)
62
+ │ │
63
+ │ └── constants/ # 🔧 常量配置层
64
+ │ └── index.ts # CLI 配置、URL 配置、命令名称、默认值
65
+ │
66
+ ├── dist/ # 📤 编译输出目录(编译后自动生成)
67
+ │ └── ... # JavaScript 编译产物 + 类型声明 + SourceMap
68
+ │
69
+ ├── package.json # 📄 项目配置(依赖、脚本、bin 命令)
70
+ ├── tsconfig.json # 📄 TypeScript 编译配置
71
+ ├── .gitignore # 📄 Git 忽略配置
72
+ └── README.md # 📖 项目说明文档
73
+ ```
74
+
75
+ ### 架构设计原则
76
+
77
+ 1. **分层清晰**:`core → commands → utils → types/constants`,上层依赖下层,单向依赖无循环
78
+ 2. **低耦合**:命令之间互相独立,通过注册器统一管理;新增命令只需在 `commands/` 下新建文件并加入 `commands/index.ts` 数组
79
+ 3. **高内聚**:每个工具类只负责单一职责(如 `BrowserUtils` 只处理浏览器打开,`CryptoUtils` 只处理加解密)
80
+ 4. **可扩展**:
81
+ - 新增命令:实现 `ICommand` 接口 → 放入 `commands/index.ts` 数组即可自动注册
82
+ - 新增工具:在 `utils/` 下新建类,通过 `utils/index.ts` 导出
83
+ - 命令注册器支持运行时动态注册/注销命令
84
+
85
+ ---
86
+
87
+ ## 🚀 项目使用说明
88
+
89
+ ### 1. 环境要求
90
+
91
+ 确保已安装 **Node.js v24** 或更高版本:
92
+
93
+ ```bash
94
+ # 查看 Node.js 版本
95
+ node -v
96
+ # 要求输出 v24.x.x 或更高
97
+
98
+ # 查看 npm 版本
99
+ npm -v
100
+ ```
101
+
102
+ > 如果 Node.js 版本不符合要求,建议通过 [nvm (Node Version Manager)](https://github.com/nvm-sh/nvm) 或 [nvm-windows](https://github.com/coreybutler/nvm-windows) 进行安装和版本管理。
103
+
104
+ ### 2. 安装依赖
105
+
106
+ 在项目根目录下执行:
107
+
108
+ ```bash
109
+ npm install
110
+ ```
111
+
112
+ 依赖安装完成后,`node_modules/` 目录将生成。
113
+
114
+ ### 3. 编译项目
115
+
116
+ 项目使用 TypeScript 编写,需要编译为 JavaScript 后才能运行:
117
+
118
+ ```bash
119
+ # 编译(生成 dist/ 目录)
120
+ npm run build
121
+
122
+ # 清理旧的编译产物并重新编译
123
+ npm run rebuild
124
+ ```
125
+
126
+ 编译完成后,`dist/` 目录将包含:
127
+
128
+ - `*.js` — 编译后的 JavaScript 代码
129
+ - `*.d.ts` — TypeScript 类型声明文件
130
+ - `*.js.map` — SourceMap 调试映射文件
131
+
132
+ ### 4. 开发模式(免编译运行)
133
+
134
+ 开发阶段可使用 `ts-node` 直接运行 TypeScript 代码,无需手动编译:
135
+
136
+ ```bash
137
+ # 直接运行 TypeScript 源码
138
+ npm run dev -- [参数]
139
+
140
+ # 示例:查看帮助
141
+ npm run dev -- --help
142
+
143
+ # 示例:执行 /homepage 命令
144
+ npm run dev -- /homepage
145
+ ```
146
+
147
+ ### 5. 全局安装(推荐)
148
+
149
+ 将 CLI 工具链接为全局命令,可在任意目录下直接使用 `sino-bc-cli`:
150
+
151
+ ```bash
152
+ # 方式一:从源码目录全局链接(开发/测试场景)
153
+ cd d:\Project\demo\sino-bc-cli
154
+ npm run build # 必须先编译
155
+ npm link # 全局链接(Windows 下需要管理员权限)
156
+
157
+ # 方式二:后续发布到 npm 后
158
+ npm i sino-bc-cli -g
159
+ ```
160
+
161
+ 安装完成后,即可在任意终端直接使用:
162
+
163
+ ```bash
164
+ sino-bc-cli --help
165
+ sino-bc-cli /homepage
166
+ ```
167
+
168
+ > 卸载全局链接:`npm unlink` 或 `npm uninstall -g sino-bc-cli`
169
+
170
+ ---
171
+
172
+ ## 📖 命令说明
173
+
174
+ ### 可用命令一览
175
+
176
+ | 命令 | 说明 |
177
+ | :--------------- | :----------------------------------------------------------------------------------------------------------------- |
178
+ | `/homepage` | 使用默认浏览器打开 BeyondClick 业务平台主页 (`https://business.beyondclick.com/`) |
179
+ | `/nexus-swagger` | 使用默认浏览器打开 BeyondClick Nexus Swagger 文档页 (`https://o-test-sino-bc-nexus.meetsocial.com/doc.html#/home`) |
180
+
181
+ ### 全局选项
182
+
183
+ | 选项 | 短选项 | 说明 |
184
+ | :---------- | :----- | :---------------------------------------- |
185
+ | `--version` | `-v` | 显示版本信息 |
186
+ | `--help` | `-h` | 显示帮助信息 |
187
+ | `--debug` | `-d` | 启用 Debug 日志模式,输出更详细的运行信息 |
188
+
189
+ ### 使用示例
190
+
191
+ #### ① 查看版本和帮助
192
+
193
+ ```bash
194
+ # 查看版本号
195
+ sino-bc-cli --version
196
+ sino-bc-cli -v
197
+
198
+ # 查看帮助文档(含所有可用命令列表)
199
+ sino-bc-cli --help
200
+ sino-bc-cli -h
201
+ ```
202
+
203
+ #### ② 打开 BeyondClick 业务平台主页
204
+
205
+ ```bash
206
+ sino-bc-cli /homepage
207
+ ```
208
+
209
+ 执行效果:自动调用系统默认浏览器打开 `https://business.beyondclick.com/`。
210
+
211
+ #### ③ 打开 BeyondClick Nexus Swagger 文档页
212
+
213
+ ```bash
214
+ sino-bc-cli /nexus-swagger
215
+ ```
216
+
217
+ 执行效果:自动调用系统默认浏览器打开 Nexus Swagger 文档页。
218
+
219
+ #### ④ 启用 Debug 模式运行
220
+
221
+ ```bash
222
+ sino-bc-cli --debug /homepage
223
+ # 或使用短选项
224
+ sino-bc-cli -d /nexus-swagger
225
+ ```
226
+
227
+ Debug 模式会输出详细的日志,包括参数解析、命令注册、URL 打开过程等信息,便于排查问题。
228
+
229
+ ---
230
+
231
+ ## 🌐 跨平台兼容性
232
+
233
+ 本工具已针对以下操作系统进行兼容性处理:
234
+
235
+ | 操作系统 | 测试状态 | 打开浏览器方式 |
236
+ | :--------------------------- | :------- | :----------------------------------------------------------------- |
237
+ | **Windows** (10/11) | ✅ 支持 | 使用 `cmd /c start "" "url"`,已处理 URL 中 `&`/`^` 等特殊字符转义 |
238
+ | **macOS** | ✅ 支持 | 使用系统 `open` 命令 |
239
+ | **Linux** (Ubuntu/CentOS 等) | ✅ 支持 | 使用 `xdg-open` 命令 |
240
+
241
+ > 所有平台均通过 Node.js 内置 `child_process.exec` 调用,**不依赖任何 native 模块**,确保跨平台一致性。
242
+
243
+ ---
244
+
245
+ ## 📦 NPM 脚本说明
246
+
247
+ 在 `package.json` 中预定义了以下脚本:
248
+
249
+ ```bash
250
+ # 编译 TypeScript 为 JavaScript(输出到 dist/)
251
+ npm run build
252
+
253
+ # 开发模式:直接运行 TypeScript 源码(ts-node)
254
+ npm run dev -- [参数]
255
+
256
+ # 运行已编译的 CLI(需要先 build)
257
+ npm start -- [参数]
258
+
259
+ # 清理编译产物(删除 dist/ 目录)
260
+ npm run clean
261
+
262
+ # 清理后重新编译
263
+ npm run rebuild
264
+ ```
265
+
266
+ ---
267
+
268
+ ## 🔧 扩展新命令(开发者指南)
269
+
270
+ ### 步骤
271
+
272
+ 1. **新建命令文件**:在 `src/commands/` 下创建 `xxx.command.ts`
273
+ 2. **实现 ICommand 接口**:编写 `name`、`description` 和 `execute()` 方法
274
+ 3. **注册命令**:在 `src/commands/index.ts` 的 `commands` 数组中添加实例
275
+
276
+ ### 示例
277
+
278
+ ```typescript
279
+ // src/commands/example.command.ts
280
+ import { ICommand } from "../types";
281
+ import { logger, BrowserUtils } from "../utils";
282
+
283
+ export class ExampleCommand implements ICommand {
284
+ public readonly name = "example";
285
+ public readonly description = "示例命令 - 打开示例网站";
286
+
287
+ public async execute(args: string[]): Promise<void> {
288
+ logger.info("执行示例命令,参数:", args);
289
+ await BrowserUtils.openUrl("https://example.com/");
290
+ }
291
+ }
292
+ ```
293
+
294
+ ```typescript
295
+ // src/commands/index.ts
296
+ import { ExampleCommand } from "./example.command"; // 新增导入
297
+
298
+ export const commands: ICommand[] = [
299
+ new HomepageCommand(),
300
+ new NexusSwaggerCommand(),
301
+ new ExampleCommand(), // 新增注册
302
+ ];
303
+ ```
304
+
305
+ 完成后执行 `npm run build` 即可使用 `sino-bc-cli /example`。
306
+
307
+ ---
308
+
309
+ ## 📄 License
310
+
311
+ MIT License