UNPKG

create-ai-context

Version:

šŸ¤– Generate AI-optimized project documentation and context files for better AI-assisted development. Creates structured templates with version control, architectural documentation, and clear guidelines for AI tools like Claude Code, GitHub Copilot, and Ch

157 lines (135 loc) • 4.43 kB
#!/usr/bin/env node const path = require('path'); const { createAIContext, validateAndPromptPath } = require('../src/index.js'); function parseArgs() { const args = process.argv.slice(2); const options = { path: null, agent: null, help: false, version: false, isDirectMode: false, force: false }; for (let i = 0; i < args.length; i++) { const arg = args[i]; switch (arg) { case '--help': case '-h': options.help = true; break; case '--version': case '-v': options.version = true; break; case '--path': if (i + 1 < args.length) { options.path = args[i + 1]; options.isDirectMode = true; i++; // Skip next argument as it's the path value } else { console.error('Error: --path requires a directory path'); process.exit(1); } break; case '--agent': if (i + 1 < args.length) { options.agent = args[i + 1]; options.isDirectMode = true; i++; } else { console.error('Error: --agent requires an agent name (claude, claude-code, cursor, codex, other)'); process.exit(1); } break; case '--force': case '-f': options.force = true; break; default: // Unknown argument if (arg.startsWith('-')) { console.error(`Unknown option: ${arg}`); console.error('Use --help for usage information'); process.exit(1); } else { console.error(`Unknown argument: ${arg}`); console.error('Use --help for usage information'); process.exit(1); } } } // Validate direct mode - must have both --agent and --path if (options.isDirectMode && (!options.agent || !options.path)) { console.error('Error: Direct mode requires both --agent and --path'); console.error('Usage: npx create-ai-context --agent <name> --path <directory>'); process.exit(1); } // Default to current directory for interactive mode if (!options.isDirectMode) { options.path = process.cwd(); } return options; } function showHelp() { console.log(` šŸ¤– create-ai-context - Generate AI-optimized project documentation USAGE: npx create-ai-context # Interactive mode npx create-ai-context --agent <name> --path <dir> # Direct mode OPTIONS: --agent <name> AI agent: claude, claude-code, cursor, codex, other (required for direct mode) --path <directory> Target directory (required for direct mode) -h, --help Show this help message -v, --version Show version number MODES: Interactive Mode: npx create-ai-context • Prompts for target directory (default: current) • Prompts for AI agent selection (claude as default) • Uses smart defaults - AI agents handle project analysis Direct Mode: npx create-ai-context --agent cursor --path ./my-project • Requires both --agent and --path • No prompts, uses smart defaults • Perfect for automation GENERATED FILES: Root directory: DEVELOPMENT_PLAN.md # Project roadmap and development guidelines ARCHITECTURE.md # Technical architecture and code standards ai-instructions.md # Step-by-step AI agent setup guidance For more information, visit: https://bishnubista.github.io/create-ai-context `); } function showVersion() { const packageJson = require('../package.json'); console.log(`create-ai-context v${packageJson.version}`); } // Parse command line arguments const options = parseArgs(); // Handle help and version if (options.help) { showHelp(); process.exit(0); } if (options.version) { showVersion(); process.exit(0); } // Main execution with path validation async function main() { try { // Resolve the initial target path const initialPath = path.resolve(process.cwd(), options.path); // Validate and get the final target path const validatedPath = await validateAndPromptPath(initialPath, options.isDirectMode); // Run the creation process await createAIContext(validatedPath, options); // Success message is now handled in createAIContext } catch (error) { console.error('āŒ Error creating AI context files:', error.message); process.exit(1); } } // Run the main function main();