UNPKG

ruch

Version:

Revolutionary React TypeScript CLI with hexagonal architecture & AI-powered development assistance. Create maintainable, scalable applications with domain-driven design and integrated AI tooling.

105 lines (92 loc) 2.92 kB
import { getEntityTemplate } from './entities'; import { getPortTemplate } from './ports'; import { getServicesTemplate } from './services'; import { getServicesTestTemplate } from './services.test'; import { getAdapterTemplate } from './adapters'; import { getAdapterTestTemplate } from './adapters.test'; import { getHookTemplate } from './hooks'; import { getHookTestTemplate } from './hooks.test'; import { getUiTemplate, getUiIndexTemplate } from './ui'; import { getUiTestTemplate } from './ui.test'; export interface DomainGenerationOptions { withUi: boolean; withStore: boolean; withQueries: boolean; withApi: boolean; } export interface GeneratedFile { path: string; content: string; } export async function generateDomainFiles(domainName: string, options: DomainGenerationOptions): Promise<void> { // Cette fonction sera appelée par DomainFactory qui gère la création des fichiers // Pour l'instant, on ne fait rien ici car DomainFactory doit être refactorisé } export function getDomainFiles(domainName: string, options: DomainGenerationOptions): GeneratedFile[] { const files: GeneratedFile[] = []; const capitalizedName = domainName.charAt(0).toUpperCase() + domainName.slice(1); // Entities files.push({ path: `entities/${capitalizedName}.ts`, content: getEntityTemplate(domainName) }); // Ports files.push({ path: `ports/${capitalizedName}Port.ts`, content: getPortTemplate(domainName) }); // Services files.push({ path: `services/${capitalizedName}Service.ts`, content: getServicesTemplate(domainName) }); files.push({ path: `services/${capitalizedName}Service.test.ts`, content: getServicesTestTemplate(domainName) }); // Adapters files.push({ path: `adapters/${capitalizedName}Adapter.ts`, content: getAdapterTemplate(domainName) }); files.push({ path: `adapters/${capitalizedName}Adapter.test.ts`, content: getAdapterTestTemplate(domainName) }); // Hooks files.push({ path: `hooks/use${capitalizedName}.ts`, content: getHookTemplate(domainName) }); files.push({ path: `hooks/use${capitalizedName}.test.tsx`, content: getHookTestTemplate(domainName) }); // UI if (options.withUi) { files.push({ path: `ui/${capitalizedName}View.tsx`, content: getUiTemplate(domainName) }); files.push({ path: `ui/index.ts`, content: getUiIndexTemplate(domainName) }); files.push({ path: `ui/${capitalizedName}View.test.tsx`, content: getUiTestTemplate(domainName) }); } return files; } export const getIndexTemplate = (domainName: string): string => { return `// Entry point for the ${domainName} domain // Exports all public elements of the domain export * from './types'; export * from './services'; export * from './api'; export * from './queries'; export * from './store'; export * from './ui'; `; }