@gati-framework/cli
Version:
CLI tool for Gati framework - create, develop, build and deploy cloud-native applications
81 lines ⢠3.32 kB
JavaScript
/**
* @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