Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
168 lines (139 loc) Β· 6.4 KB
/
Copy pathindex.js
File metadata and controls
168 lines (139 loc) Β· 6.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
const fs = require('fs-extra');
const path = require('path');
const glob = require('glob');
const chalk = require('chalk');
class CursorRulesGenerator {
constructor() {
// Get the directory where this package is installed
this.packageDir = path.dirname(require.resolve('./package.json'));
this.templatesDir = path.join(this.packageDir, 'templates');
this.rulesDir = path.join(this.templatesDir, 'rules');
this.commandsDir = path.join(this.templatesDir, 'commands');
this.rulesDestinationDir = '.cursor/rules';
this.commandsDestinationDir = '.cursor/commands';
}
/**
* Copy all template files from templates/rules to .cursor/rules and templates/commands to .cursor/commands
*/
async copyRules() {
try {
console.log(chalk.blue('π WeOrbitant Cursor Rules Generator'));
console.log(chalk.gray('================================'));
// Ensure destination directories exist
await fs.ensureDir(this.rulesDestinationDir);
await fs.ensureDir(this.commandsDestinationDir);
console.log(chalk.green(`β
Created directory: ${this.rulesDestinationDir}`));
console.log(chalk.green(`β
Created directory: ${this.commandsDestinationDir}`));
// Find all template files from both rules and commands directories
const rulesFiles = glob.sync('**/*.mdc', { cwd: this.rulesDir });
const commandsFiles = glob.sync('**/*.md', { cwd: this.commandsDir });
const allTemplateFiles = [
...rulesFiles.map(file => ({ file, source: 'rules' })),
...commandsFiles.map(file => ({ file, source: 'commands' }))
];
if (allTemplateFiles.length === 0) {
console.log(chalk.yellow('β οΈ No template files found in templates/'));
return;
}
console.log(chalk.blue(`π Found ${allTemplateFiles.length} template files:`));
// Copy each template file to its appropriate destination
for (const { file: templateFile, source } of allTemplateFiles) {
const sourceDir = source === 'rules' ? this.rulesDir : this.commandsDir;
const destDir = source === 'rules' ? this.rulesDestinationDir : this.commandsDestinationDir;
const sourcePath = path.join(sourceDir, templateFile);
const destPath = path.join(destDir, templateFile);
// Ensure destination directory exists
await fs.ensureDir(path.dirname(destPath));
// Copy file
await fs.copy(sourcePath, destPath);
console.log(chalk.green(` β
Copied: ${templateFile} (from ${source} to .cursor/${source})`));
}
console.log(chalk.green(`\nπ Successfully copied template files:`));
console.log(chalk.gray(` β’ Rules: ${rulesFiles.length} files to ${this.rulesDestinationDir}/`));
console.log(chalk.gray(` β’ Commands: ${commandsFiles.length} files to ${this.commandsDestinationDir}/`));
console.log(chalk.gray('You can now use these rules and commands in your Cursor IDE!'));
} catch (error) {
console.error(chalk.red('β Error copying rules:'), error.message);
process.exit(1);
}
}
/**
* List available template files
*/
async listTemplates() {
try {
const rulesFiles = glob.sync('**/*.mdc', { cwd: this.rulesDir });
const commandsFiles = glob.sync('**/*.md', { cwd: this.commandsDir });
const allTemplateFiles = [
...rulesFiles.map(file => ({ file, source: 'rules' })),
...commandsFiles.map(file => ({ file, source: 'commands' }))
];
console.log(chalk.blue('π Available Cursor Rules Templates:'));
console.log(chalk.gray('===================================='));
if (allTemplateFiles.length === 0) {
console.log(chalk.yellow('No template files found.'));
return;
}
allTemplateFiles.forEach(({ file, source }, index) => {
console.log(chalk.white(`${index + 1}. ${file} (${source})`));
});
} catch (error) {
console.error(chalk.red('β Error listing templates:'), error.message);
process.exit(1);
}
}
/**
* Clean/remove only the template files that were copied from this package
*/
async cleanRules() {
try {
console.log(chalk.blue('π§Ή Cleaning WeOrbitant Cursor Rules'));
console.log(chalk.gray('================================'));
// Find all template files that should be removed
const rulesFiles = glob.sync('**/*.mdc', { cwd: this.rulesDir });
const commandsFiles = glob.sync('**/*.md', { cwd: this.commandsDir });
const allTemplateFiles = [
...rulesFiles.map(file => ({ file, source: 'rules' })),
...commandsFiles.map(file => ({ file, source: 'commands' }))
];
if (allTemplateFiles.length === 0) {
console.log(chalk.yellow('β οΈ No template files found to clean'));
return;
}
let cleanedCount = 0;
let notFoundCount = 0;
// Remove each template file from its appropriate destination
for (const { file: templateFile, source } of allTemplateFiles) {
const destDir = source === 'rules' ? this.rulesDestinationDir : this.commandsDestinationDir;
const destPath = path.join(destDir, templateFile);
if (await fs.pathExists(destPath)) {
await fs.remove(destPath);
console.log(chalk.green(` β
Removed: ${templateFile} (from .cursor/${source})`));
cleanedCount++;
} else {
console.log(chalk.gray(` βͺ Not found: ${templateFile}`));
notFoundCount++;
}
}
// Remove empty directories if they exist
for (const destDir of [this.rulesDestinationDir, this.commandsDestinationDir]) {
if (await fs.pathExists(destDir)) {
const remainingFiles = await fs.readdir(destDir);
if (remainingFiles.length === 0) {
await fs.remove(destDir);
console.log(chalk.green(`β
Removed empty directory: ${destDir}`));
} else {
console.log(chalk.blue(`π Directory ${destDir} kept (contains other files)`));
}
}
}
console.log(chalk.green(`\nπ Cleanup complete!`));
console.log(chalk.gray(` β’ Removed: ${cleanedCount} files`));
console.log(chalk.gray(` β’ Not found: ${notFoundCount} files`));
} catch (error) {
console.error(chalk.red('β Error cleaning rules:'), error.message);
process.exit(1);
}
}
}
module.exports = CursorRulesGenerator;