6a-spec-install 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,167 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+
4
+ class Installer {
5
+ constructor() {
6
+ // 获取包目录(安装后)
7
+ this.packageDir = this.findPackageDir();
8
+ this.targetDir = process.cwd();
9
+ }
10
+
11
+ // 查找包目录(支持本地开发和 npm 安装)
12
+ findPackageDir() {
13
+ // 如果是本地开发,直接使用当前目录
14
+ if (fs.existsSync(path.join(__dirname, '../.cursor'))) {
15
+ return path.join(__dirname, '..');
16
+ }
17
+
18
+ // 如果是 npm 安装,查找 node_modules
19
+ let current = __dirname;
20
+ while (current !== path.dirname(current)) {
21
+ const cursorPath = path.join(current, '.cursor');
22
+ if (fs.existsSync(cursorPath)) {
23
+ return current;
24
+ }
25
+ current = path.dirname(current);
26
+ }
27
+
28
+ throw new Error('未找到 .cursor 目录,请确保包已正确安装');
29
+ }
30
+
31
+ // 颜色输出
32
+ log(message, type = 'info') {
33
+ const colors = {
34
+ info: '\x1b[32m[INFO]\x1b[0m',
35
+ warn: '\x1b[33m[WARN]\x1b[0m',
36
+ error: '\x1b[31m[ERROR]\x1b[0m',
37
+ success: '\x1b[32m[SUCCESS]\x1b[0m'
38
+ };
39
+ console.log(`${colors[type]} ${message}`);
40
+ }
41
+
42
+ // 备份目录
43
+ backupDir(targetPath) {
44
+ if (fs.existsSync(targetPath)) {
45
+ const backupPath = `${targetPath}.backup.${Date.now()}`;
46
+ this.log(`备份现有配置到: ${backupPath}`, 'warn');
47
+ this.copyDir(targetPath, backupPath);
48
+ return backupPath;
49
+ }
50
+ return null;
51
+ }
52
+
53
+ // 递归复制目录
54
+ copyDir(src, dest) {
55
+ if (!fs.existsSync(dest)) {
56
+ fs.mkdirSync(dest, { recursive: true });
57
+ }
58
+
59
+ const entries = fs.readdirSync(src, { withFileTypes: true });
60
+
61
+ for (const entry of entries) {
62
+ const srcPath = path.join(src, entry.name);
63
+ const destPath = path.join(dest, entry.name);
64
+
65
+ if (entry.isDirectory()) {
66
+ this.copyDir(srcPath, destPath);
67
+ } else {
68
+ fs.copyFileSync(srcPath, destPath);
69
+ }
70
+ }
71
+ }
72
+
73
+ // 安装 Cursor 配置
74
+ installCursor() {
75
+ this.log('开始安装 Cursor 配置...');
76
+
77
+ const sourceDir = path.join(this.packageDir, '.cursor');
78
+ const targetDir = path.join(this.targetDir, '.cursor');
79
+
80
+ if (!fs.existsSync(sourceDir)) {
81
+ throw new Error('未找到 .cursor 源目录');
82
+ }
83
+
84
+ this.backupDir(targetDir);
85
+
86
+ this.log('复制 Cursor 配置文件...');
87
+ this.copyDir(sourceDir, targetDir);
88
+
89
+ this.log('✓ Cursor 配置安装完成!', 'success');
90
+ }
91
+
92
+ // 安装 Claude 配置
93
+ installClaude() {
94
+ this.log('开始安装 Claude 配置...');
95
+
96
+ const sourceDir = path.join(this.packageDir, '.cursor');
97
+ const targetDir = path.join(this.targetDir, '.claude');
98
+
99
+ if (!fs.existsSync(sourceDir)) {
100
+ throw new Error('未找到源配置目录');
101
+ }
102
+
103
+ this.backupDir(targetDir);
104
+
105
+ this.log('转换并复制 Claude 配置文件...');
106
+
107
+ // 创建目标目录结构
108
+ if (!fs.existsSync(targetDir)) {
109
+ fs.mkdirSync(targetDir, { recursive: true });
110
+ }
111
+
112
+ // 复制 commands 到 prompts
113
+ const commandsDir = path.join(sourceDir, 'commands');
114
+ if (fs.existsSync(commandsDir)) {
115
+ const promptsDir = path.join(targetDir, 'prompts');
116
+ this.copyDir(commandsDir, promptsDir);
117
+ }
118
+
119
+ // 复制 rules
120
+ const rulesDir = path.join(sourceDir, 'rules');
121
+ if (fs.existsSync(rulesDir)) {
122
+ const targetRulesDir = path.join(targetDir, 'rules');
123
+ this.copyDir(rulesDir, targetRulesDir);
124
+ }
125
+
126
+ // 复制 scripts
127
+ const scriptDir = path.join(sourceDir, 'script');
128
+ if (fs.existsSync(scriptDir)) {
129
+ const targetScriptDir = path.join(targetDir, 'script');
130
+ this.copyDir(scriptDir, targetScriptDir);
131
+ }
132
+
133
+ this.log('✓ Claude 配置安装完成!', 'success');
134
+ }
135
+
136
+ // 主安装方法
137
+ async install(tool = 'cursor') {
138
+ this.log(`6A-spec 安装工具`);
139
+ this.log(`目标目录: ${this.targetDir}`);
140
+ this.log(`工具: ${tool}`);
141
+
142
+ try {
143
+ switch (tool.toLowerCase()) {
144
+ case 'cursor':
145
+ this.installCursor();
146
+ break;
147
+ case 'claude':
148
+ this.installClaude();
149
+ break;
150
+ case 'all':
151
+ this.installCursor();
152
+ this.installClaude();
153
+ break;
154
+ default:
155
+ throw new Error(`未知工具: ${tool}\n支持的工具: cursor, claude, all`);
156
+ }
157
+
158
+ this.log('安装完成!', 'success');
159
+ } catch (error) {
160
+ this.log(error.message, 'error');
161
+ throw error;
162
+ }
163
+ }
164
+ }
165
+
166
+ module.exports = new Installer();
167
+
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "6a-spec-install",
3
+ "version": "1.0.0",
4
+ "description": "6A-spec 驱动开发提示词安装工具,支持 Cursor 和 Claude",
5
+ "main": "lib/installer.js",
6
+ "bin": {
7
+ "6a-spec-install": "./bin/6a-spec-install"
8
+ },
9
+ "scripts": {
10
+ "test": "node bin/6a-spec-install --help"
11
+ },
12
+ "keywords": [
13
+ "cursor",
14
+ "claude",
15
+ "ai",
16
+ "prompts",
17
+ "spec-driven",
18
+ "development",
19
+ "6a-spec"
20
+ ],
21
+ "author": "yanghuijava@gmail.com",
22
+ "license": "MIT",
23
+ "files": [
24
+ "bin/",
25
+ "lib/",
26
+ ".cursor/",
27
+ "README.md"
28
+ ],
29
+ "engines": {
30
+ "node": ">=12.0.0"
31
+ },
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "https://gitee.com/yanghuijava/6-a-spec.git"
35
+ }
36
+ }
37
+