-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathindex.js
executable file
·124 lines (102 loc) · 3.71 KB
/
index.js
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
#!/usr/bin/env node
const fs = require('fs-extra');
const path = require('path');
const os = require('os');
const { simpleGit } = require('simple-git');
const { program } = require('commander');
const { version } = require('./package.json');
const _debug = require('debug');
const debug = require('debug')('cursor-bank');
const git = simpleGit();
// Configuration
const config = {
repoUrl: 'https://github.com/tacticlaunch/cursor-bank',
sourcePath: '.cursor/rules',
targetPath: '.cursor/rules',
branch: 'main'
};
// Custom logger function
const log = {
info: (message) => console.log(message),
debug: (message) => debug(message),
error: (message) => console.error(message)
};
async function cloneAndCopy(options) {
// Enable debug logging if the debug flag is set
if (options.debug) {
_debug.enable('cursor-bank');
debug('Debug mode enabled');
}
// Create a temporary directory
const tempDir = path.join(os.tmpdir(), `cursor-bank-${Date.now()}`);
log.debug(`Creating temporary directory: ${tempDir}`);
try {
// Clone the repository
log.info(`Cloning repository...`);
log.debug(`Cloning from ${config.repoUrl} branch ${config.branch}`);
await git.clone(config.repoUrl, tempDir, [
'--depth', '1',
'--single-branch',
'--branch', config.branch
]);
// Path to source directory in the cloned repo
const sourcePath = path.join(tempDir, config.sourcePath);
// Path to target directory in current working directory
const targetPath = path.join(process.cwd(), config.targetPath);
// Check if source exists
if (!fs.existsSync(sourcePath)) {
throw new Error(`Source path ${config.sourcePath} not found in repository`);
}
// Create target directory if it doesn't exist
log.info(`Copying rules to ${config.targetPath}...`);
log.debug(`Full source path: ${sourcePath}`);
log.debug(`Full target path: ${targetPath}`);
await fs.ensureDir(path.dirname(targetPath));
// Copy directory
await fs.copy(sourcePath, targetPath);
log.debug(`Successfully copied ${config.sourcePath} to ${targetPath}`);
// Create memory-bank directory if it doesn't exist
const memoryBankPath = path.join(process.cwd(), 'memory-bank');
if (!fs.existsSync(memoryBankPath)) {
log.info('Creating memory-bank directory...');
await fs.ensureDir(memoryBankPath);
log.debug('Successfully created memory-bank directory');
} else {
log.debug('memory-bank directory already exists');
}
log.info('\n✅ Setup complete! You can now use the Cursor Memory Bank.');
log.info('For new projects, I recommend starting with a PLAN command before initializing the memory bank. For more details, visit https://github.com/tacticlaunch/cursor-bank');
log.info('For existing projects, write to your Cursor assistant: "initialize memory bank".');
} catch (error) {
log.error('An error occurred:');
log.error(error.message);
if (options.debug) {
log.debug(error.stack);
}
process.exit(1);
} finally {
// Clean up temporary directory
if (fs.existsSync(tempDir)) {
log.debug(`Cleaning up temporary directory: ${tempDir}`);
await fs.remove(tempDir);
}
}
}
// Setup CLI commands
program
.name('cursor-bank')
.description('Cursor Memory Bank installer and utilities')
.version(version);
program
.command('init')
.description('Initialize Cursor Memory Bank in the current project')
.option('-d, --debug', 'Enable debug output')
.action((options) => {
log.info('Initializing Cursor Memory Bank...');
cloneAndCopy(options);
});
// If no arguments provided, show help
if (process.argv.length === 2) {
program.help();
}
program.parse();