@optima-chat/commerce-cli 1.0.0 → 1.2.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-i18n/SKILL.md +141 -0
- package/.claude/skills/commerce-inventory/SKILL.md +83 -0
- package/.claude/skills/commerce-order/SKILL.md +112 -0
- package/.claude/skills/commerce-product/SKILL.md +108 -0
- package/.claude/skills/commerce-storefront/SKILL.md +110 -0
- package/README.md +41 -51
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +122 -67
- package/dist/commands/init.js.map +1 -1
- package/dist/index.js +0 -2
- package/dist/index.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
- package/.claude/CLAUDE.md +0 -101
- package/dist/commands/cleanup.d.ts +0 -3
- package/dist/commands/cleanup.d.ts.map +0 -1
- package/dist/commands/cleanup.js +0 -100
- package/dist/commands/cleanup.js.map +0 -1
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"}
|
package/package.json
CHANGED
package/.claude/CLAUDE.md
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
## Optima CLI
|
|
4
|
-
|
|
5
|
-
电商店铺管理命令行工具 - 用自然语言管理商品、订单、库存和物流。
|
|
6
|
-
|
|
7
|
-
**版本**: v0.18.2 | **安装**: `npm install -g @optima-chat/commerce-cli@latest`
|
|
8
|
-
|
|
9
|
-
### Available Modules (15)
|
|
10
|
-
**auth** - OAuth 认证管理(login, logout, whoami)
|
|
11
|
-
**merchant** - 商户资料管理(信息、URL、初始化设置)
|
|
12
|
-
**product** - 商品目录管理(CRUD、图片、URL、标签)
|
|
13
|
-
**variant** - 商品变体/SKU 管理(规格、库存、图片)
|
|
14
|
-
**order** - 订单履行(发货、取消、完成、标记送达)
|
|
15
|
-
**refund** - 退款管理
|
|
16
|
-
**inventory** - 库存管理(低库存预警、更新、历史、预留)
|
|
17
|
-
**homepage** - 首页配置管理(模块、设置、分析、翻译)
|
|
18
|
-
**collection** - 集合管理(CRUD、产品关联、翻译)
|
|
19
|
-
**shipping** - 物流管理(运费计算、物流追踪)
|
|
20
|
-
**shipping-zone** - 运费区域配置(按地区设置运费费率)
|
|
21
|
-
**upload** - 媒体文件上传(图片、视频、文件)
|
|
22
|
-
**conversation** - 客服对话管理
|
|
23
|
-
**transfer** - 财务转账和汇总
|
|
24
|
-
**i18n** - 多语言翻译管理(商品/变体/集合/商户/首页的国际化)
|
|
25
|
-
|
|
26
|
-
### Best Practices
|
|
27
|
-
|
|
28
|
-
**环境支持(v0.17.0)** - 支持生产和开发环境切换
|
|
29
|
-
- 生产环境(默认):auth.optima.shop + api.optima.shop
|
|
30
|
-
- 开发环境:auth.optima.chat + api.optima.chat
|
|
31
|
-
- 使用 `--env development` 连接开发后端
|
|
32
|
-
|
|
33
|
-
**非交互模式** - AI 环境自动检测,缺少参数立即报错。删除操作需 `--yes`。
|
|
34
|
-
|
|
35
|
-
**i18n 参数区分** - 翻译命令根据实体使用不同参数:
|
|
36
|
-
- 变体翻译:`--variant-id`(不是 `--product-id`)
|
|
37
|
-
- 集合翻译:`--collection-id`
|
|
38
|
-
- 首页区块翻译:`--section-id`(用于前端展示的多语言标题和描述)
|
|
39
|
-
|
|
40
|
-
**图片上传** - 先 `optima upload image`,再用 `media_id` 关联到商品,避免重复上传。
|
|
41
|
-
|
|
42
|
-
**主动执行** - 不要询问可选字段,先完成任务再报告。
|
|
43
|
-
|
|
44
|
-
### Common Command Examples
|
|
45
|
-
|
|
46
|
-
```bash
|
|
47
|
-
# 认证
|
|
48
|
-
commerce auth login # 登录到生产环境(默认)
|
|
49
|
-
commerce auth login --env development # 登录到开发环境
|
|
50
|
-
commerce merchant info
|
|
51
|
-
|
|
52
|
-
# 商品管理(支持标签)
|
|
53
|
-
commerce product create --title "T恤" --price 99 --tags "featured,new,sale"
|
|
54
|
-
commerce product list --tags "featured,new"
|
|
55
|
-
commerce product update --id prod_123 --price 99
|
|
56
|
-
|
|
57
|
-
# 图片上传
|
|
58
|
-
commerce upload image --path ./photo.jpg
|
|
59
|
-
commerce product add-images --id prod_123 --media-id media_456
|
|
60
|
-
|
|
61
|
-
# 变体管理
|
|
62
|
-
commerce variant create --product-id prod_123 --sku "CUP-S-WHITE" --price 89 --stock 10 --attributes '{"size":"S","color":"White"}'
|
|
63
|
-
|
|
64
|
-
# 首页配置
|
|
65
|
-
commerce homepage module create --slug hero-banner --type banner --position 1 --config '{"images":[{"url":"https://example.com/banner.jpg"}]}'
|
|
66
|
-
commerce homepage settings update --show-search true --featured-limit 8
|
|
67
|
-
|
|
68
|
-
# 集合管理
|
|
69
|
-
commerce collection create --name "Summer Sale" --slug summer-sale
|
|
70
|
-
commerce collection add-products --slug summer-sale --product-ids prod_123,prod_456
|
|
71
|
-
|
|
72
|
-
# 订单履行
|
|
73
|
-
commerce order list --status pending
|
|
74
|
-
commerce order ship --id order_123 --tracking DHL123456 --carrier DHL
|
|
75
|
-
|
|
76
|
-
# 库存管理
|
|
77
|
-
commerce inventory low-stock --threshold 5
|
|
78
|
-
commerce inventory update --id prod_123 --quantity 100
|
|
79
|
-
|
|
80
|
-
# 运费计算
|
|
81
|
-
commerce shipping calculate --country US --postal-code 10001 --weight 0.5
|
|
82
|
-
|
|
83
|
-
# 运费区域配置
|
|
84
|
-
commerce shipping-zone create --name "北美区域" --countries US,CA,MX --price 15 --currency USD
|
|
85
|
-
|
|
86
|
-
# 多语言翻译(注意参数区分)
|
|
87
|
-
commerce i18n product create --product-id prod_123 --lang zh-CN --name "陶瓷杯"
|
|
88
|
-
commerce i18n variant create --variant-id var_456 --lang ja-JP --name "セラミックマグ" --variant-attributes-translations '{"size":{"key_translation":"サイズ","value_translation":{"S":"小"}},"color":{"key_translation":"色","value_translation":{"白":"白"}}}'
|
|
89
|
-
commerce i18n collection create --collection-id coll_789 --lang es-ES --name "Promoción de Verano"
|
|
90
|
-
|
|
91
|
-
# 首页区块翻译(为前端展示添加多语言标题和描述)
|
|
92
|
-
commerce i18n homepage set --section-id section_123 --lang zh-CN --title "精选商品" --description "查看我们最受欢迎的产品"
|
|
93
|
-
commerce i18n homepage set --section-id section_123 --lang en-US --title "Featured Products" --description "Discover our most popular items"
|
|
94
|
-
commerce i18n homepage list --section-id section_123 # 查看区块的所有翻译
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
### Tips
|
|
98
|
-
- 使用 `commerce <命令> --help` 查看详细用法
|
|
99
|
-
- 删除操作需要 `-y` 或 `--yes` 跳过确认
|
|
100
|
-
- 支持的语言:en-US, es-ES, ja-JP, vi-VN, zh-CN
|
|
101
|
-
<!-- END_OPTIMA_CLI -->
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cleanup.d.ts","sourceRoot":"","sources":["../../src/commands/cleanup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAmHpC,eAAO,MAAM,cAAc,SAAM,CAAC"}
|
package/dist/commands/cleanup.js
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { Command } from 'commander';
|
|
2
|
-
import chalk from 'chalk';
|
|
3
|
-
import fs from 'fs';
|
|
4
|
-
import path from 'path';
|
|
5
|
-
import os from 'os';
|
|
6
|
-
import inquirer from 'inquirer';
|
|
7
|
-
import { isInteractiveEnvironment } from '../utils/interactive.js';
|
|
8
|
-
import { ValidationError, handleError } from '../utils/error.js';
|
|
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
|
-
import { addEnhancedHelp } from '../utils/helpText.js';
|
|
13
|
-
const cmd = new Command('cleanup')
|
|
14
|
-
.description('Remove Optima CLI config from Claude Code global settings')
|
|
15
|
-
.option('--yes', 'Skip confirmation prompt (non-interactive)')
|
|
16
|
-
.action(async (options) => {
|
|
17
|
-
try {
|
|
18
|
-
await cleanupConfig(options);
|
|
19
|
-
}
|
|
20
|
-
catch (error) {
|
|
21
|
-
handleError(error);
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
async function cleanupConfig(options) {
|
|
25
|
-
// 检查文件是否存在
|
|
26
|
-
if (!fs.existsSync(CLAUDE_MD_PATH)) {
|
|
27
|
-
console.log(chalk.yellow('\n⚠️ 未找到 Claude Code 配置文件\n'));
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
// 读取内容
|
|
31
|
-
const content = fs.readFileSync(CLAUDE_MD_PATH, 'utf-8');
|
|
32
|
-
// 检查是否包含 Optima CLI 配置
|
|
33
|
-
if (!content.includes(OPTIMA_START_MARKER)) {
|
|
34
|
-
console.log(chalk.yellow('\n⚠️ 配置文件中未找到 Optima CLI 区块\n'));
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
// 确认
|
|
38
|
-
if (!options.yes) {
|
|
39
|
-
if (isInteractiveEnvironment()) {
|
|
40
|
-
// 交互模式:显示确认提示
|
|
41
|
-
const answer = await inquirer.prompt([
|
|
42
|
-
{
|
|
43
|
-
type: 'confirm',
|
|
44
|
-
name: 'confirm',
|
|
45
|
-
message: '确定要从 Claude Code 配置中移除 Optima CLI 区块吗?',
|
|
46
|
-
default: false,
|
|
47
|
-
},
|
|
48
|
-
]);
|
|
49
|
-
if (!answer.confirm) {
|
|
50
|
-
console.log(chalk.gray('\n已取消\n'));
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
// 非交互模式:要求使用 --yes 标志
|
|
56
|
-
throw new ValidationError('非交互环境需要使用 --yes 标志确认清理操作', 'yes');
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
// 移除 Optima CLI 区块
|
|
60
|
-
let newContent = content;
|
|
61
|
-
if (content.includes(OPTIMA_END_MARKER)) {
|
|
62
|
-
const regex = new RegExp(`${OPTIMA_START_MARKER}[\\s\\S]*?${OPTIMA_END_MARKER}\\n?`, 'g');
|
|
63
|
-
newContent = newContent.replace(regex, '');
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
const regex = /## Optima CLI[\s\S]*?(?=\n## [^\n]|\n*$)/g;
|
|
67
|
-
newContent = newContent.replace(regex, '');
|
|
68
|
-
}
|
|
69
|
-
// 清理多余空行
|
|
70
|
-
newContent = newContent.replace(/\n{3,}/g, '\n\n').trim() + '\n';
|
|
71
|
-
// 写回文件
|
|
72
|
-
fs.writeFileSync(CLAUDE_MD_PATH, newContent, 'utf-8');
|
|
73
|
-
console.log(chalk.green('\n✓ 已从 Claude Code 配置中移除 Optima CLI'));
|
|
74
|
-
console.log(chalk.gray(` 配置文件: ${CLAUDE_MD_PATH}\n`));
|
|
75
|
-
}
|
|
76
|
-
addEnhancedHelp(cmd, {
|
|
77
|
-
examples: [
|
|
78
|
-
'# Remove Optima config with confirmation',
|
|
79
|
-
'$ commerce cleanup',
|
|
80
|
-
'',
|
|
81
|
-
'# Remove without confirmation (non-interactive)',
|
|
82
|
-
'$ commerce cleanup --yes',
|
|
83
|
-
],
|
|
84
|
-
output: {
|
|
85
|
-
description: 'Removes Optima CLI section from ~/.claude/CLAUDE.md',
|
|
86
|
-
example: 'Configuration file: /Users/username/.claude/CLAUDE.md'
|
|
87
|
-
},
|
|
88
|
-
relatedCommands: [
|
|
89
|
-
{ command: 'init', description: 'Re-enable Optima in project' },
|
|
90
|
-
{ command: 'auth logout', description: 'Logout before cleanup' },
|
|
91
|
-
],
|
|
92
|
-
notes: [
|
|
93
|
-
'Removes global configuration from ~/.claude/CLAUDE.md',
|
|
94
|
-
'Requires confirmation unless --yes flag is used',
|
|
95
|
-
'Does not affect tokens or login status',
|
|
96
|
-
'Project-level configs (.claude/CLAUDE.md) are not affected',
|
|
97
|
-
]
|
|
98
|
-
});
|
|
99
|
-
export const cleanupCommand = cmd;
|
|
100
|
-
//# sourceMappingURL=cleanup.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cleanup.js","sourceRoot":"","sources":["../../src/commands/cleanup.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,MAAM,IAAI,CAAC;AACpB,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEjE,MAAM,cAAc,GAAG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