UNPKG

@vladimirdukelic/revolutionary-ui-factory

Version:

Revolutionary UI Factory System v2 - Generate ANY UI component for ANY framework with 60-95% code reduction

462 lines 16.9 kB
"use strict"; /** * Revolutionary UI Factory - Project Detector * Analyzes project structure and detects installed frameworks, libraries, and tools */ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.ProjectDetector = void 0; const fs = __importStar(require("fs")); const path = __importStar(require("path")); const frameworks_1 = require("../../config/frameworks"); const ui_libraries_1 = require("../../config/ui-libraries"); const icon_libraries_1 = require("../../config/icon-libraries"); const design_tools_1 = require("../../config/design-tools"); class ProjectDetector { projectPath; packageJson; packageLockJson; dependencies = {}; devDependencies = {}; constructor(projectPath = process.cwd()) { this.projectPath = projectPath; } /** * Main analysis function */ async analyze() { // Load package.json await this.loadPackageJson(); // Detect package manager const packageManager = this.detectPackageManager(); // Merge dependencies this.dependencies = { ...this.packageJson.dependencies || {} }; this.devDependencies = { ...this.packageJson.devDependencies || {} }; // Detect all components const frameworks = this.detectFrameworks(); const uiLibraries = this.detectUILibraries(); const iconLibraries = this.detectIconLibraries(); const designTools = this.detectDesignTools(); const colorTools = this.detectColorTools(); const fonts = this.detectFonts(); const utilities = this.detectUtilities(); const buildTools = this.detectBuildTools(); // Check for common tools const hasTypeScript = this.hasTypeScript(); const hasTailwind = this.hasTailwind(); const hasESLint = this.hasESLint(); const hasPrettier = this.hasPrettier(); const testingFrameworks = this.detectTestingFrameworks(); // Generate recommendations const recommendations = this.generateRecommendations({ frameworks, uiLibraries, iconLibraries, hasTypeScript, hasTailwind }); return { projectName: this.packageJson.name || 'unknown', projectPath: this.projectPath, packageManager, frameworks, uiLibraries, iconLibraries, designTools, colorTools, fonts, utilities, buildTools, hasTypeScript, hasTailwind, hasESLint, hasPrettier, testingFrameworks, recommendations }; } /** * Load package.json */ async loadPackageJson() { const packageJsonPath = path.join(this.projectPath, 'package.json'); if (!fs.existsSync(packageJsonPath)) { throw new Error('No package.json found in the project directory'); } const content = fs.readFileSync(packageJsonPath, 'utf-8'); this.packageJson = JSON.parse(content); } /** * Detect package manager */ detectPackageManager() { if (fs.existsSync(path.join(this.projectPath, 'bun.lockb'))) return 'bun'; if (fs.existsSync(path.join(this.projectPath, 'pnpm-lock.yaml'))) return 'pnpm'; if (fs.existsSync(path.join(this.projectPath, 'yarn.lock'))) return 'yarn'; return 'npm'; } /** * Detect installed frameworks */ detectFrameworks() { const detected = []; for (const framework of frameworks_1.FRAMEWORK_CONFIGS) { const isInstalled = this.isPackageInstalled(framework.packageName); const currentVersion = this.getPackageVersion(framework.packageName); detected.push({ name: framework.name, version: framework.version, type: 'framework', installed: isInstalled, currentVersion, latestVersion: framework.version, needsUpdate: currentVersion ? this.needsUpdate(currentVersion, framework.version) : false }); } // Also check for common frameworks not in our config const additionalFrameworks = [ { name: 'gatsby', display: 'Gatsby' }, { name: 'remix', display: 'Remix' }, { name: 'astro', display: 'Astro' }, { name: 'vitepress', display: 'VitePress' } ]; for (const fw of additionalFrameworks) { if (this.isPackageInstalled(fw.name)) { detected.push({ name: fw.display, version: this.getPackageVersion(fw.name) || 'unknown', type: 'framework', installed: true, currentVersion: this.getPackageVersion(fw.name) }); } } return detected; } /** * Detect UI libraries */ detectUILibraries() { const detected = []; for (const lib of ui_libraries_1.UI_LIBRARIES) { const isInstalled = this.isPackageInstalled(lib.packageName); const currentVersion = this.getPackageVersion(lib.packageName); detected.push({ name: lib.name, version: lib.version, type: 'ui-library', installed: isInstalled, currentVersion, latestVersion: lib.version, needsUpdate: currentVersion ? this.needsUpdate(currentVersion, lib.version) : false }); } return detected; } /** * Detect icon libraries */ detectIconLibraries() { const detected = []; for (const lib of icon_libraries_1.ICON_LIBRARIES) { const isInstalled = this.isPackageInstalled(lib.packageName); const currentVersion = this.getPackageVersion(lib.packageName); detected.push({ name: lib.name, version: lib.version, type: 'icon-library', installed: isInstalled, currentVersion, latestVersion: lib.version, needsUpdate: currentVersion ? this.needsUpdate(currentVersion, lib.version) : false }); } return detected; } /** * Detect design tools */ detectDesignTools() { const detected = []; for (const tool of design_tools_1.DESIGN_TOOLS) { const isInstalled = this.isPackageInstalled(tool.packageName); const currentVersion = this.getPackageVersion(tool.packageName); detected.push({ name: tool.name, version: tool.version, type: 'design-tool', installed: isInstalled, currentVersion, latestVersion: tool.version, needsUpdate: currentVersion ? this.needsUpdate(currentVersion, tool.version) : false }); } return detected; } /** * Detect color tools */ detectColorTools() { const detected = []; for (const tool of design_tools_1.COLOR_TOOLS) { const isInstalled = this.isPackageInstalled(tool.packageName); const currentVersion = this.getPackageVersion(tool.packageName); detected.push({ name: tool.name, version: tool.version, type: 'color-tool', installed: isInstalled, currentVersion, latestVersion: tool.version, needsUpdate: currentVersion ? this.needsUpdate(currentVersion, tool.version) : false }); } return detected; } /** * Detect fonts */ detectFonts() { const detected = []; for (const font of design_tools_1.FONTS) { const isInstalled = this.isPackageInstalled(font.packageName); const currentVersion = this.getPackageVersion(font.packageName); detected.push({ name: font.name, version: font.version, type: 'font', installed: isInstalled, currentVersion, latestVersion: font.version, needsUpdate: currentVersion ? this.needsUpdate(currentVersion, font.version) : false }); } return detected; } /** * Detect common utilities */ detectUtilities() { const utilities = [ { name: 'clsx', display: 'clsx' }, { name: 'classnames', display: 'classnames' }, { name: 'tailwind-merge', display: 'Tailwind Merge' }, { name: 'class-variance-authority', display: 'CVA' }, { name: 'framer-motion', display: 'Framer Motion' }, { name: 'zod', display: 'Zod' }, { name: 'react-hook-form', display: 'React Hook Form' }, { name: 'axios', display: 'Axios' }, { name: 'swr', display: 'SWR' }, { name: '@tanstack/react-query', display: 'React Query' } ]; return utilities .filter(util => this.isPackageInstalled(util.name)) .map(util => ({ name: util.display, version: this.getPackageVersion(util.name) || 'unknown', type: 'utility', installed: true, currentVersion: this.getPackageVersion(util.name) })); } /** * Detect build tools */ detectBuildTools() { const tools = []; const buildTools = [ 'webpack', 'vite', 'parcel', 'rollup', 'esbuild', 'turbo', 'nx', 'lerna', 'rush' ]; for (const tool of buildTools) { if (this.isPackageInstalled(tool)) { tools.push(tool); } } return tools; } /** * Detect testing frameworks */ detectTestingFrameworks() { const frameworks = []; const testingTools = [ 'jest', 'vitest', 'mocha', 'jasmine', '@testing-library/react', '@testing-library/vue', 'cypress', 'playwright', '@playwright/test', 'puppeteer', 'karma' ]; for (const tool of testingTools) { if (this.isPackageInstalled(tool)) { frameworks.push(tool); } } return frameworks; } /** * Check if TypeScript is installed */ hasTypeScript() { return this.isPackageInstalled('typescript') || fs.existsSync(path.join(this.projectPath, 'tsconfig.json')); } /** * Check if Tailwind is installed */ hasTailwind() { return this.isPackageInstalled('tailwindcss') || fs.existsSync(path.join(this.projectPath, 'tailwind.config.js')) || fs.existsSync(path.join(this.projectPath, 'tailwind.config.ts')); } /** * Check if ESLint is installed */ hasESLint() { return this.isPackageInstalled('eslint') || fs.existsSync(path.join(this.projectPath, '.eslintrc.js')) || fs.existsSync(path.join(this.projectPath, '.eslintrc.json')); } /** * Check if Prettier is installed */ hasPrettier() { return this.isPackageInstalled('prettier') || fs.existsSync(path.join(this.projectPath, '.prettierrc')); } /** * Check if a package is installed */ isPackageInstalled(packageName) { return packageName in this.dependencies || packageName in this.devDependencies; } /** * Get package version */ getPackageVersion(packageName) { return this.dependencies[packageName] || this.devDependencies[packageName]; } /** * Check if package needs update */ needsUpdate(currentVersion, latestVersion) { // Simple version comparison - in real app would use semver const current = currentVersion.replace(/[\^~]/, '').split('.').map(Number); const latest = latestVersion.split('.').map(Number); for (let i = 0; i < 3; i++) { if ((latest[i] || 0) > (current[i] || 0)) return true; if ((latest[i] || 0) < (current[i] || 0)) return false; } return false; } /** * Generate recommendations based on analysis */ generateRecommendations(analysis) { const recommendations = []; // Check if any framework is installed const hasFramework = analysis.frameworks.some(f => f.installed); if (!hasFramework) { recommendations.push({ type: 'framework', packages: ['react', 'vue', 'angular'], reason: 'No framework detected. Consider installing a modern framework.', priority: 'high' }); } // Check for UI libraries const hasUILibrary = analysis.uiLibraries.some(lib => lib.installed); if (!hasUILibrary && hasFramework) { const framework = analysis.frameworks.find(f => f.installed); if (framework?.name.toLowerCase().includes('react')) { recommendations.push({ type: 'ui-library', packages: ['@mui/material', '@chakra-ui/react', 'antd'], reason: 'No UI library detected. These libraries work great with React.', priority: 'medium' }); } } // Check for icon libraries const hasIconLibrary = analysis.iconLibraries.some(lib => lib.installed); if (!hasIconLibrary) { recommendations.push({ type: 'icon-library', packages: ['lucide-react', 'react-icons', '@heroicons/react'], reason: 'No icon library detected. Icons are essential for modern UIs.', priority: 'medium' }); } // TypeScript recommendation if (!analysis.hasTypeScript) { recommendations.push({ type: 'development', packages: ['typescript', '@types/react', '@types/node'], reason: 'TypeScript provides better type safety and developer experience.', priority: 'high' }); } // Tailwind recommendation if (!analysis.hasTailwind) { recommendations.push({ type: 'styling', packages: ['tailwindcss', '@tailwindcss/forms', '@tailwindcss/typography'], reason: 'Tailwind CSS enables rapid UI development with utility classes.', priority: 'medium' }); } // Check for packages that need updates const needsUpdate = [ ...analysis.frameworks, ...analysis.uiLibraries, ...analysis.iconLibraries ].filter(pkg => pkg.needsUpdate); if (needsUpdate.length > 0) { recommendations.push({ type: 'updates', packages: needsUpdate.map(pkg => pkg.name), reason: `${needsUpdate.length} packages have newer versions available.`, priority: 'low' }); } return recommendations; } } exports.ProjectDetector = ProjectDetector; //# sourceMappingURL=project-detector.js.map