This commit is contained in:
102
.ai-context-generator-cli/src/index.ts
Normal file
102
.ai-context-generator-cli/src/index.ts
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
import { Command } from 'commander';
|
||||||
|
import * as path from 'path';
|
||||||
|
import { ContextGenerator } from './generators/contextGenerator';
|
||||||
|
import { TemplateLoader } from './templates/templateLoader';
|
||||||
|
import { ConfigLoader } from './config/configLoader';
|
||||||
|
import { CLIUtils } from './utils/cli';
|
||||||
|
import { FileUtils } from './utils/fileUtils';
|
||||||
|
import { ContextConfig } from './types';
|
||||||
|
|
||||||
|
const packageJson = {
|
||||||
|
name: 'ai-context-generator-cli',
|
||||||
|
version: '1.0.0',
|
||||||
|
description: 'A CLI tool that generates comprehensive context files for AI coding assistants',
|
||||||
|
};
|
||||||
|
|
||||||
|
async function main(): Promise<void> {
|
||||||
|
const program = new Command();
|
||||||
|
|
||||||
|
program
|
||||||
|
.name('ai-context')
|
||||||
|
.description('Generate comprehensive context files for AI coding assistants')
|
||||||
|
.version(packageJson.version);
|
||||||
|
|
||||||
|
program
|
||||||
|
.option('-d, --dir <directory>', 'Project directory to analyze', process.cwd())
|
||||||
|
.option('-o, --output <file>', 'Output file path', 'ai-context')
|
||||||
|
.option('-f, --format <format>', 'Output format (json or yaml)', 'json')
|
||||||
|
.option('-t, --template <template>', 'Template to use (default, cursor, copilot, generic)', 'default')
|
||||||
|
.option('-c, --config <file>', 'Config file path', '')
|
||||||
|
.option('-v, --verbose', 'Enable verbose output', false)
|
||||||
|
.option('--no-conventions', 'Skip convention analysis')
|
||||||
|
.option('--include-dev', 'Include dev dependencies')
|
||||||
|
.option('--no-gitignore', 'Do not respect .gitignore patterns');
|
||||||
|
|
||||||
|
program.parse(process.argv);
|
||||||
|
|
||||||
|
const options = program.opts();
|
||||||
|
|
||||||
|
try {
|
||||||
|
const dir = CLIUtils.resolveDirectory(options.dir);
|
||||||
|
const outputPath = CLIUtils.resolveOutputPath(options.output, options.format as 'json' | 'yaml');
|
||||||
|
|
||||||
|
const fileUtils = FileUtils.getInstance();
|
||||||
|
if (!(await fileUtils.fileExists(dir))) {
|
||||||
|
console.error(`Error: Directory not found: ${dir}`);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
let config: ContextConfig | undefined;
|
||||||
|
if (options.config) {
|
||||||
|
config = await ConfigLoader.load(options.config);
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
config = await ConfigLoader.load();
|
||||||
|
} catch {
|
||||||
|
config = await ConfigLoader.load();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
config.analyzeConventions = options.conventions !== false;
|
||||||
|
config.includeDevDependencies = options.includeDev === true;
|
||||||
|
config.respectGitignore = options.gitignore !== false;
|
||||||
|
config.outputFormat = options.format as 'json' | 'yaml';
|
||||||
|
config.template = options.template as 'default' | 'cursor' | 'copilot' | 'generic';
|
||||||
|
config.outputFile = options.output;
|
||||||
|
|
||||||
|
if (options.verbose) {
|
||||||
|
console.log('Analyzing directory:', dir);
|
||||||
|
console.log('Output file:', outputPath);
|
||||||
|
console.log('Format:', config.outputFormat);
|
||||||
|
console.log('Template:', config.template);
|
||||||
|
console.log('Analyzing conventions:', config.analyzeConventions);
|
||||||
|
console.log('Including dev deps:', config.includeDevDependencies);
|
||||||
|
console.log('Respecting .gitignore:', config.respectGitignore);
|
||||||
|
}
|
||||||
|
|
||||||
|
const generator = new ContextGenerator();
|
||||||
|
|
||||||
|
if (options.verbose) {
|
||||||
|
console.log('\nGenerating context...');
|
||||||
|
}
|
||||||
|
|
||||||
|
await generator.saveContext(dir, outputPath, config.outputFormat, config);
|
||||||
|
|
||||||
|
if (options.verbose) {
|
||||||
|
console.log(`\nContext saved to: ${outputPath}`);
|
||||||
|
} else {
|
||||||
|
console.log(`Context saved to: ${outputPath}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error generating context:', error instanceof Error ? error.message : error);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
main().catch(error => {
|
||||||
|
console.error('Fatal error:', error);
|
||||||
|
process.exit(1);
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user