feat: 新增license

This commit is contained in:
小蟑螂
2026-07-06 19:34:53 +08:00
parent 8a6cb23c07
commit ac890dcc5c
110 changed files with 10678 additions and 1368 deletions
+393
View File
@@ -0,0 +1,393 @@
# ecom-license CLI
Ecom-DMB License 运营管理命令行工具,用于登录 License Server、管理客户与签发/吊销许可证。
**前置条件**:License Server 已启动(默认 `http://localhost:3100`)。首次登录默认账号 `admin` / `admin123`。
---
## 安装与运行
```bash
cd ecom-license/cli
pnpm install
pnpm build # 可选,生产模式需要
```
| 方式 | 命令 | 说明 |
|------|------|------|
| 开发模式 | `pnpm dev <子命令>` | 使用 `tsx` 直接运行源码 |
| 构建产物 | `pnpm start <子命令>` | 运行 `dist/index.js` |
| 全局安装 | `pnpm link --global` 后 `ecom-license` | 需先 `pnpm build` |
| 快捷脚本 | `pnpm login` / `pnpm whoami` / `pnpm stats` | 等价于 `pnpm dev <命令>` |
无子命令时显示常用命令引导;完整帮助:
```bash
pnpm dev -- --help
pnpm dev customer --help
pnpm dev license --help
```
---
## 配置
登录成功后写入本地配置文件:
| 项 | 值 |
|----|-----|
| 默认路径 | `~/.config/ecom-license/config.json` |
| 自定义路径 | 环境变量 `ECOM_LICENSE_CONFIG` |
```json
{
"apiUrl": "http://localhost:3100",
"token": "eyJ...",
"username": "admin",
"expiresAt": "2026-06-01T00:00:00.000Z"
}
```
`logout` 会清除 token,保留 `apiUrl`。
---
## 环境变量
| 变量 | 作用 |
|------|------|
| `ECOM_LICENSE_API_URL` | API 根地址(优先级低于 `--url`) |
| `ECOM_LICENSE_TOKEN` | Bearer Token(优先级低于 `--token`) |
| `ECOM_LICENSE_USERNAME` | 非交互 `login` 用户名 |
| `ECOM_LICENSE_PASSWORD` | 非交互 `login` 密码 |
| `ECOM_LICENSE_CONFIG` | 配置文件路径 |
| `CI` | 存在时禁用交互向导 |
| `NO_COLOR` / `FORCE_COLOR` | 控制终端颜色 |
---
## 全局选项
所有命令均支持(写在子命令前或后均可,由 Commander 解析):
| 选项 | 说明 |
|------|------|
| `--url <base>` | API 根地址,如 `http://localhost:3100` |
| `--token <jwt>` | 临时指定 Token,不写配置文件 |
| `--json` | 纯 JSON 输出,适合脚本 |
| `--quiet` | 仅输出关键值(如 ID、licenseKey、文件路径) |
| `--yes` | 跳过确认(删除客户、吊销许可证) |
| `--verbose` | 显示详细错误堆栈 |
| `-V, --version` | 版本号 |
| `-h, --help` | 帮助 |
### 输出模式
| 模式 | 条件 | 行为 |
|------|------|------|
| 交互(默认) | TTY 且非 `CI`,无 `--json`/`--quiet` | 缺参时向导提问;列表用表格;请求有 spinner |
| `--json` | 显式指定 | 结构化 JSON,无颜色 |
| `--quiet` | 显式指定 | 单行关键值,便于管道 |
| 管道/重定向 | stdout 非 TTY | 同 `--json` 语义,不展示 banner/boxen |
---
## 命令总览
```
ecom-license [--url] [--token] [--json] [--quiet] [--yes] [--verbose]
login [--username] [--password]
logout
whoami
stats
customer list [--page] [--size]
customer create [--code] [--name] [--contact-name] [--contact-phone] [--contact-email]
customer show <id>
customer delete <id>
license list [--page] [--size] [--customer-id] [--status]
license show <id>
license generate [--customer-id] [--company] [--fingerprint] [--edition] [--expires] [--features]
license revoke <id>
license download <id> [-o|--output <file>]
```
---
## 认证与会话
### `login`
登录 License 平台,保存 Token 到配置文件。
| 选项 | 说明 |
|------|------|
| `--username <name>` | 用户名(非交互必填其一) |
| `--password <pwd>` | 密码 |
**交互模式**:依次询问 API 地址(默认当前配置或 `http://localhost:3100`)、用户名、密码。
```bash
pnpm dev login
pnpm dev login --username admin --password admin123
ECOM_LICENSE_USERNAME=admin ECOM_LICENSE_PASSWORD=admin123 pnpm dev login
pnpm dev login --url http://192.168.1.10:3100
```
### `logout`
清除本地 Token,不删除 API 地址配置。
```bash
pnpm dev logout
```
### `whoami`
查看当前登录状态(API 地址、用户名、Token 过期时间)。
```bash
pnpm dev whoami
pnpm dev whoami --json
pnpm dev whoami --quiet # 仅输出用户名
```
未登录时退出码 `1`,并提示运行 `login`。
### `stats`
获取平台统计:客户数、有效许可证、即将过期、许可证总数。
```bash
pnpm dev stats
pnpm dev stats --json
pnpm dev stats --quiet # 仅输出有效许可证数量
```
---
## 客户管理 `customer`
### `customer list`
分页列出客户。
| 选项 | 默认 | 说明 |
|------|------|------|
| `--page <n>` | `1` | 页码 |
| `--size <n>` | `20` | 每页条数 |
```bash
pnpm dev customer list
pnpm dev customer list --page 2 --size 10
pnpm dev customer list --json
```
### `customer create`
创建客户。交互模式下会逐步询问公司名、联系人、电话、邮箱、客户编码(编码可留空自动生成)。
| 选项 | 说明 |
|------|------|
| `--name <name>` | 公司名称(**必填**,非交互) |
| `--code <code>` | 客户编码,省略则服务端自动生成 |
| `--contact-name <n>` | 联系人 |
| `--contact-phone <p>` | 联系电话 |
| `--contact-email <e>` | 联系邮箱 |
```bash
pnpm dev customer create
pnpm dev customer create --name "某某科技有限公司" --contact-name 张三 --contact-phone 13800138000
pnpm dev customer create --name "示例公司" --code CUST-001 --json
pnpm dev customer create --name "示例公司" --quiet # 仅输出新客户 ID
```
### `customer show <id>`
查看单个客户详情(JSON 格式)。
```bash
pnpm dev customer show 1
pnpm dev customer show 1 --json
```
### `customer delete <id>`
删除客户。交互模式下需二次确认;`--yes` 跳过确认。
```bash
pnpm dev customer delete 1
pnpm dev customer delete 1 --yes
```
---
## 许可证管理 `license`
### `license list`
分页列出许可证,可按客户、状态筛选。
| 选项 | 默认 | 说明 |
|------|------|------|
| `--page <n>` | `1` | 页码 |
| `--size <n>` | `20` | 每页条数 |
| `--customer-id <id>` | — | 按客户 ID 过滤 |
| `--status <s>` | — | 按状态过滤(如 `active`、`revoked`) |
```bash
pnpm dev license list
pnpm dev license list --customer-id 1 --status active
pnpm dev license list --json
```
### `license show <id>`
查看单个许可证详情。
```bash
pnpm dev license show 1
pnpm dev license show 1 --json
```
### `license generate`
签发新许可证。交互模式为分步向导:选择客户 → 公司名 → 机器指纹 → 版本 → 有效期 → 功能 → 确认摘要。
| 选项 | 默认 | 说明 |
|------|------|------|
| `--customer-id <id>` | — | 客户 ID |
| `--company <name>` | — | 授权公司名 |
| `--fingerprint <fp>` | — | 机器指纹,`FP-xxx` 或 `*`(SaaS 不限) |
| `--edition <e>` | `enterprise` | 版本:`trial` / `enterprise` / `unlimited` |
| `--expires <date>` | — | 过期日 `YYYY-MM-DD` |
| `--features <list>` | `order-import` | 逗号分隔功能列表 |
**非交互模式**必须同时提供:`--customer-id`、`--company`、`--fingerprint`、`--expires`。
```bash
# 交互向导(推荐)
pnpm dev license generate
# 脚本签发
pnpm dev license generate \
--customer-id 1 \
--company "某某科技有限公司" \
--fingerprint "FP-abc123" \
--edition enterprise \
--expires 2027-05-28 \
--features order-import
# SaaS 不限指纹
pnpm dev license generate \
--customer-id 1 \
--company "SaaS 客户" \
--fingerprint "*" \
--expires 2027-05-28
# 仅输出 licenseKey(便于复制到主应用激活)
pnpm dev license generate ... --quiet
pnpm dev license generate ... --json
```
签发成功后交互模式以绿色面板展示 ID、JTI、过期日与完整 `licenseKey`。
### `license revoke <id>`
吊销许可证。交互模式下展示 JTI、指纹并二次确认;`--yes` 跳过。
```bash
pnpm dev license revoke 1
pnpm dev license revoke 1 --yes
pnpm dev license revoke 1 --json
```
### `license download <id>`
下载许可证文件到本地。
| 选项 | 默认 | 说明 |
|------|------|------|
| `-o, --output <file>` | `license-<id>.key` | 保存路径 |
```bash
pnpm dev license download 1
pnpm dev license download 1 -o ./my-license.key
pnpm dev license download 1 --quiet # 仅输出文件路径
```
---
## 典型工作流
### 1. 首次使用
```bash
# 1. 确保 License Server 已启动(ecom-license/server)
cd ../server && pnpm start:dev
# 2. 登录
cd ../cli && pnpm dev login
# 3. 查看平台概况
pnpm dev stats
```
### 2. 为客户签发 License
```bash
pnpm dev customer create --name "某某科技有限公司"
pnpm dev customer list --quiet # 记下客户 ID,或直接用交互 generate
pnpm dev license generate # 交互向导
# 或
pnpm dev license generate \
--customer-id 1 \
--company "某某科技有限公司" \
--fingerprint "FP-xxxxxxxx" \
--expires 2027-12-31 \
--quiet > license.key
```
### 3. CI / 脚本集成
```bash
export ECOM_LICENSE_API_URL=http://license.internal:3100
export ECOM_LICENSE_TOKEN="$(pnpm dev login --username admin --password "$SECRET" --json | jq -r .token)"
pnpm dev customer list --json | jq '.items | length'
pnpm dev stats --json
```
---
## 错误与提示
| 情况 | 行为 |
|------|------|
| 未登录调用需鉴权 API | 提示运行 `ecom-license login`,非裸 401 |
| 网络/服务端错误 | spinner 停止后显示可读错误;加 `--verbose` 看堆栈 |
| Ctrl+C 中断向导 | 优雅退出,不打印 Node 堆栈 |
| 空列表 | 提示下一步建议(如「运行 customer create」) |
---
## 当前未实现的子命令
以下能力在 License Server API 中可能存在,CLI 尚未接入:
- `customer update` — 更新客户信息
- `customer licenses <id>` — 查看某客户下全部许可证
如需使用,可直接调用 Server REST API,或后续在 CLI 中补充。
---
## 相关文档
- 整体设计:`../DESIGN.md`
- CLI 交互规格:`../DESIGN.reference.md` §E
- Server 启动:`../server/README.md`(若有)或 `../README.md`
+32
View File
@@ -0,0 +1,32 @@
{
"name": "ecom-license-cli",
"version": "0.1.0",
"private": true,
"packageManager": "pnpm@10.32.0",
"type": "module",
"bin": {
"ecom-license": "./dist/index.js"
},
"scripts": {
"build": "tsc",
"dev": "tsx src/index.ts",
"start": "node dist/index.js",
"login": "tsx src/index.ts login",
"whoami": "tsx src/index.ts whoami",
"stats": "tsx src/index.ts stats"
},
"dependencies": {
"@inquirer/prompts": "^7.2.0",
"boxen": "^8.0.1",
"chalk": "^5.4.1",
"cli-table3": "^0.6.5",
"commander": "^13.0.0",
"gradient-string": "^3.0.0",
"ora": "^8.1.1"
},
"devDependencies": {
"@types/node": "^22.10.2",
"tsx": "^4.19.2",
"typescript": "^5.7.2"
}
}
+959
View File
@@ -0,0 +1,959 @@
lockfileVersion: '9.0'
settings:
autoInstallPeers: true
excludeLinksFromLockfile: false
importers:
.:
dependencies:
'@inquirer/prompts':
specifier: ^7.2.0
version: 7.10.1(@types/node@22.19.20)
boxen:
specifier: ^8.0.1
version: 8.0.1
chalk:
specifier: ^5.4.1
version: 5.6.2
cli-table3:
specifier: ^0.6.5
version: 0.6.5
commander:
specifier: ^13.0.0
version: 13.1.0
gradient-string:
specifier: ^3.0.0
version: 3.0.0
ora:
specifier: ^8.1.1
version: 8.2.0
devDependencies:
'@types/node':
specifier: ^22.10.2
version: 22.19.20
tsx:
specifier: ^4.19.2
version: 4.22.4
typescript:
specifier: ^5.7.2
version: 5.9.3
packages:
'@colors/colors@1.5.0':
resolution: {integrity: sha512-ooWCrlZP11i8GImSjTHYHLkvFDP48nS4+204nGb1RiX/WXYHmJA2III9/e2DWVabCESdW7hBAEzHRqUn9OUVvQ==}
engines: {node: '>=0.1.90'}
'@esbuild/aix-ppc64@0.28.0':
resolution: {integrity: sha512-lhRUCeuOyJQURhTxl4WkpFTjIsbDayJHih5kZC1giwE+MhIzAb7mEsQMqMf18rHLsrb5qI1tafG20mLxEWcWlA==}
engines: {node: '>=18'}
cpu: [ppc64]
os: [aix]
'@esbuild/android-arm64@0.28.0':
resolution: {integrity: sha512-+WzIXQOSaGs33tLEgYPYe/yQHf0WTU0X42Jca3y8NWMbUVhp7rUnw+vAsRC/QiDrdD31IszMrZy+qwPOPjd+rw==}
engines: {node: '>=18'}
cpu: [arm64]
os: [android]
'@esbuild/android-arm@0.28.0':
resolution: {integrity: sha512-wqh0ByljabXLKHeWXYLqoJ5jKC4XBaw6Hk08OfMrCRd2nP2ZQ5eleDZC41XHyCNgktBGYMbqnrJKq/K/lzPMSQ==}
engines: {node: '>=18'}
cpu: [arm]
os: [android]
'@esbuild/android-x64@0.28.0':
resolution: {integrity: sha512-+VJggoaKhk2VNNqVL7f6S189UzShHC/mR9EE8rDdSkdpN0KflSwWY/gWjDrNxxisg8Fp1ZCD9jLMo4m0OUfeUA==}
engines: {node: '>=18'}
cpu: [x64]
os: [android]
'@esbuild/darwin-arm64@0.28.0':
resolution: {integrity: sha512-0T+A9WZm+bZ84nZBtk1ckYsOvyA3x7e2Acj1KdVfV4/2tdG4fzUp91YHx+GArWLtwqp77pBXVCPn2We7Letr0Q==}
engines: {node: '>=18'}
cpu: [arm64]
os: [darwin]
'@esbuild/darwin-x64@0.28.0':
resolution: {integrity: sha512-fyzLm/DLDl/84OCfp2f/XQ4flmORsjU7VKt8HLjvIXChJoFFOIL6pLJPH4Yhd1n1gGFF9mPwtlN5Wf82DZs+LQ==}
engines: {node: '>=18'}
cpu: [x64]
os: [darwin]
'@esbuild/freebsd-arm64@0.28.0':
resolution: {integrity: sha512-l9GeW5UZBT9k9brBYI+0WDffcRxgHQD8ShN2Ur4xWq/NFzUKm3k5lsH4PdaRgb2w7mI9u61nr2gI2mLI27Nh3Q==}
engines: {node: '>=18'}
cpu: [arm64]
os: [freebsd]
'@esbuild/freebsd-x64@0.28.0':
resolution: {integrity: sha512-BXoQai/A0wPO6Es3yFJ7APCiKGc1tdAEOgeTNy3SsB491S3aHn4S4r3e976eUnPdU+NbdtmBuLncYir2tMU9Nw==}
engines: {node: '>=18'}
cpu: [x64]
os: [freebsd]
'@esbuild/linux-arm64@0.28.0':
resolution: {integrity: sha512-RVyzfb3FWsGA55n6WY0MEIEPURL1FcbhFE6BffZEMEekfCzCIMtB5yyDcFnVbTnwk+CLAgTujmV/Lgvih56W+A==}
engines: {node: '>=18'}
cpu: [arm64]
os: [linux]
'@esbuild/linux-arm@0.28.0':
resolution: {integrity: sha512-CjaaREJagqJp7iTaNQjjidaNbCKYcd4IDkzbwwxtSvjI7NZm79qiHc8HqciMddQ6CKvJT6aBd8lO9kN/ZudLlw==}
engines: {node: '>=18'}
cpu: [arm]
os: [linux]
'@esbuild/linux-ia32@0.28.0':
resolution: {integrity: sha512-KBnSTt1kxl9x70q+ydterVdl+Cn0H18ngRMRCEQfrbqdUuntQQ0LoMZv47uB97NljZFzY6HcfqEZ2SAyIUTQBQ==}
engines: {node: '>=18'}
cpu: [ia32]
os: [linux]
'@esbuild/linux-loong64@0.28.0':
resolution: {integrity: sha512-zpSlUce1mnxzgBADvxKXX5sl8aYQHo2ezvMNI8I0lbblJtp8V4odlm3Yzlj7gPyt3T8ReksE6bK+pT3WD+aJRg==}
engines: {node: '>=18'}
cpu: [loong64]
os: [linux]
'@esbuild/linux-mips64el@0.28.0':
resolution: {integrity: sha512-2jIfP6mmjkdmeTlsX/9vmdmhBmKADrWqN7zcdtHIeNSCH1SqIoNI63cYsjQR8J+wGa4Y5izRcSHSm8K3QWmk3w==}
engines: {node: '>=18'}
cpu: [mips64el]
os: [linux]
'@esbuild/linux-ppc64@0.28.0':
resolution: {integrity: sha512-bc0FE9wWeC0WBm49IQMPSPILRocGTQt3j5KPCA8os6VprfuJ7KD+5PzESSrJ6GmPIPJK965ZJHTUlSA6GNYEhg==}
engines: {node: '>=18'}
cpu: [ppc64]
os: [linux]
'@esbuild/linux-riscv64@0.28.0':
resolution: {integrity: sha512-SQPZOwoTTT/HXFXQJG/vBX8sOFagGqvZyXcgLA3NhIqcBv1BJU1d46c0rGcrij2B56Z2rNiSLaZOYW5cUk7yLQ==}
engines: {node: '>=18'}
cpu: [riscv64]
os: [linux]
'@esbuild/linux-s390x@0.28.0':
resolution: {integrity: sha512-SCfR0HN8CEEjnYnySJTd2cw0k9OHB/YFzt5zgJEwa+wL/T/raGWYMBqwDNAC6dqFKmJYZoQBRfHjgwLHGSrn3Q==}
engines: {node: '>=18'}
cpu: [s390x]
os: [linux]
'@esbuild/linux-x64@0.28.0':
resolution: {integrity: sha512-us0dSb9iFxIi8srnpl931Nvs65it/Jd2a2K3qs7fz2WfGPHqzfzZTfec7oxZJRNPXPnNYZtanmRc4AL/JwVzHQ==}
engines: {node: '>=18'}
cpu: [x64]
os: [linux]
'@esbuild/netbsd-arm64@0.28.0':
resolution: {integrity: sha512-CR/RYotgtCKwtftMwJlUU7xCVNg3lMYZ0RzTmAHSfLCXw3NtZtNpswLEj/Kkf6kEL3Gw+BpOekRX0BYCtklhUw==}
engines: {node: '>=18'}
cpu: [arm64]
os: [netbsd]
'@esbuild/netbsd-x64@0.28.0':
resolution: {integrity: sha512-nU1yhmYutL+fQ71Kxnhg8uEOdC0pwEW9entHykTgEbna2pw2dkbFSMeqjjyHZoCmt8SBkOSvV+yNmm94aUrrqw==}
engines: {node: '>=18'}
cpu: [x64]
os: [netbsd]
'@esbuild/openbsd-arm64@0.28.0':
resolution: {integrity: sha512-cXb5vApOsRsxsEl4mcZ1XY3D4DzcoMxR/nnc4IyqYs0rTI8ZKmW6kyyg+11Z8yvgMfAEldKzP7AdP64HnSC/6g==}
engines: {node: '>=18'}
cpu: [arm64]
os: [openbsd]
'@esbuild/openbsd-x64@0.28.0':
resolution: {integrity: sha512-8wZM2qqtv9UP3mzy7HiGYNH/zjTA355mpeuA+859TyR+e+Tc08IHYpLJuMsfpDJwoLo1ikIJI8jC3GFjnRClzA==}
engines: {node: '>=18'}
cpu: [x64]
os: [openbsd]
'@esbuild/openharmony-arm64@0.28.0':
resolution: {integrity: sha512-FLGfyizszcef5C3YtoyQDACyg95+dndv79i2EekILBofh5wpCa1KuBqOWKrEHZg3zrL3t5ouE5jgr94vA+Wb2w==}
engines: {node: '>=18'}
cpu: [arm64]
os: [openharmony]
'@esbuild/sunos-x64@0.28.0':
resolution: {integrity: sha512-1ZgjUoEdHZZl/YlV76TSCz9Hqj9h9YmMGAgAPYd+q4SicWNX3G5GCyx9uhQWSLcbvPW8Ni7lj4gDa1T40akdlw==}
engines: {node: '>=18'}
cpu: [x64]
os: [sunos]
'@esbuild/win32-arm64@0.28.0':
resolution: {integrity: sha512-Q9StnDmQ/enxnpxCCLSg0oo4+34B9TdXpuyPeTedN/6+iXBJ4J+zwfQI28u/Jl40nOYAxGoNi7mFP40RUtkmUA==}
engines: {node: '>=18'}
cpu: [arm64]
os: [win32]
'@esbuild/win32-ia32@0.28.0':
resolution: {integrity: sha512-zF3ag/gfiCe6U2iczcRzSYJKH1DCI+ByzSENHlM2FcDbEeo5Zd2C86Aq0tKUYAJJ1obRP84ymxIAksZUcdztHA==}
engines: {node: '>=18'}
cpu: [ia32]
os: [win32]
'@esbuild/win32-x64@0.28.0':
resolution: {integrity: sha512-pEl1bO9mfAmIC+tW5btTmrKaujg3zGtUmWNdCw/xs70FBjwAL3o9OEKNHvNmnyylD6ubxUERiEhdsL0xBQ9efw==}
engines: {node: '>=18'}
cpu: [x64]
os: [win32]
'@inquirer/ansi@1.0.2':
resolution: {integrity: sha512-S8qNSZiYzFd0wAcyG5AXCvUHC5Sr7xpZ9wZ2py9XR88jUz8wooStVx5M6dRzczbBWjic9NP7+rY0Xi7qqK/aMQ==}
engines: {node: '>=18'}
'@inquirer/checkbox@4.3.2':
resolution: {integrity: sha512-VXukHf0RR1doGe6Sm4F0Em7SWYLTHSsbGfJdS9Ja2bX5/D5uwVOEjr07cncLROdBvmnvCATYEWlHqYmXv2IlQA==}
engines: {node: '>=18'}
peerDependencies:
'@types/node': '>=18'
peerDependenciesMeta:
'@types/node':
optional: true
'@inquirer/confirm@5.1.21':
resolution: {integrity: sha512-KR8edRkIsUayMXV+o3Gv+q4jlhENF9nMYUZs9PA2HzrXeHI8M5uDag70U7RJn9yyiMZSbtF5/UexBtAVtZGSbQ==}
engines: {node: '>=18'}
peerDependencies:
'@types/node': '>=18'
peerDependenciesMeta:
'@types/node':
optional: true
'@inquirer/core@10.3.2':
resolution: {integrity: sha512-43RTuEbfP8MbKzedNqBrlhhNKVwoK//vUFNW3Q3vZ88BLcrs4kYpGg+B2mm5p2K/HfygoCxuKwJJiv8PbGmE0A==}
engines: {node: '>=18'}
peerDependencies:
'@types/node': '>=18'
peerDependenciesMeta:
'@types/node':
optional: true
'@inquirer/editor@4.2.23':
resolution: {integrity: sha512-aLSROkEwirotxZ1pBaP8tugXRFCxW94gwrQLxXfrZsKkfjOYC1aRvAZuhpJOb5cu4IBTJdsCigUlf2iCOu4ZDQ==}
engines: {node: '>=18'}
peerDependencies:
'@types/node': '>=18'
peerDependenciesMeta:
'@types/node':
optional: true
'@inquirer/expand@4.0.23':
resolution: {integrity: sha512-nRzdOyFYnpeYTTR2qFwEVmIWypzdAx/sIkCMeTNTcflFOovfqUk+HcFhQQVBftAh9gmGrpFj6QcGEqrDMDOiew==}
engines: {node: '>=18'}
peerDependencies:
'@types/node': '>=18'
peerDependenciesMeta:
'@types/node':
optional: true
'@inquirer/external-editor@1.0.3':
resolution: {integrity: sha512-RWbSrDiYmO4LbejWY7ttpxczuwQyZLBUyygsA9Nsv95hpzUWwnNTVQmAq3xuh7vNwCp07UTmE5i11XAEExx4RA==}
engines: {node: '>=18'}
peerDependencies:
'@types/node': '>=18'
peerDependenciesMeta:
'@types/node':
optional: true
'@inquirer/figures@1.0.15':
resolution: {integrity: sha512-t2IEY+unGHOzAaVM5Xx6DEWKeXlDDcNPeDyUpsRc6CUhBfU3VQOEl+Vssh7VNp1dR8MdUJBWhuObjXCsVpjN5g==}
engines: {node: '>=18'}
'@inquirer/input@4.3.1':
resolution: {integrity: sha512-kN0pAM4yPrLjJ1XJBjDxyfDduXOuQHrBB8aLDMueuwUGn+vNpF7Gq7TvyVxx8u4SHlFFj4trmj+a2cbpG4Jn1g==}
engines: {node: '>=18'}
peerDependencies:
'@types/node': '>=18'
peerDependenciesMeta:
'@types/node':
optional: true
'@inquirer/number@3.0.23':
resolution: {integrity: sha512-5Smv0OK7K0KUzUfYUXDXQc9jrf8OHo4ktlEayFlelCjwMXz0299Y8OrI+lj7i4gCBY15UObk76q0QtxjzFcFcg==}
engines: {node: '>=18'}
peerDependencies:
'@types/node': '>=18'
peerDependenciesMeta:
'@types/node':
optional: true
'@inquirer/password@4.0.23':
resolution: {integrity: sha512-zREJHjhT5vJBMZX/IUbyI9zVtVfOLiTO66MrF/3GFZYZ7T4YILW5MSkEYHceSii/KtRk+4i3RE7E1CUXA2jHcA==}
engines: {node: '>=18'}
peerDependencies:
'@types/node': '>=18'
peerDependenciesMeta:
'@types/node':
optional: true
'@inquirer/prompts@7.10.1':
resolution: {integrity: sha512-Dx/y9bCQcXLI5ooQ5KyvA4FTgeo2jYj/7plWfV5Ak5wDPKQZgudKez2ixyfz7tKXzcJciTxqLeK7R9HItwiByg==}
engines: {node: '>=18'}
peerDependencies:
'@types/node': '>=18'
peerDependenciesMeta:
'@types/node':
optional: true
'@inquirer/rawlist@4.1.11':
resolution: {integrity: sha512-+LLQB8XGr3I5LZN/GuAHo+GpDJegQwuPARLChlMICNdwW7OwV2izlCSCxN6cqpL0sMXmbKbFcItJgdQq5EBXTw==}
engines: {node: '>=18'}
peerDependencies:
'@types/node': '>=18'
peerDependenciesMeta:
'@types/node':
optional: true
'@inquirer/search@3.2.2':
resolution: {integrity: sha512-p2bvRfENXCZdWF/U2BXvnSI9h+tuA8iNqtUKb9UWbmLYCRQxd8WkvwWvYn+3NgYaNwdUkHytJMGG4MMLucI1kA==}
engines: {node: '>=18'}
peerDependencies:
'@types/node': '>=18'
peerDependenciesMeta:
'@types/node':
optional: true
'@inquirer/select@4.4.2':
resolution: {integrity: sha512-l4xMuJo55MAe+N7Qr4rX90vypFwCajSakx59qe/tMaC1aEHWLyw68wF4o0A4SLAY4E0nd+Vt+EyskeDIqu1M6w==}
engines: {node: '>=18'}
peerDependencies:
'@types/node': '>=18'
peerDependenciesMeta:
'@types/node':
optional: true
'@inquirer/type@3.0.10':
resolution: {integrity: sha512-BvziSRxfz5Ov8ch0z/n3oijRSEcEsHnhggm4xFZe93DHcUCTlutlq9Ox4SVENAfcRD22UQq7T/atg9Wr3k09eA==}
engines: {node: '>=18'}
peerDependencies:
'@types/node': '>=18'
peerDependenciesMeta:
'@types/node':
optional: true
'@types/node@22.19.20':
resolution: {integrity: sha512-6tELRwSDYWW9EdZhbeZmYGZ1/7Djkt+Ah3/ScEYT9cDord7UJzasR/4D3VONg9tQI5CDp+/CZC1AXj2pCFOvpw==}
'@types/tinycolor2@1.4.6':
resolution: {integrity: sha512-iEN8J0BoMnsWBqjVbWH/c0G0Hh7O21lpR2/+PrvAVgWdzL7eexIFm4JN/Wn10PTcmNdtS6U67r499mlWMXOxNw==}
ansi-align@3.0.1:
resolution: {integrity: sha512-IOfwwBF5iczOjp/WeY4YxyjqAFMQoZufdQWDd19SEExbVLNXqvpzSJ/M7Za4/sCPmQ0+GRquoA7bGcINcxew6w==}
ansi-regex@5.0.1:
resolution: {integrity: sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==}
engines: {node: '>=8'}
ansi-regex@6.2.2:
resolution: {integrity: sha512-Bq3SmSpyFHaWjPk8If9yc6svM8c56dB5BAtW4Qbw5jHTwwXXcTLoRMkpDJp6VL0XzlWaCHTXrkFURMYmD0sLqg==}
engines: {node: '>=12'}
ansi-styles@4.3.0:
resolution: {integrity: sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==}
engines: {node: '>=8'}
ansi-styles@6.2.3:
resolution: {integrity: sha512-4Dj6M28JB+oAH8kFkTLUo+a2jwOFkuqb3yucU0CANcRRUbxS0cP0nZYCGjcc3BNXwRIsUVmDGgzawme7zvJHvg==}
engines: {node: '>=12'}
boxen@8.0.1:
resolution: {integrity: sha512-F3PH5k5juxom4xktynS7MoFY+NUWH5LC4CnH11YB8NPew+HLpmBLCybSAEyb2F+4pRXhuhWqFesoQd6DAyc2hw==}
engines: {node: '>=18'}
camelcase@8.0.0:
resolution: {integrity: sha512-8WB3Jcas3swSvjIeA2yvCJ+Miyz5l1ZmB6HFb9R1317dt9LCQoswg/BGrmAmkWVEszSrrg4RwmO46qIm2OEnSA==}
engines: {node: '>=16'}
chalk@5.6.2:
resolution: {integrity: sha512-7NzBL0rN6fMUW+f7A6Io4h40qQlG+xGmtMxfbnH/K7TAtt8JQWVQK+6g0UXKMeVJoyV5EkkNsErQ8pVD3bLHbA==}
engines: {node: ^12.17.0 || ^14.13 || >=16.0.0}
chardet@2.1.1:
resolution: {integrity: sha512-PsezH1rqdV9VvyNhxxOW32/d75r01NY7TQCmOqomRo15ZSOKbpTFVsfjghxo6JloQUCGnH4k1LGu0R4yCLlWQQ==}
cli-boxes@3.0.0:
resolution: {integrity: sha512-/lzGpEWL/8PfI0BmBOPRwp0c/wFNX1RdUML3jK/RcSBA9T8mZDdQpqYBKtCFTOfQbwPqWEOpjqW+Fnayc0969g==}
engines: {node: '>=10'}
cli-cursor@5.0.0:
resolution: {integrity: sha512-aCj4O5wKyszjMmDT4tZj93kxyydN/K5zPWSCe6/0AV/AA1pqe5ZBIw0a2ZfPQV7lL5/yb5HsUreJ6UFAF1tEQw==}
engines: {node: '>=18'}
cli-spinners@2.9.2:
resolution: {integrity: sha512-ywqV+5MmyL4E7ybXgKys4DugZbX0FC6LnwrhjuykIjnK9k8OQacQ7axGKnjDXWNhns0xot3bZI5h55H8yo9cJg==}
engines: {node: '>=6'}
cli-table3@0.6.5:
resolution: {integrity: sha512-+W/5efTR7y5HRD7gACw9yQjqMVvEMLBHmboM/kPWam+H+Hmyrgjh6YncVKK122YZkXrLudzTuAukUw9FnMf7IQ==}
engines: {node: 10.* || >= 12.*}
cli-width@4.1.0:
resolution: {integrity: sha512-ouuZd4/dm2Sw5Gmqy6bGyNNNe1qt9RpmxveLSO7KcgsTnU7RXfsw+/bukWGo1abgBiMAic068rclZsO4IWmmxQ==}
engines: {node: '>= 12'}
color-convert@2.0.1:
resolution: {integrity: sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==}
engines: {node: '>=7.0.0'}
color-name@1.1.4:
resolution: {integrity: sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==}
commander@13.1.0:
resolution: {integrity: sha512-/rFeCpNJQbhSZjGVwO9RFV3xPqbnERS8MmIQzCtD/zl6gpJuV/bMLuN92oG3F7d8oDEHHRrujSXNUr8fpjntKw==}
engines: {node: '>=18'}
emoji-regex@10.6.0:
resolution: {integrity: sha512-toUI84YS5YmxW219erniWD0CIVOo46xGKColeNQRgOzDorgBi1v4D71/OFzgD9GO2UGKIv1C3Sp8DAn0+j5w7A==}
emoji-regex@8.0.0:
resolution: {integrity: sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==}
esbuild@0.28.0:
resolution: {integrity: sha512-sNR9MHpXSUV/XB4zmsFKN+QgVG82Cc7+/aaxJ8Adi8hyOac+EXptIp45QBPaVyX3N70664wRbTcLTOemCAnyqw==}
engines: {node: '>=18'}
hasBin: true
fsevents@2.3.3:
resolution: {integrity: sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==}
engines: {node: ^8.16.0 || ^10.6.0 || >=11.0.0}
os: [darwin]
get-east-asian-width@1.6.0:
resolution: {integrity: sha512-QRbvDIbx6YklUe6RxeTeleMR0yv3cYH6PsPZHcnVn7xv7zO1BHN8r0XETu8n6Ye3Q+ahtSarc3WgtNWmehIBfA==}
engines: {node: '>=18'}
gradient-string@3.0.0:
resolution: {integrity: sha512-frdKI4Qi8Ihp4C6wZNB565de/THpIaw3DjP5ku87M+N9rNSGmPTjfkq61SdRXB7eCaL8O1hkKDvf6CDMtOzIAg==}
engines: {node: '>=14'}
iconv-lite@0.7.2:
resolution: {integrity: sha512-im9DjEDQ55s9fL4EYzOAv0yMqmMBSZp6G0VvFyTMPKWxiSBHUj9NW/qqLmXUwXrrM7AvqSlTCfvqRb0cM8yYqw==}
engines: {node: '>=0.10.0'}
is-fullwidth-code-point@3.0.0:
resolution: {integrity: sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==}
engines: {node: '>=8'}
is-interactive@2.0.0:
resolution: {integrity: sha512-qP1vozQRI+BMOPcjFzrjXuQvdak2pHNUMZoeG2eRbiSqyvbEf/wQtEOTOX1guk6E3t36RkaqiSt8A/6YElNxLQ==}
engines: {node: '>=12'}
is-unicode-supported@1.3.0:
resolution: {integrity: sha512-43r2mRvz+8JRIKnWJ+3j8JtjRKZ6GmjzfaE/qiBJnikNnYv/6bagRJ1kUhNk8R5EX/GkobD+r+sfxCPJsiKBLQ==}
engines: {node: '>=12'}
is-unicode-supported@2.1.0:
resolution: {integrity: sha512-mE00Gnza5EEB3Ds0HfMyllZzbBrmLOX3vfWoj9A9PEnTfratQ/BcaJOuMhnkhjXvb2+FkY3VuHqtAGpTPmglFQ==}
engines: {node: '>=18'}
log-symbols@6.0.0:
resolution: {integrity: sha512-i24m8rpwhmPIS4zscNzK6MSEhk0DUWa/8iYQWxhffV8jkI4Phvs3F+quL5xvS0gdQR0FyTCMMH33Y78dDTzzIw==}
engines: {node: '>=18'}
mimic-function@5.0.1:
resolution: {integrity: sha512-VP79XUPxV2CigYP3jWwAUFSku2aKqBH7uTAapFWCBqutsbmDo96KY5o8uh6U+/YSIn5OxJnXp73beVkpqMIGhA==}
engines: {node: '>=18'}
mute-stream@2.0.0:
resolution: {integrity: sha512-WWdIxpyjEn+FhQJQQv9aQAYlHoNVdzIzUySNV1gHUPDSdZJ3yZn7pAAbQcV7B56Mvu881q9FZV+0Vx2xC44VWA==}
engines: {node: ^18.17.0 || >=20.5.0}
onetime@7.0.0:
resolution: {integrity: sha512-VXJjc87FScF88uafS3JllDgvAm+c/Slfz06lorj2uAY34rlUu0Nt+v8wreiImcrgAjjIHp1rXpTDlLOGw29WwQ==}
engines: {node: '>=18'}
ora@8.2.0:
resolution: {integrity: sha512-weP+BZ8MVNnlCm8c0Qdc1WSWq4Qn7I+9CJGm7Qali6g44e/PUzbjNqJX5NJ9ljlNMosfJvg1fKEGILklK9cwnw==}
engines: {node: '>=18'}
restore-cursor@5.1.0:
resolution: {integrity: sha512-oMA2dcrw6u0YfxJQXm342bFKX/E4sG9rbTzO9ptUcR/e8A33cHuvStiYOwH7fszkZlZ1z/ta9AAoPk2F4qIOHA==}
engines: {node: '>=18'}
safer-buffer@2.1.2:
resolution: {integrity: sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==}
signal-exit@4.1.0:
resolution: {integrity: sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw==}
engines: {node: '>=14'}
stdin-discarder@0.2.2:
resolution: {integrity: sha512-UhDfHmA92YAlNnCfhmq0VeNL5bDbiZGg7sZ2IvPsXubGkiNa9EC+tUTsjBRsYUAz87btI6/1wf4XoVvQ3uRnmQ==}
engines: {node: '>=18'}
string-width@4.2.3:
resolution: {integrity: sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==}
engines: {node: '>=8'}
string-width@7.2.0:
resolution: {integrity: sha512-tsaTIkKW9b4N+AEj+SVA+WhJzV7/zMhcSu78mLKWSk7cXMOSHsBKFWUs0fWwq8QyK3MgJBQRX6Gbi4kYbdvGkQ==}
engines: {node: '>=18'}
strip-ansi@6.0.1:
resolution: {integrity: sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==}
engines: {node: '>=8'}
strip-ansi@7.2.0:
resolution: {integrity: sha512-yDPMNjp4WyfYBkHnjIRLfca1i6KMyGCtsVgoKe/z1+6vukgaENdgGBZt+ZmKPc4gavvEZ5OgHfHdrazhgNyG7w==}
engines: {node: '>=12'}
tinycolor2@1.6.0:
resolution: {integrity: sha512-XPaBkWQJdsf3pLKJV9p4qN/S+fm2Oj8AIPo1BTUhg5oxkvm9+SVEGFdhyOz7tTdUTfvxMiAs4sp6/eZO2Ew+pw==}
tinygradient@1.1.5:
resolution: {integrity: sha512-8nIfc2vgQ4TeLnk2lFj4tRLvvJwEfQuabdsmvDdQPT0xlk9TaNtpGd6nNRxXoK6vQhN6RSzj+Cnp5tTQmpxmbw==}
tsx@4.22.4:
resolution: {integrity: sha512-X8EX+XV4QR5xCsrgxaED954zTDfY8KqlDtskKEL0cHhyS/P8b4IFOvGDQpsC9Q1XnLq915wEfwwY/zzskCtmhg==}
engines: {node: '>=18.0.0'}
hasBin: true
type-fest@4.41.0:
resolution: {integrity: sha512-TeTSQ6H5YHvpqVwBRcnLDCBnDOHWYu7IvGbHT6N8AOymcr9PJGjc1GTtiWZTYg0NCgYwvnYWEkVChQAr9bjfwA==}
engines: {node: '>=16'}
typescript@5.9.3:
resolution: {integrity: sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==}
engines: {node: '>=14.17'}
hasBin: true
undici-types@6.21.0:
resolution: {integrity: sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==}
widest-line@5.0.0:
resolution: {integrity: sha512-c9bZp7b5YtRj2wOe6dlj32MK+Bx/M/d+9VB2SHM1OtsUHR0aV0tdP6DWh/iMt0kWi1t5g1Iudu6hQRNd1A4PVA==}
engines: {node: '>=18'}
wrap-ansi@6.2.0:
resolution: {integrity: sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA==}
engines: {node: '>=8'}
wrap-ansi@9.0.2:
resolution: {integrity: sha512-42AtmgqjV+X1VpdOfyTGOYRi0/zsoLqtXQckTmqTeybT+BDIbM/Guxo7x3pE2vtpr1ok6xRqM9OpBe+Jyoqyww==}
engines: {node: '>=18'}
yoctocolors-cjs@2.1.3:
resolution: {integrity: sha512-U/PBtDf35ff0D8X8D0jfdzHYEPFxAI7jJlxZXwCSez5M3190m+QobIfh+sWDWSHMCWWJN2AWamkegn6vr6YBTw==}
engines: {node: '>=18'}
snapshots:
'@colors/colors@1.5.0':
optional: true
'@esbuild/aix-ppc64@0.28.0':
optional: true
'@esbuild/android-arm64@0.28.0':
optional: true
'@esbuild/android-arm@0.28.0':
optional: true
'@esbuild/android-x64@0.28.0':
optional: true
'@esbuild/darwin-arm64@0.28.0':
optional: true
'@esbuild/darwin-x64@0.28.0':
optional: true
'@esbuild/freebsd-arm64@0.28.0':
optional: true
'@esbuild/freebsd-x64@0.28.0':
optional: true
'@esbuild/linux-arm64@0.28.0':
optional: true
'@esbuild/linux-arm@0.28.0':
optional: true
'@esbuild/linux-ia32@0.28.0':
optional: true
'@esbuild/linux-loong64@0.28.0':
optional: true
'@esbuild/linux-mips64el@0.28.0':
optional: true
'@esbuild/linux-ppc64@0.28.0':
optional: true
'@esbuild/linux-riscv64@0.28.0':
optional: true
'@esbuild/linux-s390x@0.28.0':
optional: true
'@esbuild/linux-x64@0.28.0':
optional: true
'@esbuild/netbsd-arm64@0.28.0':
optional: true
'@esbuild/netbsd-x64@0.28.0':
optional: true
'@esbuild/openbsd-arm64@0.28.0':
optional: true
'@esbuild/openbsd-x64@0.28.0':
optional: true
'@esbuild/openharmony-arm64@0.28.0':
optional: true
'@esbuild/sunos-x64@0.28.0':
optional: true
'@esbuild/win32-arm64@0.28.0':
optional: true
'@esbuild/win32-ia32@0.28.0':
optional: true
'@esbuild/win32-x64@0.28.0':
optional: true
'@inquirer/ansi@1.0.2': {}
'@inquirer/checkbox@4.3.2(@types/node@22.19.20)':
dependencies:
'@inquirer/ansi': 1.0.2
'@inquirer/core': 10.3.2(@types/node@22.19.20)
'@inquirer/figures': 1.0.15
'@inquirer/type': 3.0.10(@types/node@22.19.20)
yoctocolors-cjs: 2.1.3
optionalDependencies:
'@types/node': 22.19.20
'@inquirer/confirm@5.1.21(@types/node@22.19.20)':
dependencies:
'@inquirer/core': 10.3.2(@types/node@22.19.20)
'@inquirer/type': 3.0.10(@types/node@22.19.20)
optionalDependencies:
'@types/node': 22.19.20
'@inquirer/core@10.3.2(@types/node@22.19.20)':
dependencies:
'@inquirer/ansi': 1.0.2
'@inquirer/figures': 1.0.15
'@inquirer/type': 3.0.10(@types/node@22.19.20)
cli-width: 4.1.0
mute-stream: 2.0.0
signal-exit: 4.1.0
wrap-ansi: 6.2.0
yoctocolors-cjs: 2.1.3
optionalDependencies:
'@types/node': 22.19.20
'@inquirer/editor@4.2.23(@types/node@22.19.20)':
dependencies:
'@inquirer/core': 10.3.2(@types/node@22.19.20)
'@inquirer/external-editor': 1.0.3(@types/node@22.19.20)
'@inquirer/type': 3.0.10(@types/node@22.19.20)
optionalDependencies:
'@types/node': 22.19.20
'@inquirer/expand@4.0.23(@types/node@22.19.20)':
dependencies:
'@inquirer/core': 10.3.2(@types/node@22.19.20)
'@inquirer/type': 3.0.10(@types/node@22.19.20)
yoctocolors-cjs: 2.1.3
optionalDependencies:
'@types/node': 22.19.20
'@inquirer/external-editor@1.0.3(@types/node@22.19.20)':
dependencies:
chardet: 2.1.1
iconv-lite: 0.7.2
optionalDependencies:
'@types/node': 22.19.20
'@inquirer/figures@1.0.15': {}
'@inquirer/input@4.3.1(@types/node@22.19.20)':
dependencies:
'@inquirer/core': 10.3.2(@types/node@22.19.20)
'@inquirer/type': 3.0.10(@types/node@22.19.20)
optionalDependencies:
'@types/node': 22.19.20
'@inquirer/number@3.0.23(@types/node@22.19.20)':
dependencies:
'@inquirer/core': 10.3.2(@types/node@22.19.20)
'@inquirer/type': 3.0.10(@types/node@22.19.20)
optionalDependencies:
'@types/node': 22.19.20
'@inquirer/password@4.0.23(@types/node@22.19.20)':
dependencies:
'@inquirer/ansi': 1.0.2
'@inquirer/core': 10.3.2(@types/node@22.19.20)
'@inquirer/type': 3.0.10(@types/node@22.19.20)
optionalDependencies:
'@types/node': 22.19.20
'@inquirer/prompts@7.10.1(@types/node@22.19.20)':
dependencies:
'@inquirer/checkbox': 4.3.2(@types/node@22.19.20)
'@inquirer/confirm': 5.1.21(@types/node@22.19.20)
'@inquirer/editor': 4.2.23(@types/node@22.19.20)
'@inquirer/expand': 4.0.23(@types/node@22.19.20)
'@inquirer/input': 4.3.1(@types/node@22.19.20)
'@inquirer/number': 3.0.23(@types/node@22.19.20)
'@inquirer/password': 4.0.23(@types/node@22.19.20)
'@inquirer/rawlist': 4.1.11(@types/node@22.19.20)
'@inquirer/search': 3.2.2(@types/node@22.19.20)
'@inquirer/select': 4.4.2(@types/node@22.19.20)
optionalDependencies:
'@types/node': 22.19.20
'@inquirer/rawlist@4.1.11(@types/node@22.19.20)':
dependencies:
'@inquirer/core': 10.3.2(@types/node@22.19.20)
'@inquirer/type': 3.0.10(@types/node@22.19.20)
yoctocolors-cjs: 2.1.3
optionalDependencies:
'@types/node': 22.19.20
'@inquirer/search@3.2.2(@types/node@22.19.20)':
dependencies:
'@inquirer/core': 10.3.2(@types/node@22.19.20)
'@inquirer/figures': 1.0.15
'@inquirer/type': 3.0.10(@types/node@22.19.20)
yoctocolors-cjs: 2.1.3
optionalDependencies:
'@types/node': 22.19.20
'@inquirer/select@4.4.2(@types/node@22.19.20)':
dependencies:
'@inquirer/ansi': 1.0.2
'@inquirer/core': 10.3.2(@types/node@22.19.20)
'@inquirer/figures': 1.0.15
'@inquirer/type': 3.0.10(@types/node@22.19.20)
yoctocolors-cjs: 2.1.3
optionalDependencies:
'@types/node': 22.19.20
'@inquirer/type@3.0.10(@types/node@22.19.20)':
optionalDependencies:
'@types/node': 22.19.20
'@types/node@22.19.20':
dependencies:
undici-types: 6.21.0
'@types/tinycolor2@1.4.6': {}
ansi-align@3.0.1:
dependencies:
string-width: 4.2.3
ansi-regex@5.0.1: {}
ansi-regex@6.2.2: {}
ansi-styles@4.3.0:
dependencies:
color-convert: 2.0.1
ansi-styles@6.2.3: {}
boxen@8.0.1:
dependencies:
ansi-align: 3.0.1
camelcase: 8.0.0
chalk: 5.6.2
cli-boxes: 3.0.0
string-width: 7.2.0
type-fest: 4.41.0
widest-line: 5.0.0
wrap-ansi: 9.0.2
camelcase@8.0.0: {}
chalk@5.6.2: {}
chardet@2.1.1: {}
cli-boxes@3.0.0: {}
cli-cursor@5.0.0:
dependencies:
restore-cursor: 5.1.0
cli-spinners@2.9.2: {}
cli-table3@0.6.5:
dependencies:
string-width: 4.2.3
optionalDependencies:
'@colors/colors': 1.5.0
cli-width@4.1.0: {}
color-convert@2.0.1:
dependencies:
color-name: 1.1.4
color-name@1.1.4: {}
commander@13.1.0: {}
emoji-regex@10.6.0: {}
emoji-regex@8.0.0: {}
esbuild@0.28.0:
optionalDependencies:
'@esbuild/aix-ppc64': 0.28.0
'@esbuild/android-arm': 0.28.0
'@esbuild/android-arm64': 0.28.0
'@esbuild/android-x64': 0.28.0
'@esbuild/darwin-arm64': 0.28.0
'@esbuild/darwin-x64': 0.28.0
'@esbuild/freebsd-arm64': 0.28.0
'@esbuild/freebsd-x64': 0.28.0
'@esbuild/linux-arm': 0.28.0
'@esbuild/linux-arm64': 0.28.0
'@esbuild/linux-ia32': 0.28.0
'@esbuild/linux-loong64': 0.28.0
'@esbuild/linux-mips64el': 0.28.0
'@esbuild/linux-ppc64': 0.28.0
'@esbuild/linux-riscv64': 0.28.0
'@esbuild/linux-s390x': 0.28.0
'@esbuild/linux-x64': 0.28.0
'@esbuild/netbsd-arm64': 0.28.0
'@esbuild/netbsd-x64': 0.28.0
'@esbuild/openbsd-arm64': 0.28.0
'@esbuild/openbsd-x64': 0.28.0
'@esbuild/openharmony-arm64': 0.28.0
'@esbuild/sunos-x64': 0.28.0
'@esbuild/win32-arm64': 0.28.0
'@esbuild/win32-ia32': 0.28.0
'@esbuild/win32-x64': 0.28.0
fsevents@2.3.3:
optional: true
get-east-asian-width@1.6.0: {}
gradient-string@3.0.0:
dependencies:
chalk: 5.6.2
tinygradient: 1.1.5
iconv-lite@0.7.2:
dependencies:
safer-buffer: 2.1.2
is-fullwidth-code-point@3.0.0: {}
is-interactive@2.0.0: {}
is-unicode-supported@1.3.0: {}
is-unicode-supported@2.1.0: {}
log-symbols@6.0.0:
dependencies:
chalk: 5.6.2
is-unicode-supported: 1.3.0
mimic-function@5.0.1: {}
mute-stream@2.0.0: {}
onetime@7.0.0:
dependencies:
mimic-function: 5.0.1
ora@8.2.0:
dependencies:
chalk: 5.6.2
cli-cursor: 5.0.0
cli-spinners: 2.9.2
is-interactive: 2.0.0
is-unicode-supported: 2.1.0
log-symbols: 6.0.0
stdin-discarder: 0.2.2
string-width: 7.2.0
strip-ansi: 7.2.0
restore-cursor@5.1.0:
dependencies:
onetime: 7.0.0
signal-exit: 4.1.0
safer-buffer@2.1.2: {}
signal-exit@4.1.0: {}
stdin-discarder@0.2.2: {}
string-width@4.2.3:
dependencies:
emoji-regex: 8.0.0
is-fullwidth-code-point: 3.0.0
strip-ansi: 6.0.1
string-width@7.2.0:
dependencies:
emoji-regex: 10.6.0
get-east-asian-width: 1.6.0
strip-ansi: 7.2.0
strip-ansi@6.0.1:
dependencies:
ansi-regex: 5.0.1
strip-ansi@7.2.0:
dependencies:
ansi-regex: 6.2.2
tinycolor2@1.6.0: {}
tinygradient@1.1.5:
dependencies:
'@types/tinycolor2': 1.4.6
tinycolor2: 1.6.0
tsx@4.22.4:
dependencies:
esbuild: 0.28.0
optionalDependencies:
fsevents: 2.3.3
type-fest@4.41.0: {}
typescript@5.9.3: {}
undici-types@6.21.0: {}
widest-line@5.0.0:
dependencies:
string-width: 7.2.0
wrap-ansi@6.2.0:
dependencies:
ansi-styles: 4.3.0
string-width: 4.2.3
strip-ansi: 6.0.1
wrap-ansi@9.0.2:
dependencies:
ansi-styles: 6.2.3
string-width: 7.2.0
strip-ansi: 7.2.0
yoctocolors-cjs@2.1.3: {}
+95
View File
@@ -0,0 +1,95 @@
import { getGlobalOpts, isInteractive } from '../context.js';
import { loadConfig, resolveApiUrl, resolveToken } from '../config.js';
import { failSpinner, runSpinner } from '../ui/render.js';
export class ApiError extends Error {
constructor(
message: string,
public status?: number,
) {
super(message);
}
}
async function parseError(res: Response): Promise<string> {
try {
const body = await res.json();
if (typeof body?.message === 'string') return body.message;
if (Array.isArray(body?.message)) return body.message.join(', ');
return JSON.stringify(body);
} catch {
return res.statusText || `HTTP ${res.status}`;
}
}
export async function apiRequest<T>(
method: string,
path: string,
body?: unknown,
auth = true,
): Promise<T> {
const opts = getGlobalOpts();
const config = await loadConfig();
const baseUrl = resolveApiUrl(opts.url, config);
const token = resolveToken(opts.token, config);
const headers: Record<string, string> = {
'Content-Type': 'application/json',
Accept: 'application/json',
};
if (auth && token) {
headers.Authorization = `Bearer ${token}`;
}
const doFetch = async () => {
const res = await fetch(`${baseUrl}/api${path}`, {
method,
headers,
body: body !== undefined ? JSON.stringify(body) : undefined,
});
if (!res.ok) {
throw new ApiError(await parseError(res), res.status);
}
if (res.status === 204) return undefined as T;
const contentType = res.headers.get('content-type') || '';
if (contentType.includes('application/json')) {
return (await res.json()) as T;
}
return (await res.text()) as T;
};
if (isInteractive() && !opts.quiet && !opts.json) {
return runSpinner(doFetch, '请求中...');
}
try {
return await doFetch();
} catch (e) {
if (e instanceof ApiError && e.status === 401 && auth) {
failSpinner('未登录或 Token 已过期,请运行: ecom-license login');
}
throw e;
}
}
export async function apiDownload(path: string, outfile: string): Promise<string> {
const opts = getGlobalOpts();
const config = await loadConfig();
const baseUrl = resolveApiUrl(opts.url, config);
const token = resolveToken(opts.token, config);
const doFetch = async () => {
const res = await fetch(`${baseUrl}/api${path}`, {
headers: token ? { Authorization: `Bearer ${token}` } : {},
});
if (!res.ok) throw new ApiError(await parseError(res), res.status);
const { writeFile } = await import('fs/promises');
const text = await res.text();
await writeFile(outfile, text, 'utf8');
return outfile;
};
if (isInteractive()) {
return runSpinner(doFetch, '正在下载...');
}
return doFetch();
}
+104
View File
@@ -0,0 +1,104 @@
import { confirm, input } from '@inquirer/prompts';
import { apiRequest } from '../api/client.js';
import { getGlobalOpts, isInteractive } from '../context.js';
import {
printEmptyHint,
printJson,
printQuiet,
printSuccess,
printTable,
} from '../ui/render.js';
interface Customer {
id: number;
code: string;
name: string;
status: number;
contactName?: string;
contactPhone?: string;
}
interface PageResult<T> {
items: T[];
total: number;
page: number;
size: number;
}
export async function customerList(opts: { page?: number; size?: number }) {
const global = getGlobalOpts();
const page = opts.page || 1;
const size = opts.size || 20;
const data = await apiRequest<PageResult<Customer>>(
'GET',
`/customers?page=${page}&size=${size}`,
);
if (global.json) {
printJson(data);
return;
}
if (!data.items.length) {
printEmptyHint('运行 ecom-license customer create 创建客户');
return;
}
printTable(
['ID', 'CODE', 'NAME', 'STATUS'],
data.items.map((c) => [
String(c.id),
c.code,
c.name,
c.status === 1 ? '启用' : '禁用',
]),
);
console.log(`共 ${data.total} 条 · 第 ${data.page}/${Math.ceil(data.total / data.size) || 1} 页`);
}
export async function customerCreate(opts: {
code?: string;
name?: string;
contactName?: string;
contactPhone?: string;
contactEmail?: string;
}) {
const global = getGlobalOpts();
let payload = { ...opts };
if (isInteractive() && !opts.name) {
payload.name = await input({ message: '公司名称', validate: (v) => !!v || '必填' });
payload.contactName = await input({ message: '联系人', default: '' });
payload.contactPhone = await input({ message: '联系电话', default: '' });
payload.contactEmail = await input({ message: '联系邮箱', default: '' });
payload.code = await input({ message: '客户编码(留空自动生成)', default: '' });
if (!payload.code) delete payload.code;
}
if (!payload.name) {
console.error('请提供 --name');
process.exit(1);
}
const created = await apiRequest<Customer>('POST', '/customers', payload);
if (global.json) printJson(created);
else if (global.quiet) printQuiet(String(created.id));
else printSuccess(`客户已创建: ${created.code} · ${created.name}`);
}
export async function customerShow(id: number) {
const global = getGlobalOpts();
const customer = await apiRequest<Customer>('GET', `/customers/${id}`);
if (global.json) printJson(customer);
else printJson(customer);
}
export async function customerDelete(id: number, yes?: boolean) {
const global = getGlobalOpts();
if (isInteractive() && !yes && !global.yes) {
const ok = await confirm({ message: `确认删除客户 #${id}?`, default: false });
if (!ok) return;
}
await apiRequest('DELETE', `/customers/${id}`);
printSuccess(`客户 #${id} 已删除`);
}
+257
View File
@@ -0,0 +1,257 @@
import { checkbox, confirm, input, search, select } from '@inquirer/prompts';
import { apiRequest, apiDownload } from '../api/client.js';
import { getGlobalOpts, isInteractive } from '../context.js';
import {
printBox,
printEmptyHint,
printJson,
printQuiet,
printSuccess,
printTable,
} from '../ui/render.js';
interface Customer {
id: number;
code: string;
name: string;
}
interface License {
id: number;
jti: string;
edition: string;
machineFingerprint: string;
status: string;
expiresAt: string;
licenseKey?: string;
customer?: Customer;
}
interface PageResult<T> {
items: T[];
total: number;
page: number;
size: number;
}
interface GenerateResult {
id: number;
licenseKey: string;
jti: string;
edition: string;
machineFingerprint: string;
expiresAt: string;
status: string;
}
export async function licenseList(opts: {
page?: number;
size?: number;
customerId?: number;
status?: string;
}) {
const global = getGlobalOpts();
const params = new URLSearchParams();
if (opts.page) params.set('page', String(opts.page));
if (opts.size) params.set('size', String(opts.size));
if (opts.customerId) params.set('customerId', String(opts.customerId));
if (opts.status) params.set('status', opts.status);
const data = await apiRequest<PageResult<License>>(
'GET',
`/licenses?${params.toString()}`,
);
if (global.json) {
printJson(data);
return;
}
if (!data.items.length) {
printEmptyHint('运行 ecom-license license generate 签发许可证');
return;
}
printTable(
['ID', 'JTI', 'EDITION', 'FINGERPRINT', 'STATUS', 'EXPIRES'],
data.items.map((l) => [
String(l.id),
l.jti.slice(0, 8) + '...',
l.edition,
l.machineFingerprint.slice(0, 16) + (l.machineFingerprint.length > 16 ? '...' : ''),
l.status,
l.expiresAt?.slice(0, 10) || '-',
]),
);
console.log(`共 ${data.total} 条`);
}
export async function licenseShow(id: number) {
const global = getGlobalOpts();
const license = await apiRequest<License>('GET', `/licenses/${id}`);
if (global.json) printJson(license);
else printJson(license);
}
export async function licenseGenerate(opts: {
customerId?: number;
company?: string;
fingerprint?: string;
edition?: string;
expires?: string;
features?: string;
}) {
const global = getGlobalOpts();
let customerId = opts.customerId;
let company = opts.company;
let fingerprint = opts.fingerprint;
let edition = opts.edition || 'enterprise';
let expiresAt = opts.expires;
let features = opts.features?.split(',').map((s) => s.trim()).filter(Boolean) || [
'order-import',
'order-create',
];
if (isInteractive() && !customerId) {
const customers = await apiRequest<PageResult<Customer>>('GET', '/customers?page=1&size=100');
if (!customers.items.length) {
console.error('暂无客户,请先 ecom-license customer create');
process.exit(1);
}
customerId = await search({
message: '选择客户',
source: async (term) => {
const q = (term || '').toLowerCase();
return customers.items
.filter(
(c) =>
!q ||
c.name.toLowerCase().includes(q) ||
c.code.toLowerCase().includes(q),
)
.map((c) => ({ name: `${c.code} · ${c.name}`, value: c.id }));
},
});
const picked = customers.items.find((c) => c.id === customerId)!;
company = await input({ message: '授权公司名', default: picked.name });
const fpMode = await select({
message: '机器指纹',
choices: [
{ name: '私有部署(输入 FP-xxx)', value: 'custom' },
{ name: 'SaaS 不限指纹 (*)', value: '*' },
],
});
fingerprint =
fpMode === '*'
? '*'
: await input({
message: '机器指纹',
validate: (v) => v.startsWith('FP-') || v === '*' || '格式应为 FP-...',
});
edition = await select({
message: '版本类型',
choices: [
{ name: 'trial · 试用', value: 'trial' },
{ name: 'enterprise · 企业', value: 'enterprise' },
{ name: 'unlimited · 无限', value: 'unlimited' },
],
});
const expireChoice = await select({
message: '有效期',
choices: [
{ name: '+30 天', value: '30d' },
{ name: '+1 年', value: '1y' },
{ name: '自定义日期', value: 'custom' },
],
});
if (expireChoice === 'custom') {
expiresAt = await input({
message: '过期日期 (YYYY-MM-DD)',
validate: (v) => /^\d{4}-\d{2}-\d{2}$/.test(v) || '格式 YYYY-MM-DD',
});
} else {
const d = new Date();
if (expireChoice === '30d') d.setDate(d.getDate() + 30);
else d.setFullYear(d.getFullYear() + 1);
expiresAt = d.toISOString().slice(0, 10);
}
features = await checkbox({
message: '授权功能',
choices: [
{ name: 'order-import · 订单导入', value: 'order-import', checked: true },
{ name: 'order-create · 创建订单', value: 'order-create', checked: true },
],
});
const summary = [
`客户 ID: ${customerId}`,
`公司: ${company}`,
`指纹: ${fingerprint}`,
`版本: ${edition}`,
`过期: ${expiresAt}`,
`功能: ${features.join(', ')}`,
].join('\n');
const ok = await confirm({ message: `确认签发?\n${summary}`, default: true });
if (!ok) return;
}
if (!customerId || !company || !fingerprint || !expiresAt) {
console.error('缺少参数,交互模式请直接运行 ecom-license license generate');
process.exit(1);
}
const result = await apiRequest<GenerateResult>('POST', '/licenses/generate', {
customerId,
company,
machineFingerprint: fingerprint,
edition,
expiresAt: new Date(expiresAt).toISOString(),
features,
});
if (global.json) {
printJson(result);
return;
}
if (global.quiet) {
printQuiet(result.licenseKey);
return;
}
printBox(
'签发成功',
[
`ID: ${result.id}`,
`JTI: ${result.jti}`,
`过期: ${result.expiresAt?.slice(0, 10)}`,
'',
result.licenseKey,
'',
'提示: 使用 --quiet 仅输出 licenseKey',
].join('\n'),
'green',
);
}
export async function licenseRevoke(id: number, yes?: boolean) {
const global = getGlobalOpts();
const license = await apiRequest<License>('GET', `/licenses/${id}`);
if (isInteractive() && !yes && !global.yes) {
const ok = await confirm({
message: `确认吊销?\nJTI: ${license.jti}\n指纹: ${license.machineFingerprint}`,
default: false,
});
if (!ok) return;
}
const result = await apiRequest('POST', `/licenses/${id}/revoke`);
if (global.json) printJson(result);
else printSuccess(`许可证 #${id} 已吊销`);
}
export async function licenseDownload(id: number, output?: string) {
const global = getGlobalOpts();
const outfile = output || `license-${id}.key`;
const path = await apiDownload(`/licenses/${id}/download`, outfile);
if (global.json) printJson({ path });
else if (global.quiet) printQuiet(path);
else printSuccess(`已保存到 ${path}`);
}
+63
View File
@@ -0,0 +1,63 @@
import { input, password } from '@inquirer/prompts';
import { apiRequest } from '../api/client.js';
import { loadConfig, resolveApiUrl, saveConfig } from '../config.js';
import { getGlobalOpts, isInteractive } from '../context.js';
import { printBanner, printError, printJson, printSuccess } from '../ui/render.js';
interface LoginResult {
token: string;
username: string;
expiresAt: string | null;
}
export async function loginCommand(opts: {
url?: string;
username?: string;
password?: string;
}) {
const global = getGlobalOpts();
const config = await loadConfig();
const apiUrl = resolveApiUrl(opts.url || global.url, config);
if (isInteractive()) printBanner();
let username = opts.username || process.env.ECOM_LICENSE_USERNAME;
let pass = opts.password || process.env.ECOM_LICENSE_PASSWORD;
if (isInteractive()) {
username = await input({ message: '用户名', default: username || 'admin' });
pass = await password({ message: '密码', mask: '*' });
}
if (!username || !pass) {
printError('请提供用户名和密码');
process.exit(1);
}
try {
const result = await apiRequest<LoginResult>(
'POST',
'/auth/login',
{ username, password: pass },
false,
);
await saveConfig({
apiUrl,
token: result.token,
username: result.username,
expiresAt: result.expiresAt || undefined,
});
if (global.json) {
printJson({ username: result.username, expiresAt: result.expiresAt, apiUrl });
return;
}
printSuccess(
`登录成功 · ${result.username}` +
(result.expiresAt ? ` · Token 有效期至 ${result.expiresAt.slice(0, 10)}` : ''),
);
} catch (e: any) {
printError(e?.message || '登录失败');
process.exit(1);
}
}
+7
View File
@@ -0,0 +1,7 @@
import { clearConfig } from '../config.js';
import { printSuccess } from '../ui/render.js';
export async function logoutCommand() {
await clearConfig();
printSuccess('已退出登录');
}
+35
View File
@@ -0,0 +1,35 @@
import { apiRequest } from '../api/client.js';
import { getGlobalOpts } from '../context.js';
import { printBox, printJson, printQuiet } from '../ui/render.js';
interface Stats {
customerCount: number;
activeLicenseCount: number;
expiringSoonCount: number;
totalLicenses: number;
}
export async function statsCommand() {
const global = getGlobalOpts();
const stats = await apiRequest<Stats>('GET', '/dashboard/stats');
if (global.json) {
printJson(stats);
return;
}
if (global.quiet) {
printQuiet(String(stats.activeLicenseCount));
return;
}
printBox(
'平台概览',
[
`客户数: ${stats.customerCount}`,
`有效许可证: ${stats.activeLicenseCount}`,
`即将过期: ${stats.expiringSoonCount}`,
`许可证总数: ${stats.totalLicenses}`,
].join('\n'),
'green',
);
}
+39
View File
@@ -0,0 +1,39 @@
import { loadConfig, resolveApiUrl } from '../config.js';
import { getGlobalOpts } from '../context.js';
import { printBox, printError, printJson, printQuiet } from '../ui/render.js';
export async function whoamiCommand() {
const global = getGlobalOpts();
const config = await loadConfig();
const apiUrl = resolveApiUrl(global.url, config);
if (!config?.token && !global.token) {
printError('未登录,请运行: ecom-license login');
process.exit(1);
}
const info = {
apiUrl,
username: config?.username,
expiresAt: config?.expiresAt,
loggedIn: Boolean(config?.token || global.token),
};
if (global.json) {
printJson(info);
return;
}
if (global.quiet) {
printQuiet(config?.username || '');
return;
}
printBox(
'当前会话',
[
`API: ${apiUrl}`,
`用户: ${config?.username || '(未知)'}`,
`过期: ${config?.expiresAt || '-'}`,
].join('\n'),
);
}
+53
View File
@@ -0,0 +1,53 @@
import { mkdir, readFile, writeFile } from 'fs/promises';
import { homedir } from 'os';
import { dirname, join } from 'path';
export interface CliConfig {
apiUrl: string;
token?: string;
username?: string;
expiresAt?: string;
}
const DEFAULT_CONFIG_PATH = join(
homedir(),
'.config',
'ecom-license',
'config.json',
);
export function getConfigPath(): string {
return process.env.ECOM_LICENSE_CONFIG || DEFAULT_CONFIG_PATH;
}
export async function loadConfig(): Promise<CliConfig | null> {
try {
const raw = await readFile(getConfigPath(), 'utf8');
return JSON.parse(raw) as CliConfig;
} catch {
return null;
}
}
export async function saveConfig(config: CliConfig): Promise<void> {
const path = getConfigPath();
await mkdir(dirname(path), { recursive: true });
await writeFile(path, JSON.stringify(config, null, 2), 'utf8');
}
export async function clearConfig(): Promise<void> {
await saveConfig({ apiUrl: (await loadConfig())?.apiUrl || 'http://localhost:3100' });
}
export function resolveApiUrl(flagUrl?: string, config?: CliConfig | null): string {
return (
flagUrl ||
process.env.ECOM_LICENSE_API_URL ||
config?.apiUrl ||
'http://localhost:3100'
).replace(/\/$/, '');
}
export function resolveToken(flagToken?: string, config?: CliConfig | null): string | undefined {
return flagToken || process.env.ECOM_LICENSE_TOKEN || config?.token;
}
+30
View File
@@ -0,0 +1,30 @@
/** 全局 CLI 运行上下文(由 commander 注入) */
export interface GlobalOpts {
url?: string;
token?: string;
json?: boolean;
quiet?: boolean;
yes?: boolean;
verbose?: boolean;
}
let globalOpts: GlobalOpts = {};
export function setGlobalOpts(opts: GlobalOpts) {
globalOpts = opts;
}
export function getGlobalOpts(): GlobalOpts {
return globalOpts;
}
/** TTY 交互模式检测 */
export function isInteractive(): boolean {
const opts = getGlobalOpts();
return (
Boolean(process.stdout.isTTY) &&
!process.env.CI &&
!opts.json &&
!opts.quiet
);
}
+118
View File
@@ -0,0 +1,118 @@
#!/usr/bin/env node
import { Command } from 'commander';
import { customerCreate, customerDelete, customerList, customerShow } from './commands/customer.js';
import { licenseDownload, licenseGenerate, licenseList, licenseRevoke, licenseShow } from './commands/license.js';
import { loginCommand } from './commands/login.js';
import { logoutCommand } from './commands/logout.js';
import { statsCommand } from './commands/stats.js';
import { whoamiCommand } from './commands/whoami.js';
import { setGlobalOpts } from './context.js';
import { printBanner } from './ui/render.js';
function applyGlobals(cmd: Command) {
return cmd
.option('--url <base>', 'API 根地址')
.option('--token <jwt>', 'Bearer Token')
.option('--json', 'JSON 输出')
.option('--quiet', '仅输出关键值')
.option('--yes', '跳过确认')
.option('--verbose', '显示详细错误')
.hook('preAction', (thisCmd) => {
const root = thisCmd.optsWithGlobals();
setGlobalOpts({
url: root.url,
token: root.token,
json: root.json,
quiet: root.quiet,
yes: root.yes,
verbose: root.verbose,
});
});
}
const program = new Command();
program.name('ecom-license').description('Ecom-DMB License 运营管理 CLI').version('0.1.0');
applyGlobals(program);
program
.command('login')
.description('登录 License 平台')
.option('--username <name>')
.option('--password <pwd>')
.action((opts, cmd) => loginCommand({ ...opts, url: cmd.optsWithGlobals().url }));
program.command('logout').description('退出登录').action(logoutCommand);
program.command('whoami').description('查看当前登录状态').action(whoamiCommand);
program.command('stats').description('平台统计').action(statsCommand);
const customer = program.command('customer').description('客户管理');
applyGlobals(customer);
customer.command('list').option('--page <n>').option('--size <n>').action((opts) =>
customerList({ page: Number(opts.page) || 1, size: Number(opts.size) || 20 }),
);
customer
.command('create')
.option('--code <code>')
.option('--name <name>')
.option('--contact-name <n>')
.option('--contact-phone <p>')
.option('--contact-email <e>')
.action((opts) => customerCreate(opts));
customer.command('show <id>').action((id) => customerShow(Number(id)));
customer.command('delete <id>').action((id, opts, cmd) =>
customerDelete(Number(id), cmd.optsWithGlobals().yes),
);
const license = program.command('license').description('许可证管理');
applyGlobals(license);
license
.command('list')
.option('--page <n>')
.option('--size <n>')
.option('--customer-id <id>')
.option('--status <s>')
.action((opts) =>
licenseList({
page: Number(opts.page) || 1,
size: Number(opts.size) || 20,
customerId: opts.customerId ? Number(opts.customerId) : undefined,
status: opts.status,
}),
);
license.command('show <id>').action((id) => licenseShow(Number(id)));
license
.command('generate')
.option('--customer-id <id>')
.option('--company <name>')
.option('--fingerprint <fp>')
.option('--edition <e>')
.option('--expires <date>')
.option('--features <list>')
.action((opts) => licenseGenerate(opts));
license.command('revoke <id>').action((id, _o, cmd) =>
licenseRevoke(Number(id), cmd.optsWithGlobals().yes),
);
license
.command('download <id>')
.option('-o, --output <file>')
.action((id, opts) => licenseDownload(Number(id), opts.output));
// 无子命令时只展示引导,不输出冗长 --help
program.action(() => {
printBanner();
console.log('常用命令:');
console.log(' pnpm dev login # 开发模式登录');
console.log(' pnpm dev customer create # 创建客户');
console.log(' pnpm dev license generate # 签发 License');
console.log(' pnpm start login # 使用构建产物');
console.log('');
console.log('完整帮助: pnpm dev -- --help');
});
program.parseAsync(process.argv).catch((err) => {
if (err?.name === 'ExitPromptError') process.exit(0);
console.error(err?.message || err);
process.exit(1);
});
+100
View File
@@ -0,0 +1,100 @@
import boxen from 'boxen';
import chalk from 'chalk';
import Table from 'cli-table3';
import gradient from 'gradient-string';
import ora, { type Ora } from 'ora';
import { getGlobalOpts, isInteractive } from '../context.js';
export function printBanner() {
if (!isInteractive()) return;
const title = gradient.pastel('Ecom License CLI');
console.log(
boxen(`${title}\n${chalk.gray('授权管理平台 · 运营端')}`, {
padding: 1,
borderColor: 'cyan',
borderStyle: 'round',
}),
);
}
export function printJson(data: unknown) {
console.log(JSON.stringify(data, null, getGlobalOpts().json ? 2 : 0));
}
export function printQuiet(value: string) {
console.log(value);
}
export function printSuccess(msg: string) {
if (getGlobalOpts().json || getGlobalOpts().quiet) return;
console.log(chalk.green('✔'), msg);
}
export function printError(msg: string) {
if (getGlobalOpts().json) {
printJson({ error: msg });
return;
}
console.error(chalk.red('✖'), msg);
}
export function printInfo(msg: string) {
if (getGlobalOpts().json || getGlobalOpts().quiet) return;
console.log(chalk.blue('ℹ'), msg);
}
export function printBox(title: string, content: string, borderColor: 'green' | 'cyan' | 'yellow' = 'cyan') {
if (!isInteractive()) return;
console.log(
boxen(content, {
title: chalk.bold(title),
padding: 1,
borderColor,
}),
);
}
export function printTable(headers: string[], rows: string[][]) {
if (getGlobalOpts().json) {
printJson(
rows.map((row) =>
Object.fromEntries(headers.map((h, i) => [h, row[i]])),
),
);
return;
}
if (getGlobalOpts().quiet) return;
const table = new Table({ head: headers.map((h) => chalk.cyan(h)) });
rows.forEach((r) => table.push(r));
console.log(table.toString());
}
export function printEmptyHint(hint: string) {
if (getGlobalOpts().json || getGlobalOpts().quiet) return;
console.log(chalk.yellow('暂无数据。'), chalk.gray(hint));
}
let activeSpinner: Ora | null = null;
export async function runSpinner<T>(fn: () => Promise<T>, text: string): Promise<T> {
const spinner = ora(text).start();
activeSpinner = spinner;
try {
const result = await fn();
spinner.succeed();
return result;
} catch (e) {
spinner.fail();
throw e;
} finally {
activeSpinner = null;
}
}
export function failSpinner(msg: string) {
if (activeSpinner) {
activeSpinner.fail(msg);
activeSpinner = null;
}
}
+14
View File
@@ -0,0 +1,14 @@
{
"compilerOptions": {
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"outDir": "./dist",
"rootDir": "./src",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"declaration": false
},
"include": ["src/**/*"]
}