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.

113 lines 4.82 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.listDomains = void 0; const fs_extra_1 = __importDefault(require("fs-extra")); const path_1 = __importDefault(require("path")); const logger_1 = require("../utils/logger"); const paths_1 = require("../utils/paths"); const file_operations_1 = require("../utils/file-operations"); const logging_1 = require("../utils/logging"); // Pure functions const buildDomainDirectoryPath = (basePath, domainName) => path_1.default.join(basePath, domainName); const isDirectory = (stats) => stats.isDirectory(); const sortDomainFolders = (folders) => { const folderOrder = ['entities', 'ports', 'services', 'adapters', 'hooks', 'ui']; return folders.sort((a, b) => { const aIndex = folderOrder.indexOf(a); const bIndex = folderOrder.indexOf(b); if (aIndex === -1 && bIndex === -1) return a.localeCompare(b); if (aIndex === -1) return 1; if (bIndex === -1) return -1; return aIndex - bIndex; }); }; const getDomainDisplayIcon = (index, total) => index === total - 1 ? '└──' : '├──'; const getFolderDisplayIcon = (folderIndex, totalFolders, isLastDomain) => { if (folderIndex === totalFolders - 1 && isLastDomain) return ' └──'; if (folderIndex === totalFolders - 1) return '│ └──'; if (isLastDomain) return ' ├──'; return '│ ├──'; }; // Domain operations const getDomainFolderStructure = async (fileSystem, domainPath) => { const directoryEntries = await (0, file_operations_1.readDirectory)(fileSystem, domainPath); const domainFolders = []; for (const entry of directoryEntries) { const entryPath = path_1.default.join(domainPath, entry); const stats = await (0, file_operations_1.getFileMetadata)(fileSystem, entryPath); if (isDirectory(stats)) { domainFolders.push(entry); } } return sortDomainFolders(domainFolders); }; const analyzeDomainStructures = async (fileSystem, basePath, entries) => { const domainStructures = []; for (const entry of entries) { const entryPath = buildDomainDirectoryPath(basePath, entry); const stats = await (0, file_operations_1.getFileMetadata)(fileSystem, entryPath); if (isDirectory(stats)) { const folders = await getDomainFolderStructure(fileSystem, entryPath); domainStructures.push({ name: entry, path: entryPath, folders }); } } return domainStructures; }; // Display operations const formatDomainDisplay = (domain, index, total) => { const icon = getDomainDisplayIcon(index, total); const folders = domain.folders.map((folder, folderIndex) => ({ icon: getFolderDisplayIcon(folderIndex, domain.folders.length, index === total - 1), name: folder })); return { icon, name: domain.name, folders }; }; const displayDomainStructure = (log, display) => { log.log(`${display.icon} 📁 ${display.name}`); display.folders.forEach(folder => { log.log(`${folder.icon} 📂 ${folder.name}`); }); }; const displayDomainSeparator = (log, index, total) => { if (index < total - 1) { log.log('│'); } }; // Main function const listDomains = async (fileSystem = fs_extra_1.default, log = logger_1.logger) => { const domainsSourcePath = (0, paths_1.getDomainsSourceDirectoryPath)(); try { if (!(await (0, file_operations_1.validateFileExists)(fileSystem, domainsSourcePath))) { (0, logging_1.logNoDomainsFound)(log, domainsSourcePath); return; } const directoryEntries = await (0, file_operations_1.readDirectory)(fileSystem, domainsSourcePath); const domainStructures = await analyzeDomainStructures(fileSystem, domainsSourcePath, directoryEntries); if (domainStructures.length === 0) { (0, logging_1.logNoDomainsFound)(log, domainsSourcePath); return; } (0, logging_1.logDomainsListed)(log, domainStructures.length, domainsSourcePath); log.log(''); domainStructures.forEach((domain, index) => { const display = formatDomainDisplay(domain, index, domainStructures.length); displayDomainStructure(log, display); displayDomainSeparator(log, index, domainStructures.length); }); log.log(''); } catch (error) { (0, logging_1.logError)(log, `Error reading domains: ${error instanceof Error ? error.message : 'Unknown error'}`); } }; exports.listDomains = listDomains; //# sourceMappingURL=list.js.map