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.
- package/README.md +311 -0
- package/dist/SKILL.md +466 -0
- package/dist/commands/bc-mcp.command.d.ts +53 -0
- package/dist/commands/bc-mcp.command.js +208 -0
- package/dist/commands/bc-mcp.command.js.map +1 -0
- package/dist/commands/homepage.command.d.ts +19 -0
- package/dist/commands/homepage.command.js +96 -0
- package/dist/commands/homepage.command.js.map +1 -0
- package/dist/commands/index.d.ts +10 -0
- package/dist/commands/index.js +23 -0
- package/dist/commands/index.js.map +1 -0
- package/dist/commands/nexus-swagger.command.d.ts +19 -0
- package/dist/commands/nexus-swagger.command.js +95 -0
- package/dist/commands/nexus-swagger.command.js.map +1 -0
- package/dist/constants/api-doc.d.ts +6 -0
- package/dist/constants/api-doc.js +80 -0
- package/dist/constants/api-doc.js.map +1 -0
- package/dist/constants/gateway.d.ts +31 -0
- package/dist/constants/gateway.js +109 -0
- package/dist/constants/gateway.js.map +1 -0
- package/dist/constants/index.d.ts +38 -0
- package/dist/constants/index.js +52 -0
- package/dist/constants/index.js.map +1 -0
- package/dist/core/cli-app.d.ts +51 -0
- package/dist/core/cli-app.js +281 -0
- package/dist/core/cli-app.js.map +1 -0
- package/dist/core/command-registry.d.ts +71 -0
- package/dist/core/command-registry.js +195 -0
- package/dist/core/command-registry.js.map +1 -0
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.js +9 -0
- package/dist/core/index.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +34 -0
- package/dist/index.js.map +1 -0
- package/dist/types/index.d.ts +120 -0
- package/dist/types/index.js +46 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/browser.d.ts +36 -0
- package/dist/utils/browser.js +143 -0
- package/dist/utils/browser.js.map +1 -0
- package/dist/utils/common.d.ts +97 -0
- package/dist/utils/common.js +198 -0
- package/dist/utils/common.js.map +1 -0
- package/dist/utils/crypto.d.ts +53 -0
- package/dist/utils/crypto.js +153 -0
- package/dist/utils/crypto.js.map +1 -0
- package/dist/utils/http.d.ts +58 -0
- package/dist/utils/http.js +187 -0
- package/dist/utils/http.js.map +1 -0
- package/dist/utils/index.d.ts +6 -0
- package/dist/utils/index.js +16 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/logger.d.ts +56 -0
- package/dist/utils/logger.js +161 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/prompt.d.ts +18 -0
- package/dist/utils/prompt.js +77 -0
- package/dist/utils/prompt.js.map +1 -0
- package/package.json +63 -0
package/dist/SKILL.md
ADDED
|
@@ -0,0 +1,466 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: sino-bc-cli
|
|
3
|
+
description: >
|
|
4
|
+
BeyondClick CLI 项目说明、命令用法、扩展新命令与 npm 发布/回滚步骤。
|
|
5
|
+
Use when 开发或使用 sino-bc-cli、执行 /homepage /nexus-swagger /bc-mcp、扩展命令、
|
|
6
|
+
npm publish、release:patch/minor/major、切 registry、排查 ENEEDAUTH/E403/EPUBLISHCONFLICT,
|
|
7
|
+
或发布到私有 Nexus / 企业私服。
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# sino-bc-cli
|
|
11
|
+
|
|
12
|
+
BeyondClick 命令行工具集合 — 提供快捷访问 BeyondClick 平台的命令行接口。
|
|
13
|
+
|
|
14
|
+
适用:`sino-bc-cli`(Node.js v24 + TypeScript v5 CLI)
|
|
15
|
+
|
|
16
|
+
## 目录
|
|
17
|
+
|
|
18
|
+
- [技术栈](#技术栈)
|
|
19
|
+
- [项目结构](#项目结构)
|
|
20
|
+
- [环境与安装](#环境与安装)
|
|
21
|
+
- [命令说明](#命令说明)
|
|
22
|
+
- [扩展新命令](#扩展新命令)
|
|
23
|
+
- [npm 发布](#npm-发布)
|
|
24
|
+
- [发布前检查清单](#一发布前检查清单必须全部通过)
|
|
25
|
+
- [前置条件](#二前置条件准备)
|
|
26
|
+
- [发布流程](#三发布流程按顺序执行)
|
|
27
|
+
- [后续版本迭代](#四后续版本迭代一行命令)
|
|
28
|
+
- [私有 Nexus / 企业私服](#五发布到私有-nexus--企业私服可选)
|
|
29
|
+
- [常见报错](#六常见报错速查表)
|
|
30
|
+
- [回滚 / 撤销](#七回滚--撤销发布)
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## 技术栈
|
|
35
|
+
|
|
36
|
+
| 技术/依赖 | 版本要求 | 用途说明 |
|
|
37
|
+
| :------------- | :----------- | :------------------------------------------------------ |
|
|
38
|
+
| **Node.js** | `>= v24.0.0` | CLI 运行时环境,要求使用 v24 及以上版本 |
|
|
39
|
+
| **TypeScript** | `^v5.5.0` | 开发语言,提供静态类型检查和更好的可维护性 |
|
|
40
|
+
| **lodash** | `^4.17.21` | 工具函数库,提供对象/数组/字符串处理等高效方法 |
|
|
41
|
+
| **dayjs** | `^1.11.11` | 轻量级日期处理库,替代 Moment.js 处理日期时间格式化 |
|
|
42
|
+
| **axios** | `^1.7.0` | HTTP 客户端库,用于网络请求、连通性检测等 |
|
|
43
|
+
| **crypto-js** | `^4.2.0` | 加密算法库,提供 MD5、SHA-256、AES、Base64 等加解密能力 |
|
|
44
|
+
| **commander** | `^12.1.0` | 命令行参数解析框架(预留,当前采用自研注册器模式) |
|
|
45
|
+
| **chalk** | `^4.1.2` | 终端彩色输出库,用于美化日志和帮助信息 |
|
|
46
|
+
| **open** | `^8.4.2` | 跨平台文件/URL 打开工具(兼容备用方案) |
|
|
47
|
+
|
|
48
|
+
### 开发依赖
|
|
49
|
+
|
|
50
|
+
| 依赖 | 版本 | 用途 |
|
|
51
|
+
| :----------------- | :-------- | :-------------------------------- |
|
|
52
|
+
| `@types/node` | `^22.0.0` | Node.js 类型声明 |
|
|
53
|
+
| `@types/lodash` | `^4.17.5` | lodash 类型声明 |
|
|
54
|
+
| `@types/crypto-js` | `^4.2.2` | crypto-js 类型声明 |
|
|
55
|
+
| `ts-node` | `^10.9.2` | 开发阶段直接运行 TypeScript 代码 |
|
|
56
|
+
| `rimraf` | `^5.0.7` | 跨平台目录清理工具,替代 `rm -rf` |
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## 项目结构
|
|
61
|
+
|
|
62
|
+
项目采用 **模块化、低耦合、高内聚** 的分层设计。
|
|
63
|
+
|
|
64
|
+
```
|
|
65
|
+
sino-bc-cli/
|
|
66
|
+
├── src/
|
|
67
|
+
│ ├── index.ts # CLI 入口,bin 关联点
|
|
68
|
+
│ ├── core/ # 核心模块(参数解析、帮助、命令分发、注册器)
|
|
69
|
+
│ ├── commands/ # 命令实现(每命令一个文件)
|
|
70
|
+
│ ├── utils/ # 可复用工具(logger / browser / crypto / http / common)
|
|
71
|
+
│ ├── types/ # 全局接口、枚举(ICommand、LogLevel)
|
|
72
|
+
│ └── constants/ # CLI 配置、URL、命令名称、默认值
|
|
73
|
+
├── dist/ # 编译产物(js + d.ts + SourceMap)
|
|
74
|
+
├── package.json
|
|
75
|
+
├── tsconfig.json
|
|
76
|
+
└── .gitignore
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### 架构原则
|
|
80
|
+
|
|
81
|
+
1. **分层清晰**:`core → commands → utils → types/constants`,上层依赖下层,单向依赖无循环
|
|
82
|
+
2. **低耦合**:命令互相独立,通过注册器统一管理;新增命令只需在 `commands/` 下新建文件并加入 `commands/index.ts` 数组
|
|
83
|
+
3. **高内聚**:每个工具类只负责单一职责
|
|
84
|
+
4. **可扩展**:实现 `ICommand` → 放入 `commands/index.ts` 即可自动注册;注册器支持运行时动态注册/注销
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
## 环境与安装
|
|
89
|
+
|
|
90
|
+
### 环境要求
|
|
91
|
+
|
|
92
|
+
确保已安装 **Node.js v24** 或更高版本(`npm` 建议 v10+):
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
node -v # 要求 v24.x.x 或更高
|
|
96
|
+
npm -v
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
版本不符时,用 [nvm](https://github.com/nvm-sh/nvm) 或 [nvm-windows](https://github.com/coreybutler/nvm-windows) 管理。
|
|
100
|
+
|
|
101
|
+
### 安装与编译
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
npm install
|
|
105
|
+
npm run build # 生成 dist/
|
|
106
|
+
npm run rebuild # 清理后重新编译
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
`dist/` 包含:`*.js`、`*.d.ts`、`*.js.map`。
|
|
110
|
+
|
|
111
|
+
### 开发模式(免编译)
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
npm run dev -- --help
|
|
115
|
+
npm run dev -- /homepage
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### 全局安装(推荐)
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
# 方式一:源码目录全局链接(须先 build;Windows 下 npm link 需要管理员权限)
|
|
122
|
+
npm run build
|
|
123
|
+
npm link
|
|
124
|
+
|
|
125
|
+
# 方式二:从 npm 安装
|
|
126
|
+
npm i sino-bc-cli -g
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
sino-bc-cli --help
|
|
131
|
+
sino-bc-cli /homepage
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
卸载:`npm unlink` 或 `npm uninstall -g sino-bc-cli`
|
|
135
|
+
|
|
136
|
+
### NPM 脚本
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
npm run build # 编译到 dist/
|
|
140
|
+
npm run dev -- [参数] # ts-node 直接跑源码
|
|
141
|
+
npm start -- [参数] # 运行已编译 CLI(需先 build)
|
|
142
|
+
npm run clean # 删除 dist/
|
|
143
|
+
npm run rebuild # clean + tsc
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
---
|
|
147
|
+
|
|
148
|
+
## 命令说明
|
|
149
|
+
|
|
150
|
+
### 可用命令
|
|
151
|
+
|
|
152
|
+
| 命令 | 说明 |
|
|
153
|
+
| :--------------- | :----------------------------------------------------------------------------------------------------------------- |
|
|
154
|
+
| `/homepage` | 使用默认浏览器打开 BeyondClick 业务平台主页 (`https://business.beyondclick.com/`) |
|
|
155
|
+
| `/nexus-swagger` | 使用默认浏览器打开 BeyondClick Nexus Swagger 文档页 (`https://o-test-sino-bc-nexus.meetsocial.com/doc.html#/home`) |
|
|
156
|
+
| `/bc-mcp` | 交互选择并调用 iCenter MCP 接口;`ENV` 默认 `prod`,`API_KEY` 默认使用网关常量 |
|
|
157
|
+
|
|
158
|
+
### 全局选项
|
|
159
|
+
|
|
160
|
+
| 选项 | 短选项 | 说明 |
|
|
161
|
+
| :---------- | :----- | :---------------------------------------- |
|
|
162
|
+
| `--version` | `-v` | 显示版本信息 |
|
|
163
|
+
| `--help` | `-h` | 显示帮助信息 |
|
|
164
|
+
| `--debug` | `-d` | 启用 Debug 日志模式,输出更详细的运行信息 |
|
|
165
|
+
|
|
166
|
+
### 使用示例
|
|
167
|
+
|
|
168
|
+
```bash
|
|
169
|
+
sino-bc-cli --version
|
|
170
|
+
sino-bc-cli --help
|
|
171
|
+
sino-bc-cli /homepage
|
|
172
|
+
sino-bc-cli /nexus-swagger
|
|
173
|
+
sino-bc-cli /bc-mcp
|
|
174
|
+
sino-bc-cli /bc-mcp test
|
|
175
|
+
sino-bc-cli --debug /homepage
|
|
176
|
+
sino-bc-cli -d /nexus-swagger
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
- `/homepage`:打开 `https://business.beyondclick.com/`
|
|
180
|
+
- `/nexus-swagger`:打开 Nexus Swagger 文档页
|
|
181
|
+
- Debug 会输出参数解析、命令注册、URL 打开过程
|
|
182
|
+
|
|
183
|
+
### 跨平台兼容性
|
|
184
|
+
|
|
185
|
+
| 操作系统 | 测试状态 | 打开浏览器方式 |
|
|
186
|
+
| :--------------------------- | :------- | :----------------------------------------------------------------- |
|
|
187
|
+
| **Windows** (10/11) | ✅ 支持 | 使用 `cmd /c start "" "url"`,已处理 URL 中 `&`/`^` 等特殊字符转义 |
|
|
188
|
+
| **macOS** | ✅ 支持 | 使用系统 `open` 命令 |
|
|
189
|
+
| **Linux** (Ubuntu/CentOS 等) | ✅ 支持 | 使用 `xdg-open` 命令 |
|
|
190
|
+
|
|
191
|
+
所有平台均通过 Node.js 内置 `child_process.exec` 调用,**不依赖任何 native 模块**。
|
|
192
|
+
|
|
193
|
+
---
|
|
194
|
+
|
|
195
|
+
## 扩展新命令
|
|
196
|
+
|
|
197
|
+
1. 在 `src/commands/` 下创建 `xxx.command.ts`
|
|
198
|
+
2. 实现 `ICommand`:`name`、`description`、`execute()`
|
|
199
|
+
3. 在 `src/commands/index.ts` 的 `commands` 数组中添加实例
|
|
200
|
+
|
|
201
|
+
```typescript
|
|
202
|
+
// src/commands/example.command.ts
|
|
203
|
+
import { ICommand } from "../types";
|
|
204
|
+
import { logger, BrowserUtils } from "../utils";
|
|
205
|
+
|
|
206
|
+
export class ExampleCommand implements ICommand {
|
|
207
|
+
public readonly name = "example";
|
|
208
|
+
public readonly description = "示例命令 - 打开示例网站";
|
|
209
|
+
|
|
210
|
+
public async execute(args: string[]): Promise<void> {
|
|
211
|
+
logger.info("执行示例命令,参数:", args);
|
|
212
|
+
await BrowserUtils.openUrl("https://example.com/");
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
```typescript
|
|
218
|
+
// src/commands/index.ts
|
|
219
|
+
import { ExampleCommand } from "./example.command";
|
|
220
|
+
|
|
221
|
+
export const commands: ICommand[] = [
|
|
222
|
+
new HomepageCommand(),
|
|
223
|
+
new NexusSwaggerCommand(),
|
|
224
|
+
new ExampleCommand(),
|
|
225
|
+
];
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
完成后 `npm run build`,即可使用 `sino-bc-cli /example`。
|
|
229
|
+
|
|
230
|
+
---
|
|
231
|
+
|
|
232
|
+
## npm 发布
|
|
233
|
+
|
|
234
|
+
### 一、发布前检查清单(必须全部通过)
|
|
235
|
+
|
|
236
|
+
首次发版请逐一核对(已在 `package.json` 和构建配置中落实):
|
|
237
|
+
|
|
238
|
+
| # | 检查项 | 如何验证 | 期望结果 |
|
|
239
|
+
| :--- | :--- | :--- | :--- |
|
|
240
|
+
| 1 | 包名 `sino-bc-cli` 未被占用 | `npm view sino-bc-cli version` | 返回 `E404`(首次发布前)或已有版本号 |
|
|
241
|
+
| 2 | `dist/index.js` 首行带 shebang | 打开 `dist/index.js` 看首行 | `#!/usr/bin/env node`(CLI 全局安装必须要有) |
|
|
242
|
+
| 3 | `package.json` 含 `files` 白名单 | 查看 `package.json` 的 `files` 数组 | 只包含 `dist/`、`README.md` 等,**不要包含 `src/`、`node_modules/`、`tsconfig.json`** |
|
|
243
|
+
| 4 | `package.json` 含 `bin` 映射 | `package.json` 的 `bin` 字段 | `"sino-bc-cli": "./dist/index.js"` |
|
|
244
|
+
| 5 | `prepublishOnly` 钩子存在 | `package.json` scripts | `"prepublishOnly": "npm run rebuild"`(防止发布旧 dist) |
|
|
245
|
+
| 6 | `publishConfig.access` = public | `package.json` | `"access": "public"` |
|
|
246
|
+
| 7 | TypeScript 编译无错误 | `npm run rebuild` | 退出码 `0`,无 TS error |
|
|
247
|
+
| 8 | CLI 冒烟测试通过 | `node dist/index.js --version` / `--help` | 正常输出版本号 / 帮助信息 |
|
|
248
|
+
| 9 | npm 登录态 | `npm whoami` | 返回 npm 用户名(ENEEDAUTH=未登录) |
|
|
249
|
+
| 10 | 本地无未提交脏改动(建议) | `git status` | `nothing to commit, working tree clean` |
|
|
250
|
+
|
|
251
|
+
### 二、前置条件准备
|
|
252
|
+
|
|
253
|
+
1. **npm 官方账号**:<https://www.npmjs.com/signup>,准备用户名 / 密码 / 邮箱
|
|
254
|
+
2. **邮箱必须已验证**:未验证发布会报 `403 Forbidden`。官网头像 → Profile,看不到 "Verify your email" 即为通过
|
|
255
|
+
3. **2FA(强烈建议)**:官网 Access Tokens / 2FA → Authentication Code,用 Authenticator 绑定。发布时输入 6 位 OTP
|
|
256
|
+
4. **Node.js**:`node -v` 建议 v24+;`npm -v` 建议 v10+
|
|
257
|
+
|
|
258
|
+
### 三、发布流程(按顺序执行)
|
|
259
|
+
|
|
260
|
+
#### Step 0:切到项目目录并拉取最新代码
|
|
261
|
+
|
|
262
|
+
```powershell
|
|
263
|
+
cd d:\Project\demo\sino-bc-cli
|
|
264
|
+
|
|
265
|
+
git checkout main
|
|
266
|
+
git pull origin main
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
#### Step 1:确认 registry 指向 npm 官方(最容易踩坑)
|
|
270
|
+
|
|
271
|
+
很多开发者默认把 registry 设为淘宝镜像或公司 Nexus。发布时不切回官方,要么失败,要么发到私服而不自知。
|
|
272
|
+
|
|
273
|
+
```powershell
|
|
274
|
+
npm config get registry
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
| 输出 | 状态 | 下一步 |
|
|
278
|
+
| :--- | :--- | :--- |
|
|
279
|
+
| `https://registry.npmjs.org/` | ✅ 正确 | 跳到 Step 2 |
|
|
280
|
+
| `https://registry.npmmirror.com/` | ⚠️ 淘宝镜像 | 执行下方切换 |
|
|
281
|
+
| `http://nexus.xxx.com/...` | ⚠️ 公司私服 | 执行下方切换(发完再切回) |
|
|
282
|
+
| 其他 | ⚠️ 自定义源 | 执行下方切换 |
|
|
283
|
+
|
|
284
|
+
```powershell
|
|
285
|
+
npm config set registry "https://registry.npmjs.org/"
|
|
286
|
+
npm config get registry
|
|
287
|
+
# 输出: https://registry.npmjs.org/
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
既要发官方 npm 又要保留镜像加速:平时保持淘宝镜像,发布时用 `npm publish --registry=https://registry.npmjs.org/` **单次指定**,不改全局配置。
|
|
291
|
+
|
|
292
|
+
#### Step 2:登录 npm 账号
|
|
293
|
+
|
|
294
|
+
Windows 下必须加 `--auth-type=legacy`。不加时新版 npm (v9+) 会走浏览器扫码/回环回调,在 PowerShell/企业终端下经常卡死。
|
|
295
|
+
|
|
296
|
+
```powershell
|
|
297
|
+
npm login --auth-type=legacy --registry=https://registry.npmjs.org/
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
按提示手动输入(脚本无法自动化):
|
|
301
|
+
|
|
302
|
+
```
|
|
303
|
+
Username: 你的 npm 用户名(区分大小写)
|
|
304
|
+
Password: 你的 npm 密码 (输入时不显示任何字符,正常)
|
|
305
|
+
Email: (this IS public) 你注册的邮箱
|
|
306
|
+
Enter one-time password: 123456 (只有开了 2FA 才会出现,没开跳过)
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
```powershell
|
|
310
|
+
npm whoami
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
仍报 `ENEEDAUTH` → registry 对不上,重做 Step 1 + Step 2。
|
|
314
|
+
|
|
315
|
+
#### Step 3:确认 / 升级版本号
|
|
316
|
+
|
|
317
|
+
**首次发布**:`package.json` 中 `1.0.0` 可直接用。
|
|
318
|
+
|
|
319
|
+
**后续迭代**:同一版本号一旦发布就不能覆盖(立刻 unpublish 也不行),必须严格递增。
|
|
320
|
+
|
|
321
|
+
| 升级类型 | 含义 | 示例 | 命令 |
|
|
322
|
+
| :--- | :--- | :--- | :--- |
|
|
323
|
+
| **patch** 补丁 | 修 bug、微调文档 | `1.0.0 → 1.0.1` | `npm version patch` |
|
|
324
|
+
| **minor** 次版本 | 新增功能,向下兼容 | `1.0.0 → 1.1.0` | `npm version minor` |
|
|
325
|
+
| **major** 主版本 | 破坏性变更 / 架构升级 | `1.0.0 → 2.0.0` | `npm version major` |
|
|
326
|
+
|
|
327
|
+
日常发版优先用下方「一行命令」脚本。
|
|
328
|
+
|
|
329
|
+
#### Step 4:Dry-Run 打包预览(强烈建议)
|
|
330
|
+
|
|
331
|
+
```powershell
|
|
332
|
+
npm pack --dry-run
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
正常末尾类似:`sino-bc-cli@1.0.0`、约 47 个文件、包大小约 30.7 kB。
|
|
336
|
+
|
|
337
|
+
不合格则暂停:
|
|
338
|
+
|
|
339
|
+
- 出现 `src/`、`tsconfig.json`、`.gitignore`、`node_modules/` → 漏配 `files` 白名单
|
|
340
|
+
- 包大小 > 500KB → 很可能打包了不该打包的内容
|
|
341
|
+
- `dist/` 文件数量 < 10 → 编译不完整,执行 `npm run rebuild`
|
|
342
|
+
|
|
343
|
+
#### Step 5:执行发布
|
|
344
|
+
|
|
345
|
+
```powershell
|
|
346
|
+
npm publish --access public
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
开了 2FA 会再要 6 位 OTP。正常 10~30 秒:
|
|
350
|
+
|
|
351
|
+
1. 触发 `prepublishOnly` → `npm run rebuild`
|
|
352
|
+
2. checksum → 上传 tgz
|
|
353
|
+
3. 成功时出现 `+ sino-bc-cli@x.y.z`
|
|
354
|
+
|
|
355
|
+
#### Step 6:发布后验证(3 步不可省)
|
|
356
|
+
|
|
357
|
+
**① 官网版本**
|
|
358
|
+
|
|
359
|
+
```powershell
|
|
360
|
+
npm view sino-bc-cli version
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
仍 E404:等 1 分钟;确认 registry 是官方源;或打开 <https://www.npmjs.com/package/sino-bc-cli>
|
|
364
|
+
|
|
365
|
+
**② npx 远程试用**
|
|
366
|
+
|
|
367
|
+
```powershell
|
|
368
|
+
npx sino-bc-cli@latest --version
|
|
369
|
+
npx sino-bc-cli@latest --help
|
|
370
|
+
# npx sino-bc-cli@latest /homepage
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
**③ 浏览器打开包页**,确认 README 渲染、Version / License / Keywords、Dependencies(lodash、dayjs、axios、crypto-js、chalk、commander、open)
|
|
374
|
+
|
|
375
|
+
发布完成后把 registry 切回平时镜像:
|
|
376
|
+
|
|
377
|
+
```powershell
|
|
378
|
+
npm config set registry https://registry.npmmirror.com
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
### 四、后续版本迭代(一行命令)
|
|
382
|
+
|
|
383
|
+
`package.json` 已内置「升级版本号 + 自动编译 + 发布」脚本:
|
|
384
|
+
|
|
385
|
+
```powershell
|
|
386
|
+
npm run release:patch # 1.0.0 → 1.0.1
|
|
387
|
+
npm run release:minor # 1.0.0 → 1.1.0
|
|
388
|
+
npm run release:major # 1.0.0 → 2.0.0
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
等价于:`npm version <type>`(升版本 + Git Tag)→ `prepublishOnly` / `rebuild` → `npm publish --access public`
|
|
392
|
+
|
|
393
|
+
发布完执行 `git push origin main --tags`。
|
|
394
|
+
|
|
395
|
+
### 五、发布到私有 Nexus / 企业私服(可选)
|
|
396
|
+
|
|
397
|
+
#### 5.1 发布侧
|
|
398
|
+
|
|
399
|
+
确认私服是 **npm-hosted**(不要用 raw-release / maven 仓库):
|
|
400
|
+
|
|
401
|
+
```powershell
|
|
402
|
+
npm login --auth-type=legacy --registry=https://nexus.your-company.com/repository/npm-hosted/
|
|
403
|
+
npm publish --access restricted --registry=https://nexus.your-company.com/repository/npm-hosted/
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
`--registry` 只对这一次生效,避免污染全局。
|
|
407
|
+
|
|
408
|
+
#### 5.2 安装侧
|
|
409
|
+
|
|
410
|
+
**不要只设 `--registry=私服地址`**,否则公共依赖也会去私服解析,未代理时 `lodash/dayjs/axios` 会 404。
|
|
411
|
+
|
|
412
|
+
**推荐(Nexus 侧)**:运维建 **npm-group**,把 `npm-hosted` + `npm-proxy(代理 https://registry.npmjs.org/)` 加入 group。客户端 registry 只指向 npm-group;发布用 npm-hosted,安装用 npm-group。
|
|
413
|
+
|
|
414
|
+
**应急(未做 group)**:平时 registry 保持官方 / 淘宝镜像;私有包用 `@company/sino-bc-cli` scope,客户端 `.npmrc`:
|
|
415
|
+
|
|
416
|
+
```ini
|
|
417
|
+
@company:registry=https://nexus.your-company.com/repository/npm-hosted/
|
|
418
|
+
```
|
|
419
|
+
|
|
420
|
+
这样 scoped 包走私服,公共依赖走官方。
|
|
421
|
+
|
|
422
|
+
### 六、常见报错速查表
|
|
423
|
+
|
|
424
|
+
| 错误码 / 关键字 | 原因 | 解决方案 |
|
|
425
|
+
| :--- | :--- | :--- |
|
|
426
|
+
| **`ENEEDAUTH`** | 未登录或登录态过期 | `npm login --auth-type=legacy`;确认 registry 一致 |
|
|
427
|
+
| **`E403 Forbidden`** | ① 邮箱未验证 ② 无该包权限 ③ OTP 错 ④ 包名被占用 | ① 官网验证邮箱 ② owner 加 Maintainer ③ 等 30 秒重输 OTP ④ 改名或发 `@你的用户名/sino-bc-cli` |
|
|
428
|
+
| **`EPUBLISHCONFLICT`** / `cannot publish over previously published version` | 版本号已发过 | `npm version patch` 再发(npm 不允许覆盖同版本) |
|
|
429
|
+
| **`E404`(发布时)** | registry 指向私服且没权限 | 切到 `https://registry.npmjs.org/` |
|
|
430
|
+
| **`E404`(安装时,包已发成功)** | 安装方 registry 不在官方 / 私服没同步 | `npm i sino-bc-cli -g --registry=https://registry.npmjs.org/` |
|
|
431
|
+
| **`E500` / `ETIMEDOUT` / `ECONNRESET`** | 网络抖动、被墙、内网限流 | 重试 2~3 次;开代理;`npm config set proxy http://x.x.x.x:port` |
|
|
432
|
+
| **登录时浏览器弹出但终端卡住** | npm v9+ web auth 被防火墙/终端拦 | `npm login --auth-type=legacy` |
|
|
433
|
+
| **`You cannot publish over previously published version`** | unpublish 后同一天重发同版本 | unpublish 后 **24 小时内不能重发同版本**,升版本或等 24h |
|
|
434
|
+
| **Windows 下 `cmd /c start` 打开浏览器失败** | 本地 `open` / `child_process` 权限 | CLI 已用 `child_process.exec(cmd /c start)` 兼容;仍失败则手动访问命令 URL |
|
|
435
|
+
|
|
436
|
+
### 七、回滚 / 撤销发布
|
|
437
|
+
|
|
438
|
+
谨慎:同一版本 unpublish 后 24h 禁发;整包 unpublish 72h 后还不能重发同名。能靠升版本号修复就不要 unpublish。
|
|
439
|
+
|
|
440
|
+
```powershell
|
|
441
|
+
# 撤销某一个版本
|
|
442
|
+
npm unpublish sino-bc-cli@1.0.0
|
|
443
|
+
|
|
444
|
+
# 撤销整个包
|
|
445
|
+
npm unpublish sino-bc-cli --force
|
|
446
|
+
|
|
447
|
+
# 更温和:废弃(推荐)
|
|
448
|
+
npm deprecate sino-bc-cli@1.0.0 "严重 Bug,请升级到 1.0.1"
|
|
449
|
+
npm deprecate sino-bc-cli@* "此包已废弃,请使用 @newscope/sino-bc-cli"
|
|
450
|
+
```
|
|
451
|
+
|
|
452
|
+
### 附录:关键配置位置
|
|
453
|
+
|
|
454
|
+
| 配置项 | 位置 |
|
|
455
|
+
| :--- | :--- |
|
|
456
|
+
| 项目版本号 / 依赖 / scripts | `package.json` |
|
|
457
|
+
| 发版白名单 files / publishConfig | `package.json` 的 `files` + `publishConfig` |
|
|
458
|
+
| TypeScript 编译配置 | `tsconfig.json` |
|
|
459
|
+
| CLI 入口(带 shebang) | `src/index.ts` → 编译后 `dist/index.js` |
|
|
460
|
+
| 命令 URL 配置 | `src/constants/index.ts` 的 `PLATFORM_URLS` |
|
|
461
|
+
|
|
462
|
+
---
|
|
463
|
+
|
|
464
|
+
## License
|
|
465
|
+
|
|
466
|
+
MIT License
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { ICommand } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* 调用 iCenter MCP 接口命令
|
|
4
|
+
* 命令名称: /bc-mcp
|
|
5
|
+
* 功能: 交互选择 api-doc 中的接口,使用文档默认请求体发起调用
|
|
6
|
+
*/
|
|
7
|
+
export declare class BcMcpCommand implements ICommand {
|
|
8
|
+
/** 命令名称 */
|
|
9
|
+
readonly name: string;
|
|
10
|
+
/** 命令描述 */
|
|
11
|
+
readonly description: string;
|
|
12
|
+
/** 命令使用示例 */
|
|
13
|
+
readonly usage: string;
|
|
14
|
+
/**
|
|
15
|
+
* 命令执行函数
|
|
16
|
+
* @param args 位置参数:[ENV] [API_KEY]
|
|
17
|
+
* @param options 解析后的选项,支持 --env / --api-key
|
|
18
|
+
*/
|
|
19
|
+
execute(args: string[], options?: Record<string, unknown>): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* 解析环境参数,优先级:--env > 位置参数中的合法 ENV > 默认 prod
|
|
22
|
+
*/
|
|
23
|
+
private resolveEnv;
|
|
24
|
+
/**
|
|
25
|
+
* 解析 API Key,优先级:--api-key > 非 ENV 的位置参数 > 默认值
|
|
26
|
+
*/
|
|
27
|
+
private resolveApiKey;
|
|
28
|
+
/**
|
|
29
|
+
* 从 options 中按候选 key 取第一个有效值
|
|
30
|
+
*/
|
|
31
|
+
private pickOption;
|
|
32
|
+
/**
|
|
33
|
+
* 打印接口清单并让用户选择
|
|
34
|
+
*/
|
|
35
|
+
private selectApi;
|
|
36
|
+
/**
|
|
37
|
+
* 打印即将发起的请求概要
|
|
38
|
+
*/
|
|
39
|
+
private printRequestPreview;
|
|
40
|
+
/**
|
|
41
|
+
* 按接口方法发起请求并打印响应
|
|
42
|
+
*/
|
|
43
|
+
private callApi;
|
|
44
|
+
/**
|
|
45
|
+
* 将响应格式化为可读 JSON 文本
|
|
46
|
+
* version 接口可能返回 text/plain,需兜底解析
|
|
47
|
+
*/
|
|
48
|
+
private formatResponse;
|
|
49
|
+
/**
|
|
50
|
+
* 统一处理 HTTP 失败:优先打印服务端响应体
|
|
51
|
+
*/
|
|
52
|
+
private handleRequestError;
|
|
53
|
+
}
|