import { existsSync, readdirSync } from 'fs'; import { join } from 'path'; import { glob } from 'glob'; /** * Detect static site or Flutter web project */ export async function detectStatic(projectPath) { // Check for Flutter project first const pubspecPath = join(projectPath, 'pubspec.yaml'); if (existsSync(pubspecPath)) { return { type: 'flutter-web', dockerizable: true, template: 'static/nginx', port: 80, entryPoint: null, buildCommand: 'flutter build web', description: 'Flutter web application (builds to static files)', buildDir: 'build/web', note: 'Run "flutter build web" before Docker build' }; } // Check for index.html (static site) const indexPath = join(projectPath, 'index.html'); const hasIndexHtml = existsSync(indexPath); // Check for common static site directories const hasPublicDir = existsSync(join(projectPath, 'public', 'index.html')); const hasDistDir = existsSync(join(projectPath, 'dist', 'index.html')); const hasBuildDir = existsSync(join(projectPath, 'build', 'index.html')); if (!hasIndexHtml && !hasPublicDir && !hasDistDir && !hasBuildDir) { return null; } // Determine the source directory let sourceDir = '.'; if (hasPublicDir) sourceDir = 'public'; else if (hasDistDir) sourceDir = 'dist'; else if (hasBuildDir) sourceDir = 'build'; // Check for PHP files (simple PHP site) const phpFiles = await glob('*.php', { cwd: projectPath }); if (phpFiles.length > 0) { return { type: 'static-php', dockerizable: true, template: 'static/php', port: 80, entryPoint: null, buildCommand: null, description: 'PHP static site', sourceDir, note: 'Uses PHP-FPM with Nginx' }; } // Pure static site (HTML/CSS/JS) return { type: 'static-nginx', dockerizable: true, template: 'static/nginx', port: 80, entryPoint: null, buildCommand: null, description: 'Static website (served by Nginx)', sourceDir }; } /** * Get additional info about static site */ export async function getStaticInfo(projectPath) { const info = { hasIndexHtml: existsSync(join(projectPath, 'index.html')), hasPackageJson: existsSync(join(projectPath, 'package.json')), files: { html: (await glob('**/*.html', { cwd: projectPath, ignore: 'node_modules/**' })).length, css: (await glob('**/*.css', { cwd: projectPath, ignore: 'node_modules/**' })).length, js: (await glob('**/*.js', { cwd: projectPath, ignore: 'node_modules/**' })).length, php: (await glob('**/*.php', { cwd: projectPath, ignore: 'node_modules/**' })).length }, directories: [] }; // Check for common directories const dirs = ['public', 'dist', 'build', 'assets', 'css', 'js', 'images']; for (const dir of dirs) { if (existsSync(join(projectPath, dir))) { info.directories.push(dir); } } return info; }