All files / packages/cli/src index.js

25.39% Statements 16/63
0% Branches 0/1
0% Functions 0/1
25.39% Lines 16/63

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 861x 1x 1x 1x               1x           1x 1x   1x 1x 1x 1x 1x 1x 1x       1x                                                                                                           1x  
/**
 * Coherent.js CLI - Main entry point
 * Provides project scaffolding, component generation, and build tools
 */
 
import { Command } from 'commander';
import { readFileSync } from 'fs';
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
import picocolors from 'picocolors';
 
// Import commands
import { createCommand } from './commands/create.js';
import { generateCommand } from './commands/generate.js';
import { buildCommand } from './commands/build.js';
import { devCommand } from './commands/dev.js';
 
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
 
// Get package version
let version = '1.0.1';
try {
  const packagePath = join(__dirname, '..', 'package.json');
  const packageJson = JSON.parse(readFileSync(packagePath, 'utf-8'));
  version = packageJson.version;
} catch (error) {
  // Use fallback version
}
 
export async function createCLI() {
  const program = new Command();
 
  program
    .name('coherent')
    .description(picocolors.cyan('🚀 Coherent.js CLI - Build modern web applications with pure JavaScript objects'))
    .version(version, '-v, --version', 'display version number');
 
  // Banner
  const banner = `
${picocolors.cyan('  ╔══════════════════════════════════════╗')}
${picocolors.cyan('  ║')}  ${picocolors.bold('🚀 Coherent.js CLI')}                 ${picocolors.cyan('║')}
${picocolors.cyan('  ║')}  ${picocolors.gray('Pure objects, pure performance')}      ${picocolors.cyan('║')}
${picocolors.cyan('  ╚══════════════════════════════════════╝')}
  `;
 
  // Add commands
  program
    .addCommand(createCommand)
    .addCommand(generateCommand)
    .addCommand(buildCommand)
    .addCommand(devCommand);
 
  // Custom help
  program.configureHelp({
    beforeAll: () => banner,
    afterAll: () => `
${picocolors.gray('Examples:')}
  ${picocolors.green('coherent create my-app')}           Create a new project
  ${picocolors.green('coherent generate component Button')} Generate a component  
  ${picocolors.green('coherent generate page Home')}       Generate a page
  ${picocolors.green('coherent build')}                   Build for production
  ${picocolors.green('coherent dev')}                     Start development server
 
${picocolors.gray('Learn more:')} ${picocolors.blue('https://github.com/Tomdrouv1/coherent.js')}
`
  });
 
  // Handle no command
  if (process.argv.length === 2) {
    console.log(banner);
    program.help();
    return;
  }
 
  // Parse arguments
  try {
    await program.parseAsync(process.argv);
  } catch (error) {
    console.error(picocolors.red('❌ Error:'), error.message);
    process.exit(1);
  }
}
 
// Export for direct usage
export { createCommand, generateCommand, buildCommand, devCommand };