This repository was archived by the owner on Mar 10, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcli.js
More file actions
executable file
·92 lines (74 loc) · 2.65 KB
/
cli.js
File metadata and controls
executable file
·92 lines (74 loc) · 2.65 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
#!/usr/bin/env node
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
import fs from 'fs/promises';
import chalk from 'chalk';
import { executeCodeAnalysis } from './src/index.js';
import progress from './src/progress-util.js';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const showHelp = () => {
console.log(`
${chalk.bold('GitHub to Claude Code Mapper')}
${chalk.cyan('Description:')}
Generates AI-optimized documentation from GitHub repositories for use with Claude.
Creates a directory of markdown files, each sized appropriately for LLM processing.
${chalk.cyan('Usage:')}
${chalk.yellow('npx github2claude')} ${chalk.green('<repository-url>')}
${chalk.cyan('Example:')}
${chalk.yellow('npx github2claude')} ${chalk.green('https://github.com/username/repository')}
${chalk.cyan('Output:')}
Creates a 'username__repository@version' directory in your current location
containing markdown files optimized for uploading to Claude.
${chalk.cyan('Options:')}
-h, --help Show this help message
-v, --version Show version number
For more information, visit: ${chalk.blue('https://github.com/SurfSolana/github-to-claude')}
`);
};
const showVersion = async () => {
try {
const packageJson = JSON.parse(
await fs.readFile(join(__dirname, 'package.json'), 'utf-8')
);
console.log(`v${packageJson.version}`);
} catch (error) {
console.error(chalk.red('Error reading version information'));
process.exit(1);
}
};
const main = async () => {
const args = process.argv.slice(2);
if (args.length === 0 || args.includes('-h') || args.includes('--help')) {
showHelp();
process.exit(0);
}
if (args.includes('-v') || args.includes('--version')) {
await showVersion();
process.exit(0);
}
const repoUrl = args[0];
if (!repoUrl.startsWith('https://github.com/')) {
console.error(chalk.red('Error: Please provide a valid GitHub repository URL'));
console.error(chalk.yellow('Example: https://github.com/username/repository'));
process.exit(1);
}
try {
await executeCodeAnalysis(repoUrl);
} catch (error) {
progress.error('Execution failed');
console.error(chalk.red(error.message));
process.exit(1);
}
};
// Handle unhandled promise rejections
process.on('unhandledRejection', (error) => {
progress.error('Unexpected error');
console.error(chalk.red(error.message));
process.exit(1);
});
main().catch(error => {
progress.error('Fatal error');
console.error(chalk.red(error.message));
process.exit(1);
});