tools-cc 1.0.6 → 1.0.8
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/CHANGELOG.md +31 -0
- package/CHANGELOG_en.md +31 -0
- package/README.md +10 -4
- package/README_en.md +56 -4
- package/dist/commands/help.js +31 -4
- package/dist/commands/template.d.ts +18 -0
- package/dist/commands/template.js +154 -0
- package/dist/commands/use.d.ts +2 -2
- package/dist/commands/use.js +40 -35
- package/dist/core/template.d.ts +17 -0
- package/dist/core/template.js +74 -0
- package/dist/index.js +32 -0
- package/dist/types/config.d.ts +10 -0
- package/dist/utils/path.d.ts +2 -0
- package/dist/utils/path.js +6 -1
- package/package.json +3 -3
- package/src/commands/help.ts +31 -4
- package/src/commands/template.ts +160 -0
- package/src/commands/use.ts +12 -6
- package/src/core/template.ts +91 -0
- package/src/index.ts +48 -11
- package/src/types/config.ts +112 -101
- package/src/utils/path.ts +23 -18
- package/tests/commands/export.test.ts +120 -0
- package/tests/commands/use.test.ts +326 -0
- package/tests/core/config.test.ts +37 -0
- package/tests/core/manifest.test.ts +37 -0
- package/tests/core/project.test.ts +317 -0
- package/tests/core/source.test.ts +75 -0
- package/tests/core/symlink.test.ts +39 -0
- package/tests/core/template.test.ts +103 -0
- package/tests/types/config.test.ts +232 -0
- package/tests/utils/parsePath.test.ts +235 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,37 @@
|
|
|
2
2
|
|
|
3
3
|
本项目的所有重要变更都将记录在此文件中。
|
|
4
4
|
|
|
5
|
+
## [1.0.8] - 2026-03-04
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
- 新增模板管理功能,支持保存/复用项目配置
|
|
9
|
+
- `tools-cc template save [-n <name>]` 保存当前项目配置为模板
|
|
10
|
+
- `tools-cc template list` 列出所有已保存的模板
|
|
11
|
+
- `tools-cc template rm <name>` 删除模板
|
|
12
|
+
- `tools-cc template use [name]` 应用模板到当前项目(无参数时交互选择)
|
|
13
|
+
- 模板存储在 `~/.tools-cc/templates/` 目录
|
|
14
|
+
|
|
15
|
+
### Fixed
|
|
16
|
+
- 修复测试文件未纳入版本控制的问题
|
|
17
|
+
|
|
18
|
+
## [1.0.7] - 2026-03-02
|
|
19
|
+
|
|
20
|
+
### Fixed
|
|
21
|
+
- 修复 `tools-cc update` 命令无法正确识别旧版数组格式配置的问题(sources 为数组时会被错误解析为索引)
|
|
22
|
+
|
|
23
|
+
### Changed
|
|
24
|
+
- 更新帮助文档,完善命令说明和示例
|
|
25
|
+
|
|
26
|
+
## [1.0.6] - 2026-03-02
|
|
27
|
+
|
|
28
|
+
### Added
|
|
29
|
+
- 新增无参数交互式源选择:`tools-cc use` 直接运行显示源列表供选择
|
|
30
|
+
- 新增配置文件导入功能:`tools-cc use -c config.json` 从导出的配置文件快速恢复项目配置
|
|
31
|
+
|
|
32
|
+
### Changed
|
|
33
|
+
- 重构 `use` 命令,统一支持多种模式(配置导入、交互选择、路径语法、整体导入、点模式)
|
|
34
|
+
- 优化交互选择模式,支持分组展示 skills/commands/agents
|
|
35
|
+
|
|
5
36
|
## [1.0.5] - 2026-02-28
|
|
6
37
|
|
|
7
38
|
### Added
|
package/CHANGELOG_en.md
CHANGED
|
@@ -2,6 +2,37 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
+
## [1.0.8] - 2026-03-04
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
- Added template management feature for saving/reusing project configs
|
|
9
|
+
- `tools-cc template save [-n <name>]` save current project config as template
|
|
10
|
+
- `tools-cc template list` list all saved templates
|
|
11
|
+
- `tools-cc template rm <name>` remove a template
|
|
12
|
+
- `tools-cc template use [name]` apply template to current project (interactive selection if no name)
|
|
13
|
+
- Templates stored in `~/.tools-cc/templates/` directory
|
|
14
|
+
|
|
15
|
+
### Fixed
|
|
16
|
+
- Fixed test files not being tracked in version control
|
|
17
|
+
|
|
18
|
+
## [1.0.7] - 2026-03-02
|
|
19
|
+
|
|
20
|
+
### Fixed
|
|
21
|
+
- Fixed `tools-cc update` command failing to recognize legacy array format config (sources array was incorrectly parsed as indices)
|
|
22
|
+
|
|
23
|
+
### Changed
|
|
24
|
+
- Updated help documentation with improved command descriptions and examples
|
|
25
|
+
|
|
26
|
+
## [1.0.6] - 2026-03-02
|
|
27
|
+
|
|
28
|
+
### Added
|
|
29
|
+
- Added interactive source selection: `tools-cc use` without arguments shows source list for selection
|
|
30
|
+
- Added config import feature: `tools-cc use -c config.json` to quickly restore project config from exported file
|
|
31
|
+
|
|
32
|
+
### Changed
|
|
33
|
+
- Refactored `use` command to support multiple modes (config import, interactive selection, path syntax, full import, dot mode)
|
|
34
|
+
- Improved interactive selection mode with grouped display of skills/commands/agents
|
|
35
|
+
|
|
5
36
|
## [1.0.5] - 2026-02-28
|
|
6
37
|
|
|
7
38
|
### Added
|
package/README.md
CHANGED
|
@@ -36,11 +36,14 @@ tools-cc -s list
|
|
|
36
36
|
cd my-project
|
|
37
37
|
tools-cc use my-skills -p iflow claude codex
|
|
38
38
|
|
|
39
|
-
# 4a.
|
|
39
|
+
# 4a. 无参数运行,交互式选择源
|
|
40
|
+
tools-cc use # 显示源列表供选择
|
|
41
|
+
|
|
42
|
+
# 4b. 或使用部分引入(只引入需要的 skills/commands/agents)
|
|
40
43
|
tools-cc use my-skills/skills/a-skill
|
|
41
|
-
tools-cc use my-skills --ls #
|
|
44
|
+
tools-cc use my-skills --ls # 交互式选择内容
|
|
42
45
|
|
|
43
|
-
#
|
|
46
|
+
# 4c. 或从配置文件快速导入
|
|
44
47
|
tools-cc use -c project-config.json
|
|
45
48
|
|
|
46
49
|
# 5. 查看项目状态
|
|
@@ -117,6 +120,9 @@ tools-cc export [options] # 导出项目或全局配置
|
|
|
117
120
|
#### `use` 命令详解
|
|
118
121
|
|
|
119
122
|
```bash
|
|
123
|
+
# 无参数运行:交互式选择源
|
|
124
|
+
tools-cc use # 显示可用源列表供选择
|
|
125
|
+
|
|
120
126
|
# 整源引入(全部 skills/commands/agents)
|
|
121
127
|
tools-cc use my-skills
|
|
122
128
|
tools-cc use my-skills -p iflow claude codex # 指定工具链接
|
|
@@ -127,7 +133,7 @@ tools-cc use my-skills/commands/test # 引入单个 command
|
|
|
127
133
|
tools-cc use my-skills/agents/reviewer # 引入单个 agent
|
|
128
134
|
tools-cc use my-skills/skills/a my-skills/commands/test # 引入多项
|
|
129
135
|
|
|
130
|
-
#
|
|
136
|
+
# 交互式选择内容(--ls 参数)
|
|
131
137
|
tools-cc use my-skills --ls # 分组展示,勾选引入
|
|
132
138
|
|
|
133
139
|
# 从配置文件导入
|
package/README_en.md
CHANGED
|
@@ -34,7 +34,8 @@ tools-cc -s list
|
|
|
34
34
|
|
|
35
35
|
# 4. Enable configuration sources in a project and create links
|
|
36
36
|
cd my-project
|
|
37
|
-
tools-cc use
|
|
37
|
+
tools-cc use # Interactive source selection
|
|
38
|
+
tools-cc use my-skills -p iflow claude codex
|
|
38
39
|
|
|
39
40
|
# 5. View project status
|
|
40
41
|
tools-cc status
|
|
@@ -99,11 +100,50 @@ tools-cc sources scan # Scan sourcesDir to auto-discover and
|
|
|
99
100
|
### Project Configuration
|
|
100
101
|
|
|
101
102
|
```bash
|
|
102
|
-
tools-cc use [sources...] [
|
|
103
|
+
tools-cc use [sources...] [options] # Enable configuration sources and create symbolic links
|
|
103
104
|
tools-cc update [sources...] # Sync configuration source content to project .toolscc directory
|
|
104
105
|
tools-cc list # List enabled configuration sources
|
|
105
106
|
tools-cc rm <source> # Disable configuration source
|
|
106
107
|
tools-cc status # View project status
|
|
108
|
+
tools-cc export [options] # Export project or global config
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
#### `use` Command Details
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
# No arguments: interactive source selection
|
|
115
|
+
tools-cc use # Show available sources for selection
|
|
116
|
+
|
|
117
|
+
# Full source import (all skills/commands/agents)
|
|
118
|
+
tools-cc use my-skills
|
|
119
|
+
tools-cc use my-skills -p iflow claude codex # Specify tool links
|
|
120
|
+
|
|
121
|
+
# Partial import (path syntax)
|
|
122
|
+
tools-cc use my-skills/skills/a-skill # Import single skill
|
|
123
|
+
tools-cc use my-skills/commands/test # Import single command
|
|
124
|
+
tools-cc use my-skills/agents/reviewer # Import single agent
|
|
125
|
+
tools-cc use my-skills/skills/a my-skills/commands/test # Import multiple
|
|
126
|
+
|
|
127
|
+
# Interactive content selection (--ls flag)
|
|
128
|
+
tools-cc use my-skills --ls # Grouped display, checkbox selection
|
|
129
|
+
|
|
130
|
+
# Import from config file
|
|
131
|
+
tools-cc use -c project-config.json # Quick restore project config
|
|
132
|
+
|
|
133
|
+
# Use "." for existing project sources (only create links, no copy)
|
|
134
|
+
tools-cc use . -p iflow claude codex
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
#### `export` Command Details
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
# Export project config
|
|
141
|
+
tools-cc export # Export to .toolscc-export.json
|
|
142
|
+
tools-cc export -o my-config.json # Specify output path
|
|
143
|
+
|
|
144
|
+
# Export global config
|
|
145
|
+
tools-cc export --global # Export to .toolscc-global-export.json
|
|
146
|
+
tools-cc export --global -o global.json # Specify output path
|
|
107
147
|
```
|
|
108
148
|
|
|
109
149
|
### Config Management
|
|
@@ -135,6 +175,7 @@ tools-cc --version # Display version number
|
|
|
135
175
|
| claude | `.claude` |
|
|
136
176
|
| codebuddy | `.codebuddy` |
|
|
137
177
|
| opencode | `.opencode` |
|
|
178
|
+
| codex | `.codex` |
|
|
138
179
|
|
|
139
180
|
## Configuration Source Structure
|
|
140
181
|
|
|
@@ -208,11 +249,22 @@ my-project/
|
|
|
208
249
|
|
|
209
250
|
```json
|
|
210
251
|
{
|
|
211
|
-
"sources":
|
|
212
|
-
|
|
252
|
+
"sources": {
|
|
253
|
+
"my-skills": {
|
|
254
|
+
"skills": ["a-skill", "b-skill"],
|
|
255
|
+
"commands": ["test"],
|
|
256
|
+
"agents": ["*"]
|
|
257
|
+
}
|
|
258
|
+
},
|
|
259
|
+
"links": ["iflow", "claude", "codex"]
|
|
213
260
|
}
|
|
214
261
|
```
|
|
215
262
|
|
|
263
|
+
**Notes:**
|
|
264
|
+
- `sources` records specific content imported from each source
|
|
265
|
+
- `["*"]` means import all content of that type
|
|
266
|
+
- `[]` means import nothing of that type
|
|
267
|
+
|
|
216
268
|
## License
|
|
217
269
|
|
|
218
270
|
MIT
|
package/dist/commands/help.js
CHANGED
|
@@ -28,7 +28,8 @@ ${chalk_1.default.bold('COMMANDS / 命令')}
|
|
|
28
28
|
tools-cc sources add <name> <path-or-url> Add a source / 添加配置源
|
|
29
29
|
tools-cc sources list, ls List all sources / 列出所有配置源
|
|
30
30
|
tools-cc sources remove, rm <name> Remove a source / 移除配置源
|
|
31
|
-
tools-cc sources update, up [name]
|
|
31
|
+
tools-cc sources update, up [name] git pull update / 更新源代码
|
|
32
|
+
tools-cc sources scan Scan dir for sources / 扫描发现新源
|
|
32
33
|
|
|
33
34
|
${chalk_1.default.gray('Shortcut: -s')} e.g., tools-cc -s add my-skills https://github.com/user/skills.git
|
|
34
35
|
|
|
@@ -40,16 +41,27 @@ ${chalk_1.default.bold('COMMANDS / 命令')}
|
|
|
40
41
|
${chalk_1.default.gray('Shortcut: -c')} e.g., tools-cc -c set sourcesDir D:/skills
|
|
41
42
|
|
|
42
43
|
${chalk_1.default.cyan('Project Commands / 项目命令')}
|
|
43
|
-
tools-cc use [sources...] [
|
|
44
|
+
tools-cc use [sources...] [options] Use sources in project / 在项目中启用配置源
|
|
45
|
+
tools-cc update [sources...] Sync source content to project / 同步内容到项目
|
|
44
46
|
tools-cc list List used sources / 列出已启用的配置源
|
|
45
47
|
tools-cc rm <source> Remove source from project / 禁用配置源
|
|
46
48
|
tools-cc status Show project status / 显示项目状态
|
|
49
|
+
tools-cc export [options] Export config / 导出配置
|
|
47
50
|
|
|
48
51
|
${chalk_1.default.cyan('Help / 帮助')}
|
|
49
52
|
tools-cc help Show this help / 显示此帮助信息
|
|
50
53
|
tools-cc --help, -h Show command help / 显示命令帮助
|
|
51
54
|
tools-cc --version, -V Show version / 显示版本号
|
|
52
55
|
|
|
56
|
+
${chalk_1.default.bold('USE OPTIONS / use 命令选项')}
|
|
57
|
+
-p, --tools <tools...> Target tools (iflow, claude, etc.) / 目标工具
|
|
58
|
+
--ls Interactive selection / 交互式选择内容
|
|
59
|
+
-c, --config <file> Import from config file / 从配置文件导入
|
|
60
|
+
|
|
61
|
+
${chalk_1.default.bold('EXPORT OPTIONS / export 命令选项')}
|
|
62
|
+
-o, --output <file> Output file path / 输出文件路径
|
|
63
|
+
--global Export global config / 导出全局配置
|
|
64
|
+
|
|
53
65
|
${chalk_1.default.bold('SUPPORTED TOOLS / 支持的工具')}
|
|
54
66
|
iflow → .iflow
|
|
55
67
|
claude → .claude
|
|
@@ -64,21 +76,36 @@ ${chalk_1.default.bold('EXAMPLES / 示例')}
|
|
|
64
76
|
${chalk_1.default.gray('# Add a local source / 添加本地配置源')}
|
|
65
77
|
tools-cc sources add local-skills D:/path/to/local-skills
|
|
66
78
|
|
|
79
|
+
${chalk_1.default.gray('# Scan for sources / 扫描发现配置源')}
|
|
80
|
+
tools-cc sources scan
|
|
81
|
+
|
|
67
82
|
${chalk_1.default.gray('# List all sources / 列出所有配置源')}
|
|
68
83
|
tools-cc sources list
|
|
69
84
|
|
|
70
85
|
${chalk_1.default.gray('# Use sources in project / 在项目中启用配置源')}
|
|
71
86
|
tools-cc use my-skills -p iflow claude codex
|
|
72
87
|
|
|
88
|
+
${chalk_1.default.gray('# Interactive selection / 交互式选择内容')}
|
|
89
|
+
tools-cc use my-skills --ls
|
|
90
|
+
|
|
91
|
+
${chalk_1.default.gray('# Import from config file / 从配置文件导入')}
|
|
92
|
+
tools-cc use -c project-config.json
|
|
93
|
+
|
|
94
|
+
${chalk_1.default.gray('# Sync source content to project / 同步源内容到项目')}
|
|
95
|
+
tools-cc update my-skills
|
|
96
|
+
|
|
73
97
|
${chalk_1.default.gray('# Check project status / 检查项目状态')}
|
|
74
98
|
tools-cc status
|
|
75
99
|
|
|
100
|
+
${chalk_1.default.gray('# Export project config / 导出项目配置')}
|
|
101
|
+
tools-cc export -o my-config.json
|
|
102
|
+
|
|
76
103
|
${chalk_1.default.gray('# Show full configuration / 显示完整配置')}
|
|
77
104
|
tools-cc config list
|
|
78
105
|
|
|
79
106
|
${chalk_1.default.bold('MORE INFO / 更多信息')}
|
|
80
|
-
GitHub: https://github.com/
|
|
81
|
-
Docs: https://github.com/
|
|
107
|
+
GitHub: https://github.com/q759410559/tools-cc
|
|
108
|
+
Docs: https://github.com/q759410559/tools-cc#readme
|
|
82
109
|
|
|
83
110
|
${chalk_1.default.bold.cyan('═══════════════════════════════════════════════════════════════════════════')}
|
|
84
111
|
`);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 处理 template save 命令
|
|
3
|
+
*/
|
|
4
|
+
export declare function handleTemplateSave(options: {
|
|
5
|
+
name?: string;
|
|
6
|
+
}): Promise<void>;
|
|
7
|
+
/**
|
|
8
|
+
* 处理 template list 命令
|
|
9
|
+
*/
|
|
10
|
+
export declare function handleTemplateList(): Promise<void>;
|
|
11
|
+
/**
|
|
12
|
+
* 处理 template rm 命令
|
|
13
|
+
*/
|
|
14
|
+
export declare function handleTemplateRemove(name: string): Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* 处理 template use 命令
|
|
17
|
+
*/
|
|
18
|
+
export declare function handleTemplateUse(name?: string): Promise<void>;
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.handleTemplateSave = handleTemplateSave;
|
|
7
|
+
exports.handleTemplateList = handleTemplateList;
|
|
8
|
+
exports.handleTemplateRemove = handleTemplateRemove;
|
|
9
|
+
exports.handleTemplateUse = handleTemplateUse;
|
|
10
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
11
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
|
12
|
+
const path_1 = __importDefault(require("path"));
|
|
13
|
+
const template_1 = require("../core/template");
|
|
14
|
+
const config_1 = require("../core/config");
|
|
15
|
+
const project_1 = require("../core/project");
|
|
16
|
+
const source_1 = require("../core/source");
|
|
17
|
+
const path_2 = require("../utils/path");
|
|
18
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
19
|
+
/**
|
|
20
|
+
* 处理 template save 命令
|
|
21
|
+
*/
|
|
22
|
+
async function handleTemplateSave(options) {
|
|
23
|
+
const projectDir = process.cwd();
|
|
24
|
+
const configFile = (0, path_2.getProjectConfigPath)(projectDir);
|
|
25
|
+
// 检查项目配置是否存在
|
|
26
|
+
if (!(await fs_extra_1.default.pathExists(configFile))) {
|
|
27
|
+
console.log(chalk_1.default.yellow('Project not initialized. Run `tools-cc use <source>` first.'));
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
// 读取项目配置
|
|
32
|
+
const config = await (0, config_1.loadProjectConfig)(projectDir);
|
|
33
|
+
if (!config) {
|
|
34
|
+
console.log(chalk_1.default.yellow('No project configuration found.'));
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
// 确定模板名称
|
|
38
|
+
let templateName = options.name;
|
|
39
|
+
if (!templateName) {
|
|
40
|
+
templateName = path_1.default.basename(projectDir);
|
|
41
|
+
}
|
|
42
|
+
// 检查是否已存在
|
|
43
|
+
const existing = await (0, template_1.getTemplate)(templateName, path_2.TEMPLATES_DIR);
|
|
44
|
+
if (existing) {
|
|
45
|
+
const answers = await inquirer_1.default.prompt([
|
|
46
|
+
{
|
|
47
|
+
type: 'confirm',
|
|
48
|
+
name: 'overwrite',
|
|
49
|
+
message: `Template "${templateName}" already exists. Overwrite?`,
|
|
50
|
+
default: false
|
|
51
|
+
}
|
|
52
|
+
]);
|
|
53
|
+
if (!answers.overwrite) {
|
|
54
|
+
console.log(chalk_1.default.gray('Cancelled.'));
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
// 保存模板
|
|
59
|
+
const template = await (0, template_1.saveTemplate)(templateName, projectDir, config, path_2.TEMPLATES_DIR);
|
|
60
|
+
console.log(chalk_1.default.green(`✓ Template saved: ${template.name}`));
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
console.log(chalk_1.default.red(`✗ Failed to save template: ${error instanceof Error ? error.message : 'Unknown error'}`));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* 处理 template list 命令
|
|
68
|
+
*/
|
|
69
|
+
async function handleTemplateList() {
|
|
70
|
+
const templates = await (0, template_1.listTemplates)(path_2.TEMPLATES_DIR);
|
|
71
|
+
if (templates.length === 0) {
|
|
72
|
+
console.log(chalk_1.default.gray('No templates saved.'));
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
console.log(chalk_1.default.bold('Saved templates:'));
|
|
76
|
+
for (const template of templates) {
|
|
77
|
+
const date = new Date(template.savedAt).toLocaleDateString();
|
|
78
|
+
console.log(` ${chalk_1.default.cyan(template.name.padEnd(20))} (saved: ${date})`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* 处理 template rm 命令
|
|
83
|
+
*/
|
|
84
|
+
async function handleTemplateRemove(name) {
|
|
85
|
+
try {
|
|
86
|
+
await (0, template_1.removeTemplate)(name, path_2.TEMPLATES_DIR);
|
|
87
|
+
console.log(chalk_1.default.green(`✓ Template removed: ${name}`));
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
console.log(chalk_1.default.red(`✗ Failed to remove template: ${error instanceof Error ? error.message : 'Unknown error'}`));
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* 处理 template use 命令
|
|
95
|
+
*/
|
|
96
|
+
async function handleTemplateUse(name) {
|
|
97
|
+
const projectDir = process.cwd();
|
|
98
|
+
const configFile = (0, path_2.getProjectConfigPath)(projectDir);
|
|
99
|
+
// 检查项目是否已初始化
|
|
100
|
+
if (!(await fs_extra_1.default.pathExists(configFile))) {
|
|
101
|
+
console.log(chalk_1.default.yellow('Project not initialized. Run `tools-cc use <source>` first.'));
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
// 如果没有指定名称,显示选择列表
|
|
105
|
+
if (!name) {
|
|
106
|
+
const templates = await (0, template_1.listTemplates)(path_2.TEMPLATES_DIR);
|
|
107
|
+
if (templates.length === 0) {
|
|
108
|
+
console.log(chalk_1.default.gray('No templates saved.'));
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const answers = await inquirer_1.default.prompt([
|
|
112
|
+
{
|
|
113
|
+
type: 'list',
|
|
114
|
+
name: 'selectedTemplate',
|
|
115
|
+
message: 'Select a template to use:',
|
|
116
|
+
choices: templates.map(t => ({
|
|
117
|
+
name: `${t.name} (from: ${path_1.default.basename(t.sourceProject)})`,
|
|
118
|
+
value: t.name
|
|
119
|
+
}))
|
|
120
|
+
}
|
|
121
|
+
]);
|
|
122
|
+
name = answers.selectedTemplate;
|
|
123
|
+
}
|
|
124
|
+
// 获取模板
|
|
125
|
+
const template = await (0, template_1.getTemplate)(name, path_2.TEMPLATES_DIR);
|
|
126
|
+
if (!template) {
|
|
127
|
+
console.log(chalk_1.default.red(`✗ Template not found: ${name}`));
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
// 定义源路径解析函数
|
|
131
|
+
const resolveSourcePath = async (sourceName) => {
|
|
132
|
+
return await (0, source_1.getSourcePath)(sourceName, path_2.GLOBAL_CONFIG_DIR);
|
|
133
|
+
};
|
|
134
|
+
// 创建临时配置文件
|
|
135
|
+
const tempConfigPath = path_1.default.join(projectDir, '.toolscc-template-temp.json');
|
|
136
|
+
const exportConfig = {
|
|
137
|
+
version: '1.0',
|
|
138
|
+
type: 'project',
|
|
139
|
+
config: template.config,
|
|
140
|
+
exportedAt: new Date().toISOString()
|
|
141
|
+
};
|
|
142
|
+
// 导入配置
|
|
143
|
+
try {
|
|
144
|
+
await fs_extra_1.default.writeJson(tempConfigPath, exportConfig, { spaces: 2 });
|
|
145
|
+
await (0, project_1.importProjectConfig)(tempConfigPath, projectDir, resolveSourcePath);
|
|
146
|
+
console.log(chalk_1.default.green(`✓ Applied template: ${name}`));
|
|
147
|
+
}
|
|
148
|
+
catch (error) {
|
|
149
|
+
console.log(chalk_1.default.red(`✗ Failed to apply template: ${error instanceof Error ? error.message : 'Unknown error'}`));
|
|
150
|
+
}
|
|
151
|
+
finally {
|
|
152
|
+
await fs_extra_1.default.remove(tempConfigPath);
|
|
153
|
+
}
|
|
154
|
+
}
|
package/dist/commands/use.d.ts
CHANGED
|
@@ -9,12 +9,12 @@ export interface UseOptions {
|
|
|
9
9
|
/**
|
|
10
10
|
* 处理 use 命令
|
|
11
11
|
*
|
|
12
|
-
*
|
|
12
|
+
* 支持多种模式:
|
|
13
13
|
* 1. 配置导入模式: tools-cc use -c config.json
|
|
14
14
|
* 2. 交互选择模式: tools-cc use my-source --ls
|
|
15
15
|
* 3. 路径语法模式: tools-cc use my-source/skills/a-skill
|
|
16
16
|
* 4. 整体导入模式: tools-cc use my-source
|
|
17
|
-
* 5.
|
|
17
|
+
* 5. 点模式: tools-cc use . (使用已配置源)
|
|
18
18
|
*/
|
|
19
19
|
export declare function handleUse(sourceSpecs: string[], options: UseOptions): Promise<void>;
|
|
20
20
|
export declare function handleList(): Promise<void>;
|