#!/usr/bin/env node import { Command } from 'commander'; import chalk from 'chalk'; import { fileURLToPath } from 'url'; import { dirname, join } from 'path'; import { readFileSync } from 'fs'; // Import commands import { detectCommand } from './commands/detect.js'; import { initCommand } from './commands/init.js'; import { batchCommand } from './commands/batch.js'; // Get package.json for version const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); const packageJson = JSON.parse(readFileSync(join(__dirname, '..', 'package.json'), 'utf-8')); const program = new Command(); program .name('docker-deploy') .description('Automated Docker deployment system for containerizing and deploying projects') .version(packageJson.version); // Detect command - identify project type program .command('detect [path]') .description('Detect project type and show deployment recommendations') .option('--json', 'Output as JSON') .action(async (path, options) => { try { await detectCommand(path || process.cwd(), options); } catch (error) { console.error(chalk.red('Error:'), error.message); process.exit(1); } }); // Init command - initialize Docker config for a project program .command('init [path]') .description('Initialize Docker configuration for a project') .option('--no-interactive', 'Skip interactive prompts, use smart defaults') .option('--type ', 'Force specific project type') .option('--port ', 'Override default port', parseInt) .option('--name ', 'Override container name') .option('--dry-run', 'Show what would be generated without writing files') .option('--overwrite', 'Overwrite existing files') .action(async (path, options) => { try { await initCommand(path || process.cwd(), options); } catch (error) { console.error(chalk.red('Error:'), error.message); process.exit(1); } }); // Batch command - operations across multiple projects program .command('batch ') .description('Batch operations: detect, init') .option('--root ', 'Root directory containing projects', 'C:\\.bucket\\Repos.Git') .option('--filter ', 'Filter projects by pattern') .option('--exclude ', 'Exclude projects (comma-separated)') .option('--parallel ', 'Max parallel operations', parseInt, 4) .option('--report', 'Generate summary report') .option('--force', 'Force operation even if files exist') .action(async (action, options) => { try { await batchCommand(action, options); } catch (error) { console.error(chalk.red('Error:'), error.message); process.exit(1); } }); // Build command placeholder program .command('build') .description('Build Docker image for current project') .option('--platform ', 'Target platform', 'linux/amd64') .option('--tag ', 'Image tag') .option('--no-cache', 'Build without cache') .action(async (options) => { console.log(chalk.yellow('Build command - coming soon')); console.log('For now, use the generated deploy-docker-auto.ps1 or build-image-tar.ps1 scripts'); }); // Package command placeholder program .command('package') .description('Package Docker image as tar file') .option('--output ', 'Output tar file name') .option('--compress', 'Use gzip compression') .action(async (options) => { console.log(chalk.yellow('Package command - coming soon')); console.log('For now, use the generated build-image-tar.ps1 script'); }); // Deploy command placeholder program .command('deploy') .description('Deploy to Linux server via SSH') .option('--host ', 'SSH host') .option('--user ', 'SSH user') .option('--key ', 'SSH private key path') .option('--target ', 'Target directory on server') .action(async (options) => { console.log(chalk.yellow('Deploy command - coming soon')); console.log('For now, use the generated deploy-docker-auto.ps1 script'); }); program.parse();