UNPKG

@gati-framework/cli

Version:

CLI tool for Gati framework - create, develop, build and deploy cloud-native applications

81 lines • 3.32 kB
/** * @module cli/commands/analyze * @description Analyze project and generate config/types */ import { Command } from 'commander'; import chalk from 'chalk'; import { analyzeProject } from '../analyzer/handler-analyzer.js'; // import { generateConfig, generateTypes } from '../analyzer/manifest-generator.js'; import { writeFileSync, mkdirSync, existsSync } from 'fs'; import { resolve } from 'path'; /** * Analyze project command */ async function analyzeProjectCommand(cwd, options) { try { console.log(chalk.blue('šŸ” Analyzing project...')); const manifest = analyzeProject(cwd); // Show analysis results console.log(chalk.green(`āœ… Found ${manifest.handlers.length} handlers`)); console.log(chalk.green(`āœ… Found ${manifest.modules.length} modules`)); if (manifest.conflicts.length > 0) { console.log(chalk.red('āš ļø Route conflicts detected:')); manifest.conflicts.forEach(conflict => { console.log(chalk.red(` ${conflict}`)); }); } // Generate config if requested if (options.config !== false) { // generateConfig(manifest, cwd); console.log(chalk.yellow('āš ļø Config generation not yet implemented')); } // Generate types if requested if (options.types !== false) { // const typesContent = generateTypes(manifest); // const typesDir = resolve(cwd, '.gati'); // const typesPath = resolve(typesDir, 'types.d.ts'); // if (!existsSync(typesDir)) { // mkdirSync(typesDir, { recursive: true }); // } // writeFileSync(typesPath, typesContent); console.log(chalk.yellow('āš ļø Type generation not yet implemented')); } // Show route tree console.log(chalk.blue('\nšŸ“‹ Route Tree:')); printRouteTree(manifest.routeTree); } catch (error) { console.error(chalk.red('āœ– Analysis failed:'), error); process.exit(1); } } /** * Print route tree */ function printRouteTree(node, prefix = '', isLast = true) { const connector = isLast ? '└── ' : 'ā”œā”€ā”€ '; const path = node.path === '/' ? '/' : node.path; if (node.handler) { const method = node.handler.method || 'GET'; console.log(chalk.gray(prefix + connector) + chalk.cyan(path) + chalk.yellow(` [${method}]`)); } else if (node.children.size > 0) { console.log(chalk.gray(prefix + connector) + chalk.white(path + '/')); } const children = Array.from(node.children.values()); children.forEach((child, index) => { const isChildLast = index === children.length - 1; const childPrefix = prefix + (isLast ? ' ' : '│ '); printRouteTree(child, childPrefix, isChildLast); }); } export const analyzeCommand = new Command('analyze') .description('Analyze project handlers and generate config/types') .option('--no-config', 'Skip generating gati.config.ts') .option('--no-types', 'Skip generating types') .option('-w, --watch', 'Watch for changes and re-analyze') .action(async (options) => { const cwd = process.cwd(); await analyzeProjectCommand(cwd, options); }); //# sourceMappingURL=analyze.js.map