import * as path from 'path'; import * as fs from 'fs/promises'; import { EnhancedModel } from '../utils/types'; import { toKebabCase } from '../../utils/string-formatter'; /** * Generate model index file to export all DTOs */ export async function generateModelIndexFile(model: EnhancedModel, outputDir: string): Promise { const modelName = model.name; const indexFilePath = path.join(outputDir, 'dto', 'index.ts'); // Check if index file already exists try { await fs.access(indexFilePath); // File exists, don't overwrite it return; } catch (error) { // File doesn't exist, create it let content = `export * from './create-${toKebabCase(modelName)}.dto';\n`; content += `export * from './update-${toKebabCase(modelName)}.dto';\n`; content += `export * from './find-many-${toKebabCase(modelName)}.dto';\n`; content += `export * from './flat-query-${toKebabCase(modelName)}.dto';\n`; content += `export * from './${toKebabCase(modelName)}.dto';\n`; content += `export * from './${toKebabCase(modelName)}-id.dto';\n`; content += `export * from './${toKebabCase(modelName)}-list.dto';\n`; await fs.mkdir(path.dirname(indexFilePath), { recursive: true }); await fs.writeFile(indexFilePath, content); } }