UNPKG

ai-code-to-project-files

Version:

A CLI tool to convert AI code responses with multiple file sections into organized project files

92 lines (73 loc) 2.49 kB
#!/usr/bin/env node const { generateFromFile } = require('../index'); const path = require('path'); // Display help information function showHelp() { console.log(` AI Code to Project Files CLI Usage: ai-code-to-files <input_file> [output_directory] Arguments: input_file Path to the .txt file containing AI artifact content output_directory Directory where files will be generated (default: ./generated_project) Options: -h, --help Show this help message -v, --version Show version number Examples: ai-code-to-files response.txt ai-code-to-files response.txt ./my-project ai-code-to-files /path/to/ai-response.txt ./output The input file should contain AI responses with file sections formatted like: # path/to/file.js file content here # another/file.css more content here `); } // Display version function showVersion() { const packageJson = require('../package.json'); console.log(`ai-code-to-project-files v${packageJson.version}`); } // Main CLI function async function cli() { const args = process.argv.slice(2); // Handle help and version flags if (args.includes('-h') || args.includes('--help') || args.length === 0) { showHelp(); process.exit(0); } if (args.includes('-v') || args.includes('--version')) { showVersion(); process.exit(0); } // Get input file and output directory const inputFilePath = args[0]; const outputDir = args[1] || './generated_project'; if (!inputFilePath) { console.error('Error: Please provide the path to the input file.'); console.error('Use --help for usage information.'); process.exit(1); } // Resolve absolute paths const absoluteInputPath = path.resolve(inputFilePath); const absoluteOutputPath = path.resolve(outputDir); console.log(`Processing: ${absoluteInputPath}`); console.log(`Output directory: ${absoluteOutputPath}`); console.log(''); // Generate project structure const result = await generateFromFile(absoluteInputPath, absoluteOutputPath); if (result.success) { console.log(''); console.log(`✅ ${result.message}`); console.log(`📁 Generated ${result.files} files in: ${absoluteOutputPath}`); } else { console.error('❌ Error:', result.error); process.exit(1); } } // Run CLI cli().catch(error => { console.error('❌ Unexpected error:', error.message); process.exit(1); });