@optima-chat/commerce-cli 1.0.0 → 1.1.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/.claude/skills/commerce-cli/SKILL.md +177 -0
- package/README.md +28 -49
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +29 -67
- package/dist/commands/init.js.map +1 -1
- package/dist/postinstall.js +6 -91
- package/dist/postinstall.js.map +1 -1
- package/dist/preuninstall.d.ts +0 -1
- package/dist/preuninstall.js +3 -51
- package/dist/preuninstall.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: commerce-cli
|
|
3
|
+
description: E-commerce store management CLI with 16 modules and 95+ commands. Manage products, orders, inventory, shipping, collections, i18n translations, and homepage configuration. Use when the user needs to create/update/delete products, process orders, manage inventory, configure shipping, or handle multilingual translations for their e-commerce store.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Commerce CLI - 电商店铺管理工具
|
|
7
|
+
|
|
8
|
+
## Overview
|
|
9
|
+
|
|
10
|
+
Commerce CLI 是专为 Claude Code 设计的对话式电商管理工具,支持用自然语言管理店铺。
|
|
11
|
+
|
|
12
|
+
**版本**: v1.0.0
|
|
13
|
+
**安装**: `npm install -g @optima-chat/commerce-cli@latest`
|
|
14
|
+
|
|
15
|
+
## Instructions
|
|
16
|
+
|
|
17
|
+
### 1. 认证流程
|
|
18
|
+
|
|
19
|
+
首次使用需要登录:
|
|
20
|
+
```bash
|
|
21
|
+
commerce auth login # 生产环境
|
|
22
|
+
commerce auth login --env stage # Stage 环境
|
|
23
|
+
commerce auth login --env development # 开发环境
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### 2. 自然语言映射
|
|
27
|
+
|
|
28
|
+
当用户说:
|
|
29
|
+
- "创建XX商品,价格YY" → `commerce product create --title XX --price YY`
|
|
30
|
+
- "查看今天的订单" → `commerce order list`
|
|
31
|
+
- "订单XX发货,快递单号YY" → `commerce order ship --id XX --tracking YY`
|
|
32
|
+
- "库存低于5的商品" → `commerce inventory low-stock --threshold 5`
|
|
33
|
+
- "给商品添加中文翻译" → `commerce i18n product create --product-id XX --lang zh-CN`
|
|
34
|
+
|
|
35
|
+
### 3. 功能模块
|
|
36
|
+
|
|
37
|
+
**16 个核心模块**:
|
|
38
|
+
- `auth` - OAuth 认证管理
|
|
39
|
+
- `merchant` - 商户资料管理
|
|
40
|
+
- `product` - 商品目录管理(支持标签)
|
|
41
|
+
- `variant` - 商品变体/SKU 管理
|
|
42
|
+
- `order` - 订单履行
|
|
43
|
+
- `refund` - 退款管理
|
|
44
|
+
- `inventory` - 库存管理
|
|
45
|
+
- `homepage` - 首页配置
|
|
46
|
+
- `collection` - 集合管理
|
|
47
|
+
- `shipping` - 物流管理
|
|
48
|
+
- `shipping-zone` - 运费区域配置
|
|
49
|
+
- `upload` - 媒体文件上传
|
|
50
|
+
- `conversation` - 客服对话
|
|
51
|
+
- `transfer` - 财务管理
|
|
52
|
+
- `i18n` - 多语言翻译(24个子命令)
|
|
53
|
+
- `test` - 健康检查和测试
|
|
54
|
+
|
|
55
|
+
### 4. 最佳实践
|
|
56
|
+
|
|
57
|
+
**环境管理**:
|
|
58
|
+
- 支持 Production/Stage/Development 三环境
|
|
59
|
+
- 配置文件位置:`~/.config/commerce-cli/`
|
|
60
|
+
- 环境切换:`commerce auth switch --env stage`
|
|
61
|
+
|
|
62
|
+
**非交互模式**:
|
|
63
|
+
- AI/CI 环境自动检测,缺少参数立即报错
|
|
64
|
+
- 删除操作需要 `--yes` 标志
|
|
65
|
+
|
|
66
|
+
**i18n 参数区分**:
|
|
67
|
+
- 变体翻译使用 `--variant-id`(不是 `--product-id`)
|
|
68
|
+
- 集合翻译使用 `--collection-id`
|
|
69
|
+
- 首页区块翻译使用 `--section-id`
|
|
70
|
+
|
|
71
|
+
**图片上传**:
|
|
72
|
+
- 先上传:`commerce upload image --path ./photo.jpg`
|
|
73
|
+
- 获取 `media_id`
|
|
74
|
+
- 再关联:`commerce product add-images --id prod_123 --media-id media_456`
|
|
75
|
+
|
|
76
|
+
## Examples
|
|
77
|
+
|
|
78
|
+
### 商品管理
|
|
79
|
+
```bash
|
|
80
|
+
# 用户说:"创建T恤商品,99美元,库存20,标签是featured和new"
|
|
81
|
+
commerce product create \
|
|
82
|
+
--title "T恤" \
|
|
83
|
+
--price 99 \
|
|
84
|
+
--stock 20 \
|
|
85
|
+
--tags "featured,new"
|
|
86
|
+
|
|
87
|
+
# 用户说:"查看所有featured标签的商品"
|
|
88
|
+
commerce product list --tags "featured"
|
|
89
|
+
|
|
90
|
+
# 用户说:"商品prod_123改价到129"
|
|
91
|
+
commerce product update --id prod_123 --price 129
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### 订单履行
|
|
95
|
+
```bash
|
|
96
|
+
# 用户说:"查看待发货订单"
|
|
97
|
+
commerce order list --status paid
|
|
98
|
+
|
|
99
|
+
# 用户说:"订单order_123发货,快递单号DHL123456,承运商DHL"
|
|
100
|
+
commerce order ship \
|
|
101
|
+
--id order_123 \
|
|
102
|
+
--tracking DHL123456 \
|
|
103
|
+
--carrier DHL
|
|
104
|
+
|
|
105
|
+
# 用户说:"取消订单order_456,原因是客户要求"
|
|
106
|
+
commerce order cancel \
|
|
107
|
+
--id order_456 \
|
|
108
|
+
--reason "客户要求取消" \
|
|
109
|
+
--yes
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### 库存管理
|
|
113
|
+
```bash
|
|
114
|
+
# 用户说:"查看库存低于10的商品"
|
|
115
|
+
commerce inventory low-stock --threshold 10
|
|
116
|
+
|
|
117
|
+
# 用户说:"商品prod_123补货50个"
|
|
118
|
+
commerce inventory update \
|
|
119
|
+
--id prod_123 \
|
|
120
|
+
--quantity 50 \
|
|
121
|
+
--reason "补货"
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### 多语言翻译
|
|
125
|
+
```bash
|
|
126
|
+
# 用户说:"给商品prod_123添加中文翻译,名称是手工陶瓷杯"
|
|
127
|
+
commerce i18n product create \
|
|
128
|
+
--product-id prod_123 \
|
|
129
|
+
--lang zh-CN \
|
|
130
|
+
--name "手工陶瓷杯" \
|
|
131
|
+
--description "精美的手工制作陶瓷杯"
|
|
132
|
+
|
|
133
|
+
# 用户说:"给变体var_456添加日语翻译"
|
|
134
|
+
commerce i18n variant create \
|
|
135
|
+
--variant-id var_456 \
|
|
136
|
+
--lang ja-JP \
|
|
137
|
+
--name "セラミックマグ"
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### 首页配置
|
|
141
|
+
```bash
|
|
142
|
+
# 用户说:"创建首页轮播图模块"
|
|
143
|
+
commerce homepage module create \
|
|
144
|
+
--slug hero-banner \
|
|
145
|
+
--type banner \
|
|
146
|
+
--position 1 \
|
|
147
|
+
--enabled true \
|
|
148
|
+
--config '{"images":[{"url":"https://example.com/banner.jpg"}]}'
|
|
149
|
+
|
|
150
|
+
# 用户说:"更新首页设置,启用搜索功能"
|
|
151
|
+
commerce homepage settings update \
|
|
152
|
+
--show-search true \
|
|
153
|
+
--featured-limit 8
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### 集合管理
|
|
157
|
+
```bash
|
|
158
|
+
# 用户说:"创建夏季促销集合"
|
|
159
|
+
commerce collection create \
|
|
160
|
+
--name "Summer Sale" \
|
|
161
|
+
--slug summer-sale \
|
|
162
|
+
--description "Hot deals for summer"
|
|
163
|
+
|
|
164
|
+
# 用户说:"把商品prod_123和prod_456添加到集合summer-sale"
|
|
165
|
+
commerce collection add-products \
|
|
166
|
+
--slug summer-sale \
|
|
167
|
+
--product-ids prod_123,prod_456
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## Notes
|
|
171
|
+
|
|
172
|
+
- 所有命令默认输出 JSON 格式(AI 友好)
|
|
173
|
+
- 使用 `--pretty` 参数可切换到人类可读的表格格式
|
|
174
|
+
- 环境变量 `OPTIMA_TOKEN` 可用于非交互认证(CI/CD)
|
|
175
|
+
- 支持的语言:en-US, es-ES, ja-JP, vi-VN, zh-CN
|
|
176
|
+
- 使用 `commerce <command> --help` 查看详细用法
|
|
177
|
+
- 项目仓库:https://github.com/Optima-Chat/commerce-cli
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<div align="center">
|
|
2
2
|
|
|
3
|
-
# ⚡️
|
|
3
|
+
# ⚡️ Commerce CLI
|
|
4
4
|
|
|
5
5
|
### 用自然语言管理你的电商店铺
|
|
6
6
|
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
[](https://www.typescriptlang.org/)
|
|
13
13
|
[](https://nodejs.org/)
|
|
14
14
|
|
|
15
|
-
[网站](https://cli.optima.shop) • [文档](https://github.com/Optima-Chat/
|
|
15
|
+
[网站](https://cli.optima.shop) • [文档](https://github.com/Optima-Chat/commerce-cli#readme) • [NPM](https://www.npmjs.com/package/@optima-chat/commerce-cli) • [问题反馈](https://github.com/Optima-Chat/commerce-cli/issues)
|
|
16
16
|
|
|
17
17
|
</div>
|
|
18
18
|
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
|
|
21
21
|
## 🎯 简介
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
Commerce CLI 是 [Optima Commerce](https://www.optima.shop) 生态的命令行工具,**专为 Claude Code 设计**。
|
|
24
24
|
|
|
25
25
|
无需记住命令 - 直接用中文对话,Claude 会自动调用相应的 CLI 命令来管理你的电商店铺。
|
|
26
26
|
|
|
@@ -28,14 +28,14 @@ Optima CLI 是 [Optima Commerce](https://www.optima.shop) 生态的命令行工
|
|
|
28
28
|
# 传统方式(需要记住命令)
|
|
29
29
|
commerce product create --title "陶瓷杯" --price 89 --stock 20
|
|
30
30
|
|
|
31
|
-
#
|
|
31
|
+
# Commerce CLI + Claude Code(自然语言)
|
|
32
32
|
"创建陶瓷杯商品,89 美元,库存 20" ✨
|
|
33
33
|
```
|
|
34
34
|
|
|
35
35
|
## 🎬 演示
|
|
36
36
|
|
|
37
37
|
### Claude Code 自然语言交互
|
|
38
|
-
> 这是
|
|
38
|
+
> 这是 Commerce CLI 最强大的功能 - 用自然语言管理电商店铺
|
|
39
39
|
|
|
40
40
|
<!--
|
|
41
41
|
TODO: 录制演示 GIF 后取消注释
|
|
@@ -85,10 +85,10 @@ TODO: 录制商品管理演示 GIF
|
|
|
85
85
|
npm install -g @optima-chat/commerce-cli@latest
|
|
86
86
|
```
|
|
87
87
|
|
|
88
|
-
安装完成后会自动配置 Claude
|
|
88
|
+
安装完成后会自动配置 Claude Skills,Claude 可以根据你的自然语言需求自动发现并使用 Commerce CLI。如需在特定项目中启用,对 Claude 说:
|
|
89
89
|
|
|
90
90
|
```
|
|
91
|
-
"在这个项目启用
|
|
91
|
+
"在这个项目启用 Commerce CLI"
|
|
92
92
|
```
|
|
93
93
|
|
|
94
94
|
### 2. 登录你的账号
|
|
@@ -116,13 +116,13 @@ Claude 会自动打开浏览器引导你完成 OAuth 授权。
|
|
|
116
116
|
- "给商品添加中文翻译"
|
|
117
117
|
```
|
|
118
118
|
|
|
119
|
-
Claude 会自动调用对应的 `
|
|
119
|
+
Claude 会自动调用对应的 `commerce` 命令来完成操作。
|
|
120
120
|
|
|
121
121
|
**就是这么简单!** 🎉
|
|
122
122
|
|
|
123
123
|
## 📦 功能模块
|
|
124
124
|
|
|
125
|
-
|
|
125
|
+
Commerce CLI 提供 **16 个功能模块**,**95+ 个命令**,覆盖电商全流程:
|
|
126
126
|
|
|
127
127
|
| 模块 | 命令数 | 说明 |
|
|
128
128
|
|------|--------|------|
|
|
@@ -145,7 +145,7 @@ Optima CLI 提供 **16 个功能模块**,**95+ 个命令**,覆盖电商全
|
|
|
145
145
|
|
|
146
146
|
## 🎨 输出格式
|
|
147
147
|
|
|
148
|
-
|
|
148
|
+
Commerce CLI 支持两种输出格式,适用于不同场景:
|
|
149
149
|
|
|
150
150
|
### JSON 模式(默认,AI 友好)
|
|
151
151
|
|
|
@@ -226,11 +226,11 @@ $ commerce merchant info --pretty
|
|
|
226
226
|
|
|
227
227
|
## 🤖 非交互模式 / CI/CD
|
|
228
228
|
|
|
229
|
-
**v0.16.0 新增**:
|
|
229
|
+
**v0.16.0 新增**:Commerce CLI 现在支持智能环境检测,自动适配终端用户和 AI/CI/CD 环境!
|
|
230
230
|
|
|
231
231
|
### 🎯 自动环境检测
|
|
232
232
|
|
|
233
|
-
|
|
233
|
+
Commerce CLI 自动检测运行环境,无需手动配置:
|
|
234
234
|
|
|
235
235
|
| 环境 | 行为 | 示例 |
|
|
236
236
|
|------|------|------|
|
|
@@ -272,7 +272,7 @@ jobs:
|
|
|
272
272
|
steps:
|
|
273
273
|
- uses: actions/checkout@v3
|
|
274
274
|
|
|
275
|
-
- name: Install
|
|
275
|
+
- name: Install Commerce CLI
|
|
276
276
|
run: npm install -g @optima-chat/commerce-cli
|
|
277
277
|
|
|
278
278
|
- name: Create Products
|
|
@@ -316,12 +316,12 @@ FROM node:18-alpine
|
|
|
316
316
|
RUN npm install -g @optima-chat/commerce-cli
|
|
317
317
|
|
|
318
318
|
# 非交互环境,需提供所有参数
|
|
319
|
-
CMD ["
|
|
319
|
+
CMD ["commerce", "product", "list", "--json"]
|
|
320
320
|
```
|
|
321
321
|
|
|
322
322
|
```bash
|
|
323
323
|
# 运行容器
|
|
324
|
-
docker run -e OPTIMA_TOKEN=$OPTIMA_TOKEN
|
|
324
|
+
docker run -e OPTIMA_TOKEN=$OPTIMA_TOKEN commerce-cli
|
|
325
325
|
```
|
|
326
326
|
|
|
327
327
|
### ✅ 确认操作(`--yes` 标志)
|
|
@@ -381,7 +381,7 @@ commerce auth logout --all # 登出所有环境
|
|
|
381
381
|
|
|
382
382
|
**多环境支持**(v0.19.0+):
|
|
383
383
|
|
|
384
|
-
|
|
384
|
+
Commerce CLI 支持三个独立环境,各自拥有独立的配置文件:
|
|
385
385
|
|
|
386
386
|
| 环境 | Auth API | Commerce API | 前端域名 | 配置文件 |
|
|
387
387
|
|------|----------|--------------|---------|----------|
|
|
@@ -389,7 +389,7 @@ Optima CLI 支持三个独立环境,各自拥有独立的配置文件:
|
|
|
389
389
|
| **Stage** | **auth-stage.optima.shop** | **api-stage.optima.shop** | **stage.optima.shop** | **config-stage.json** |
|
|
390
390
|
| Development | auth.optima.chat | api.optima.chat | optima.sh | config-dev.json |
|
|
391
391
|
|
|
392
|
-
**配置文件位置**:`~/.config/
|
|
392
|
+
**配置文件位置**:`~/.config/commerce-cli/`
|
|
393
393
|
|
|
394
394
|
```bash
|
|
395
395
|
# 登录到不同环境
|
|
@@ -416,14 +416,14 @@ export OPTIMA_TOKEN=<your_access_token>
|
|
|
416
416
|
commerce product list
|
|
417
417
|
|
|
418
418
|
# Docker 容器
|
|
419
|
-
docker run -e OPTIMA_TOKEN=<your_token>
|
|
419
|
+
docker run -e OPTIMA_TOKEN=<your_token> commerce-cli product list
|
|
420
420
|
|
|
421
421
|
# CI/CD 流水线
|
|
422
422
|
export OPTIMA_TOKEN=${{ secrets.OPTIMA_TOKEN }}
|
|
423
423
|
commerce product create --title "商品"
|
|
424
424
|
```
|
|
425
425
|
|
|
426
|
-
**认证优先级**:`OPTIMA_TOKEN` 环境变量 > 配置文件(`~/.config/
|
|
426
|
+
**认证优先级**:`OPTIMA_TOKEN` 环境变量 > 配置文件(`~/.config/commerce-cli`)
|
|
427
427
|
|
|
428
428
|
**自定义 Backend 地址**(适用于开发/测试环境):
|
|
429
429
|
|
|
@@ -440,7 +440,7 @@ commerce auth login
|
|
|
440
440
|
docker run \
|
|
441
441
|
-e OPTIMA_TOKEN=<your_token> \
|
|
442
442
|
-e OPTIMA_API_URL=http://host.docker.internal:8000 \
|
|
443
|
-
|
|
443
|
+
commerce-cli product list
|
|
444
444
|
```
|
|
445
445
|
|
|
446
446
|
**默认 Backend**:
|
|
@@ -800,7 +800,7 @@ commerce transfer summary # 财务汇总
|
|
|
800
800
|
|
|
801
801
|
### 🌐 国际化翻译
|
|
802
802
|
|
|
803
|
-
|
|
803
|
+
Commerce CLI 内置完整的多语言翻译管理系统:
|
|
804
804
|
|
|
805
805
|
```bash
|
|
806
806
|
# 语言管理
|
|
@@ -868,7 +868,7 @@ commerce i18n collection create --collection-id coll_789 \
|
|
|
868
868
|
|
|
869
869
|
### 🧪 测试工具
|
|
870
870
|
|
|
871
|
-
|
|
871
|
+
Commerce CLI 内置测试工具,可用作功能测试和 API 健康检查:
|
|
872
872
|
|
|
873
873
|
```bash
|
|
874
874
|
# 健康检查(检查 API 连通性和响应时间)
|
|
@@ -1020,14 +1020,14 @@ $ commerce test smoke
|
|
|
1020
1020
|
## 🛠 工具命令
|
|
1021
1021
|
|
|
1022
1022
|
```bash
|
|
1023
|
-
commerce init # 在当前项目启用
|
|
1023
|
+
commerce init # 在当前项目启用 Commerce CLI(创建 Claude Skill)
|
|
1024
1024
|
commerce cleanup # 清理配置文件
|
|
1025
1025
|
commerce version # 显示版本信息
|
|
1026
1026
|
```
|
|
1027
1027
|
|
|
1028
1028
|
## 🏗 项目状态
|
|
1029
1029
|
|
|
1030
|
-
**当前版本:
|
|
1030
|
+
**当前版本:v1.0.0** 🎉
|
|
1031
1031
|
|
|
1032
1032
|
✅ **已完成功能**:
|
|
1033
1033
|
- ✅ 完整的 OAuth 2.0 认证系统(Device Flow + 自动刷新)
|
|
@@ -1048,33 +1048,12 @@ commerce version # 显示版本信息
|
|
|
1048
1048
|
|
|
1049
1049
|
**功能覆盖率**:100%(所有核心商户运营功能 + 测试工具)
|
|
1050
1050
|
|
|
1051
|
-
**最近更新**:
|
|
1052
|
-
|
|
1053
|
-
**v0.19.0**(2025-11-13):
|
|
1054
|
-
- 🌐 **三环境架构**:新增 Stage 环境,支持 Production/Stage/Development 完全隔离
|
|
1055
|
-
- 🔐 **多文件配置**:每个环境独立配置文件(config-prod.json, config-stage.json, config-dev.json)
|
|
1056
|
-
- 🔄 **环境切换命令**:新增 `auth switch` 命令,无需重新登录即可切换环境
|
|
1057
|
-
- 🧪 **测试模块**:新增 `test health` 和 `test smoke` 命令
|
|
1058
|
-
- 📜 **E2E 测试脚本**:`scripts/e2e-test.sh` 用于 CI/CD 集成
|
|
1059
|
-
- 🛠️ **认证命令增强**:`whoami` 显示环境信息,`logout` 支持 `--env` 和 `--all`
|
|
1060
|
-
- 📚 **完整文档更新**:CLAUDE.md 和 README.md 包含所有新功能
|
|
1061
|
-
|
|
1062
|
-
**v0.18.1**(2025-11-11):
|
|
1063
|
-
- 🐛 修复:开发环境店铺域名使用正确的 `optima.sh`
|
|
1064
|
-
- 🛠️ 优化:统一店铺域名管理,自动根据环境选择
|
|
1065
|
-
|
|
1066
|
-
**v0.18.0**(2025-11-11):
|
|
1067
|
-
- 🌍 新增:环境支持(`--env development` 参数)
|
|
1068
|
-
- 🔐 支持生产和开发环境切换
|
|
1069
|
-
- 🎯 自动选择对应的 OAuth Client ID 和 API 端点
|
|
1070
|
-
- 🔄 环境配置持久化
|
|
1071
|
-
|
|
1072
1051
|
## 🔧 开发
|
|
1073
1052
|
|
|
1074
1053
|
```bash
|
|
1075
1054
|
# 克隆仓库
|
|
1076
|
-
git clone https://github.com/Optima-Chat/
|
|
1077
|
-
cd
|
|
1055
|
+
git clone https://github.com/Optima-Chat/commerce-cli.git
|
|
1056
|
+
cd commerce-cli
|
|
1078
1057
|
|
|
1079
1058
|
# 安装依赖
|
|
1080
1059
|
npm install
|
|
@@ -1117,13 +1096,13 @@ git push --follow-tags # 推送触发自动发布
|
|
|
1117
1096
|
- [Optima Store](https://go.optima.shop) - 买家购物前端
|
|
1118
1097
|
- [Claude Code](https://claude.com/claude-code)
|
|
1119
1098
|
- [NPM Package](https://www.npmjs.com/package/@optima-chat/commerce-cli)
|
|
1120
|
-
- [GitHub Issues](https://github.com/Optima-Chat/
|
|
1099
|
+
- [GitHub Issues](https://github.com/Optima-Chat/commerce-cli/issues)
|
|
1121
1100
|
|
|
1122
1101
|
## 💬 支持
|
|
1123
1102
|
|
|
1124
1103
|
遇到问题?
|
|
1125
1104
|
|
|
1126
|
-
- 提交 [Issue](https://github.com/Optima-Chat/
|
|
1105
|
+
- 提交 [Issue](https://github.com/Optima-Chat/commerce-cli/issues)
|
|
1127
1106
|
- 查看 [完整命令列表](.claude/CLAUDE.md)
|
|
1128
1107
|
- 联系团队:support@optima.chat
|
|
1129
1108
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAkEpC,eAAO,MAAM,WAAW,SAAM,CAAC"}
|
package/dist/commands/init.js
CHANGED
|
@@ -3,95 +3,57 @@ import chalk from 'chalk';
|
|
|
3
3
|
import fs from 'fs';
|
|
4
4
|
import path from 'path';
|
|
5
5
|
import { fileURLToPath } from 'url';
|
|
6
|
+
import { addEnhancedHelp } from '../utils/helpText.js';
|
|
6
7
|
const __filename = fileURLToPath(import.meta.url);
|
|
7
8
|
const __dirname = path.dirname(__filename);
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
// 从 NPM 包内读取模板内容
|
|
12
|
-
const TEMPLATE_CLAUDE_MD = path.join(__dirname, '..', '..', '.claude', 'CLAUDE.md');
|
|
13
|
-
function getOptimaSection() {
|
|
14
|
-
try {
|
|
15
|
-
const templateContent = fs.readFileSync(TEMPLATE_CLAUDE_MD, 'utf-8');
|
|
16
|
-
const match = templateContent.match(new RegExp(`${OPTIMA_START_MARKER}[\\s\\S]*?${OPTIMA_END_MARKER}`));
|
|
17
|
-
if (match) {
|
|
18
|
-
return match[0];
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
catch (error) {
|
|
22
|
-
console.log(chalk.yellow('⚠️ 无法读取模板文件,使用默认配置'));
|
|
23
|
-
}
|
|
24
|
-
// 降级方案:简化版配置
|
|
25
|
-
return `${OPTIMA_START_MARKER}
|
|
26
|
-
|
|
27
|
-
电商店铺管理命令行工具。
|
|
28
|
-
|
|
29
|
-
使用 \`commerce --help\` 查看所有命令。
|
|
30
|
-
${OPTIMA_END_MARKER}`;
|
|
31
|
-
}
|
|
32
|
-
import { addEnhancedHelp } from '../utils/helpText.js';
|
|
9
|
+
const PROJECT_SKILL_DIR = path.join(process.cwd(), '.claude', 'skills', 'commerce-cli');
|
|
10
|
+
const PROJECT_SKILL_FILE = path.join(PROJECT_SKILL_DIR, 'SKILL.md');
|
|
11
|
+
const TEMPLATE_SKILL_FILE = path.join(__dirname, '..', '..', '.claude', 'skills', 'commerce-cli', 'SKILL.md');
|
|
33
12
|
const cmd = new Command('init')
|
|
34
|
-
.description('Enable
|
|
13
|
+
.description('Enable Commerce CLI in current project (creates Claude Skill)')
|
|
35
14
|
.action(async () => {
|
|
36
15
|
try {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
fs.mkdirSync(claudeDir, { recursive: true });
|
|
41
|
-
}
|
|
42
|
-
// 读取现有内容
|
|
43
|
-
let existingContent = '';
|
|
44
|
-
let hasExisting = false;
|
|
45
|
-
if (fs.existsSync(PROJECT_CLAUDE_MD)) {
|
|
46
|
-
existingContent = fs.readFileSync(PROJECT_CLAUDE_MD, 'utf-8');
|
|
47
|
-
hasExisting = existingContent.includes(OPTIMA_START_MARKER);
|
|
16
|
+
// 确保 .claude/skills/commerce-cli 目录存在
|
|
17
|
+
if (!fs.existsSync(PROJECT_SKILL_DIR)) {
|
|
18
|
+
fs.mkdirSync(PROJECT_SKILL_DIR, { recursive: true });
|
|
48
19
|
}
|
|
49
|
-
//
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const regex = new RegExp(`${OPTIMA_START_MARKER}[\\s\\S]*?${OPTIMA_END_MARKER}\\n?`, 'g');
|
|
54
|
-
existingContent = existingContent.replace(regex, '');
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
const regex = /## Optima CLI[\s\S]*?(?=\n## [^\n]|\n*$)/g;
|
|
58
|
-
existingContent = existingContent.replace(regex, '');
|
|
59
|
-
}
|
|
60
|
-
existingContent = existingContent.replace(/\n{3,}/g, '\n\n').trim();
|
|
20
|
+
// 检查 Skill 是否已存在
|
|
21
|
+
const isUpdate = fs.existsSync(PROJECT_SKILL_FILE);
|
|
22
|
+
if (isUpdate) {
|
|
23
|
+
console.log(chalk.cyan('\n正在更新 Commerce CLI Skill...\n'));
|
|
61
24
|
}
|
|
62
|
-
//
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
console.log(chalk.
|
|
67
|
-
console.log(chalk.gray(
|
|
68
|
-
console.log(chalk.gray('
|
|
25
|
+
// 复制 Skill 模板
|
|
26
|
+
const skillContent = fs.readFileSync(TEMPLATE_SKILL_FILE, 'utf-8');
|
|
27
|
+
fs.writeFileSync(PROJECT_SKILL_FILE, skillContent, 'utf-8');
|
|
28
|
+
console.log(chalk.green(`\n✓ Commerce CLI Skill 已${isUpdate ? '更新' : '启用'}`));
|
|
29
|
+
console.log(chalk.gray(` Skill 文件: ${PROJECT_SKILL_FILE}`));
|
|
30
|
+
console.log(chalk.gray('\n 现在可以用自然语言管理店铺了!'));
|
|
31
|
+
console.log(chalk.gray(' 例如:"帮我创建一个商品" 或 "查看今天的订单"\n'));
|
|
69
32
|
}
|
|
70
33
|
catch (error) {
|
|
71
|
-
console.log(chalk.red(`\n❌
|
|
34
|
+
console.log(chalk.red(`\n❌ 初始化失败: ${error.message}\n`));
|
|
72
35
|
}
|
|
73
36
|
});
|
|
74
37
|
addEnhancedHelp(cmd, {
|
|
75
38
|
examples: [
|
|
76
|
-
'# Enable
|
|
39
|
+
'# Enable Commerce CLI in current project',
|
|
77
40
|
'$ commerce init',
|
|
78
41
|
'',
|
|
79
|
-
'# This
|
|
80
|
-
'#
|
|
42
|
+
'# This creates a Claude Skill in .claude/skills/commerce-cli.md',
|
|
43
|
+
'# Claude will auto-discover when to use Commerce CLI based on your natural language',
|
|
81
44
|
],
|
|
82
45
|
output: {
|
|
83
|
-
description: 'Creates/updates
|
|
84
|
-
example: '
|
|
46
|
+
description: 'Creates/updates Claude Skill for Commerce CLI',
|
|
47
|
+
example: 'Skill file: /path/to/project/.claude/skills/commerce-cli.md'
|
|
85
48
|
},
|
|
86
49
|
relatedCommands: [
|
|
87
|
-
{ command: 'cleanup', description: 'Remove Optima config from Claude' },
|
|
88
50
|
{ command: 'auth login', description: 'Login after initialization' },
|
|
89
51
|
],
|
|
90
52
|
notes: [
|
|
91
|
-
'Creates .claude directory if it doesn\'t exist',
|
|
92
|
-
'
|
|
93
|
-
'
|
|
94
|
-
'
|
|
53
|
+
'Creates .claude/skills directory if it doesn\'t exist',
|
|
54
|
+
'Updates Skill if already present',
|
|
55
|
+
'Project-level Skill (not global)',
|
|
56
|
+
'Claude auto-discovers based on natural language context',
|
|
95
57
|
]
|
|
96
58
|
});
|
|
97
59
|
export const initCommand = cmd;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.js","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"init.js","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"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"}
|
package/dist/postinstall.js
CHANGED
|
@@ -1,108 +1,23 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import fs from 'fs';
|
|
3
3
|
import path from 'path';
|
|
4
|
-
import os from 'os';
|
|
5
4
|
import { fileURLToPath } from 'url';
|
|
6
5
|
import { dirname } from 'path';
|
|
7
6
|
const __filename = fileURLToPath(import.meta.url);
|
|
8
7
|
const __dirname = dirname(__filename);
|
|
9
|
-
const GLOBAL_CLAUDE_MD_PATH = path.join(os.homedir(), '.claude', 'CLAUDE.md');
|
|
10
|
-
// 从环境变量获取安装时的工作目录
|
|
11
|
-
const INSTALL_CWD = process.env.INIT_CWD || process.env.PWD || process.cwd();
|
|
12
|
-
const PROJECT_CLAUDE_MD_PATH = path.join(INSTALL_CWD, '.claude', 'CLAUDE.md');
|
|
13
|
-
const TEMPLATE_CLAUDE_MD = path.join(__dirname, '..', '.claude', 'CLAUDE.md');
|
|
14
8
|
// 动态读取版本号
|
|
15
9
|
const packageJson = JSON.parse(fs.readFileSync(path.join(__dirname, '../package.json'), 'utf-8'));
|
|
16
10
|
const VERSION = packageJson.version;
|
|
17
|
-
|
|
18
|
-
const OPTIMA_END_MARKER = '<!-- END_OPTIMA_CLI -->';
|
|
19
|
-
// 简化版配置(用于全局)
|
|
20
|
-
const GLOBAL_OPTIMA_SECTION = `
|
|
21
|
-
## Optima CLI
|
|
22
|
-
|
|
23
|
-
**全局可用** - 安装后即可在任何项目中使用 Optima 命令。
|
|
24
|
-
|
|
25
|
-
**常见需求映射**:
|
|
26
|
-
- "登录 Optima" / "Optima 登录" → \`commerce auth login\`
|
|
27
|
-
- "查看商品" / "商品列表" → \`commerce product list\`
|
|
28
|
-
- "创建商品 XX,价格 YY" → \`commerce product create --title XX --price YY\`
|
|
29
|
-
- "订单 XX 发货" → \`commerce order ship XX\`
|
|
30
|
-
- "给商品添加中文翻译" → \`commerce i18n product create ...\`
|
|
31
|
-
|
|
32
|
-
**项目级启用**:如果用户想在当前项目启用完整配置文档,运行 \`commerce init\`。
|
|
33
|
-
|
|
34
|
-
使用 \`commerce --help\` 查看所有可用命令。
|
|
35
|
-
`;
|
|
36
|
-
// 从模板读取完整的 Optima CLI 配置
|
|
37
|
-
function getFullOptimaSection() {
|
|
11
|
+
async function postInstall() {
|
|
38
12
|
try {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return match[0];
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
catch (error) {
|
|
46
|
-
// 如果读取失败,返回 null
|
|
47
|
-
}
|
|
48
|
-
return '';
|
|
49
|
-
}
|
|
50
|
-
// 通用的更新 CLAUDE.md 函数
|
|
51
|
-
function updateClaudeFile(filePath, optimaSection) {
|
|
52
|
-
try {
|
|
53
|
-
const claudeDir = path.dirname(filePath);
|
|
54
|
-
// 确保目录存在
|
|
55
|
-
if (!fs.existsSync(claudeDir)) {
|
|
56
|
-
fs.mkdirSync(claudeDir, { recursive: true });
|
|
57
|
-
}
|
|
58
|
-
// 读取现有内容
|
|
59
|
-
let existingContent = '';
|
|
60
|
-
if (fs.existsSync(filePath)) {
|
|
61
|
-
existingContent = fs.readFileSync(filePath, 'utf-8');
|
|
62
|
-
// 移除旧的 Optima CLI 配置
|
|
63
|
-
if (existingContent.includes(OPTIMA_START_MARKER)) {
|
|
64
|
-
if (existingContent.includes(OPTIMA_END_MARKER)) {
|
|
65
|
-
const regex = new RegExp(`${OPTIMA_START_MARKER}[\\s\\S]*?${OPTIMA_END_MARKER}\\n?`, 'g');
|
|
66
|
-
existingContent = existingContent.replace(regex, '');
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
const regex = /## Optima CLI[\s\S]*?(?=\n## [^\n]|\n*$)/g;
|
|
70
|
-
existingContent = existingContent.replace(regex, '');
|
|
71
|
-
}
|
|
72
|
-
existingContent = existingContent.replace(/\n{3,}/g, '\n\n').trim();
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
// 写入新配置
|
|
76
|
-
const newContent = existingContent.trim() + '\n\n' + optimaSection.trim() + '\n';
|
|
77
|
-
fs.writeFileSync(filePath, newContent, 'utf-8');
|
|
78
|
-
return true;
|
|
79
|
-
}
|
|
80
|
-
catch (error) {
|
|
81
|
-
return false;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
async function setupClaude() {
|
|
85
|
-
try {
|
|
86
|
-
// 更新全局 CLAUDE.md(简化版)
|
|
87
|
-
const globalUpdated = updateClaudeFile(GLOBAL_CLAUDE_MD_PATH, GLOBAL_OPTIMA_SECTION + '\n' + OPTIMA_END_MARKER);
|
|
88
|
-
// 如果当前项目有 .claude/CLAUDE.md,更新完整版
|
|
89
|
-
if (fs.existsSync(PROJECT_CLAUDE_MD_PATH)) {
|
|
90
|
-
const fullSection = getFullOptimaSection();
|
|
91
|
-
if (fullSection) {
|
|
92
|
-
updateClaudeFile(PROJECT_CLAUDE_MD_PATH, fullSection);
|
|
93
|
-
console.log('✓ 已更新项目级 Optima CLI 配置');
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
if (globalUpdated) {
|
|
97
|
-
console.log('✓ Optima CLI 已配置到 Claude Code');
|
|
98
|
-
console.log(` 版本: v${VERSION}`);
|
|
99
|
-
console.log(' 现在可以使用 commerce auth login 登录了!');
|
|
100
|
-
}
|
|
13
|
+
console.log('✓ Commerce CLI 安装成功');
|
|
14
|
+
console.log(` 版本: v${VERSION}`);
|
|
15
|
+
console.log(' 使用 "commerce init" 在项目中启用 Claude Skills 集成');
|
|
101
16
|
}
|
|
102
17
|
catch (error) {
|
|
103
18
|
// 静默失败,不影响安装
|
|
104
19
|
}
|
|
105
20
|
}
|
|
106
|
-
//
|
|
107
|
-
|
|
21
|
+
// 总是执行
|
|
22
|
+
postInstall();
|
|
108
23
|
//# sourceMappingURL=postinstall.js.map
|
package/dist/postinstall.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postinstall.js","sourceRoot":"","sources":["../src/postinstall.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"postinstall.js","sourceRoot":"","sources":["../src/postinstall.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAE/B,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAClD,MAAM,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAEtC,UAAU;AACV,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,iBAAiB,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;AAClG,MAAM,OAAO,GAAG,WAAW,CAAC,OAAO,CAAC;AAEpC,KAAK,UAAU,WAAW;IACxB,IAAI,CAAC;QACH,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC;QACnC,OAAO,CAAC,GAAG,CAAC,UAAU,OAAO,EAAE,CAAC,CAAC;QACjC,OAAO,CAAC,GAAG,CAAC,8CAA8C,CAAC,CAAC;IAC9D,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,aAAa;IACf,CAAC;AACH,CAAC;AAED,OAAO;AACP,WAAW,EAAE,CAAC"}
|
package/dist/preuninstall.d.ts
CHANGED
package/dist/preuninstall.js
CHANGED
|
@@ -1,53 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import { fileURLToPath } from 'url';
|
|
6
|
-
import { dirname } from 'path';
|
|
7
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
8
|
-
const __dirname = dirname(__filename);
|
|
9
|
-
const CLAUDE_MD_PATH = path.join(os.homedir(), '.claude', 'CLAUDE.md');
|
|
10
|
-
const OPTIMA_START_MARKER = '## Optima CLI';
|
|
11
|
-
const OPTIMA_END_MARKER = '<!-- END_OPTIMA_CLI -->';
|
|
12
|
-
async function cleanupClaude() {
|
|
13
|
-
try {
|
|
14
|
-
// 检查文件是否存在
|
|
15
|
-
if (!fs.existsSync(CLAUDE_MD_PATH)) {
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
// 读取现有内容
|
|
19
|
-
let content = fs.readFileSync(CLAUDE_MD_PATH, 'utf-8');
|
|
20
|
-
// 检查是否包含 Optima CLI 配置
|
|
21
|
-
if (!content.includes(OPTIMA_START_MARKER)) {
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
// 移除 Optima CLI 区块
|
|
25
|
-
if (content.includes(OPTIMA_END_MARKER)) {
|
|
26
|
-
// 使用标记精确删除
|
|
27
|
-
const regex = new RegExp(`${OPTIMA_START_MARKER}[\\s\\S]*?${OPTIMA_END_MARKER}\\n?`, 'g');
|
|
28
|
-
content = content.replace(regex, '');
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
// 兼容旧版本:匹配到下一个 ## 或文件末尾
|
|
32
|
-
const regex = /## Optima CLI[\s\S]*?(?=\n## [^\n]|\n*$)/g;
|
|
33
|
-
content = content.replace(regex, '');
|
|
34
|
-
}
|
|
35
|
-
// 清理多余空行
|
|
36
|
-
content = content.replace(/\n{3,}/g, '\n\n').trim() + '\n';
|
|
37
|
-
// 写回文件
|
|
38
|
-
fs.writeFileSync(CLAUDE_MD_PATH, content, 'utf-8');
|
|
39
|
-
console.log('✓ 已从 Claude Code 配置中移除 Optima CLI');
|
|
40
|
-
}
|
|
41
|
-
catch (error) {
|
|
42
|
-
// 静默失败,不影响卸载
|
|
43
|
-
// console.log('⚠️ 清理 Claude Code 配置失败');
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
// 检查是否为全局安装位置
|
|
47
|
-
// 全局卸载时,脚本位置通常在 global node_modules 中
|
|
48
|
-
const isGlobalLocation = __dirname.includes('/node_modules/@optima-chat/optima-cli/dist') ||
|
|
49
|
-
__dirname.includes('\\node_modules\\@optima-chat\\optima-cli\\dist');
|
|
50
|
-
if (isGlobalLocation || process.env.npm_config_global === 'true') {
|
|
51
|
-
cleanupClaude();
|
|
52
|
-
}
|
|
2
|
+
"use strict";
|
|
3
|
+
// Commerce CLI 使用项目级 Skills,无需在卸载时清理全局配置
|
|
4
|
+
// 用户可以手动删除项目中的 .claude/skills/commerce-cli/ 目录
|
|
53
5
|
//# sourceMappingURL=preuninstall.js.map
|
package/dist/preuninstall.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preuninstall.js","sourceRoot":"","sources":["../src/preuninstall.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"preuninstall.js","sourceRoot":"","sources":["../src/preuninstall.ts"],"names":[],"mappings":";;AAEA,yCAAyC;AACzC,+CAA+C"}
|