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.

69 lines 3.18 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.DomainFactory = void 0; const fs_extra_1 = __importDefault(require("fs-extra")); const path_1 = __importDefault(require("path")); class DomainFactory { constructor(services) { this.services = services; } async createDomain(domainName, options) { const { logger, pathUtils, generateDomainFiles } = this.services; // Domain name validation if (!pathUtils.validateDomainName(domainName)) { logger.error(`Domain name "${domainName}" is not valid. Use only letters, numbers, hyphens and underscores.`); return; } const domainPath = pathUtils.getDomainPath(domainName); const domainsBasePath = pathUtils.getDomainsBasePath(); // Check if domain already exists if (await fs_extra_1.default.pathExists(domainPath)) { logger.error(`Domain "${domainName}" already exists in ${domainPath}`); return; } try { // Create src/domains folder if it doesn't exist await fs_extra_1.default.ensureDir(domainsBasePath); // Create domain structure logger.info(`Creating domain "${domainName}"...`); // Create all folders const folders = ['entities', 'ports', 'services', 'adapters', 'hooks']; if (options.withUi) folders.push('ui'); for (const folder of folders) { await fs_extra_1.default.ensureDir(path_1.default.join(domainPath, folder)); } // Generate and write all files const files = generateDomainFiles(domainName, options); for (const file of files) { await fs_extra_1.default.writeFile(path_1.default.join(domainPath, file.path), file.content, 'utf8'); } // Display summary logger.success(`Domain "${domainName}" created successfully!`); logger.info(`Location: ${domainPath}`); logger.info('Generated structure:'); logger.log(`├── entities/`); logger.log(`├── ports/`); logger.log(`├── services/`); logger.log(`├── adapters/`); logger.log(`├── hooks/`); if (options.withUi) logger.log(`├── ui/`); logger.log(`└── index.ts`); logger.info(`💡 You can now import the domain with: import { ... } from './src/domains/${domainName}'`); } catch (error) { logger.error(`Error creating domain: ${error instanceof Error ? error.message : 'Unknown error'}`); // Cleanup on error if (await fs_extra_1.default.pathExists(domainPath)) { await fs_extra_1.default.remove(domainPath); logger.info('Cleanup completed after error.'); } } } } exports.DomainFactory = DomainFactory; //# sourceMappingURL=domain-factory.js.map