Lit Showcase Hub
Explore a rich collection of modular Lit Web Components, prototypes, interactive instruments, databases, and custom UI modules. Select any example from the sidebar to preview in real-time with responsive viewport sandboxing.
const fs = require('fs'); const path = require('path'); const { execSync } = require('child_process'); const ROOT_DIR = __dirname; const DIST_DIR = path.join(ROOT_DIR, 'dist'); // Emojis for showcase listing const EMOJIS = { 'figma-to-lit': '🎨', 'figma_lit_example': '📐', 'lit-3d-piano': '🎹', 'lit-calculator': '🧮', 'lit-code-editor': '💻', 'lit-draggable-dom': '🖐️', 'lit-file-based-routing': '🚦', 'lit-force-graph': '🕸️', 'lit-html-editor': '✍️', 'lit-html-table': '📊', 'lit-modules': '📦', 'lit-native': '📱', 'lit-node-editor': '🪢', 'lit-sheet-music': '🎼', 'lit-starter-ts': '🚀', 'lit-vscode-extension': '🔌', 'lit-wmr': '⚡', 'vite-lit-capacitor': '🔋', 'vite-lit-element-starter': '🌱', 'vite-rxdb-lit': '💾' }; function checkPnpm() { try { execSync('pnpm --version', { stdio: 'ignore' }); return true; } catch (e) { return false; } } const hasPnpm = checkPnpm(); const pm = hasPnpm ? 'pnpm' : 'npm'; console.log(`Using package manager: ${pm}`); function buildProject(dirName) { const dirPath = path.join(ROOT_DIR, dirName); const pkgPath = path.join(dirPath, 'package.json'); if (!fs.existsSync(pkgPath)) { console.log(`[${dirName}] No package.json found. Copying static files directly.`); return { success: false, mode: 'static' }; } let pkg; try { pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8')); } catch (e) { console.error(`[${dirName}] Failed to parse package.json: ${e.message}`); return { success: false, mode: 'static' }; } // 1. Install dependencies console.log(`[${dirName}] Installing dependencies...`); try { const installCmd = pm === 'pnpm' ? 'pnpm install --no-frozen-lockfile' : 'npm install --no-audit --no-fund'; execSync(installCmd, { cwd: dirPath, stdio: 'inherit' }); } catch (e) { console.error(`[${dirName}] Dependency installation failed: ${e.message}`); // Proceed anyway, might be able to build or serve statically } // 2. Build if a build script exists if (pkg.scripts && pkg.scripts.build) { console.log(`[${dirName}] Running build script...`); try { execSync(`${pm} run build`, { cwd: dirPath, stdio: 'inherit' }); return { success: true, mode: 'build' }; } catch (e) { console.error(`[${dirName}] Build failed: ${e.message}. Falling back to static copy.`); return { success: false, mode: 'static' }; } } return { success: false, mode: 'static' }; } function copyOutput(dirName, buildResult) { const dirPath = path.join(ROOT_DIR, dirName); const destPath = path.join(DIST_DIR, dirName); if (fs.existsSync(destPath)) { fs.rmSync(destPath, { recursive: true, force: true }); } fs.mkdirSync(destPath, { recursive: true }); let srcPath = dirPath; if (buildResult.success) { // Check standard build output directories const candidates = ['dist', 'build', 'docs']; for (const cand of candidates) { const candPath = path.join(dirPath, cand); if (fs.existsSync(candPath) && fs.statSync(candPath).isDirectory()) { srcPath = candPath; break; } } } console.log(`[${dirName}] Copying from ${srcPath} to ${destPath}`); // Custom recursive copy to ignore node_modules, .git, etc. copyRecursiveSync(srcPath, destPath); } function copyRecursiveSync(src, dest) { const exists = fs.existsSync(src); const stats = exists && fs.statSync(src); const isDirectory = exists && stats.isDirectory(); if (isDirectory) { if (!fs.existsSync(dest)) { fs.mkdirSync(dest, { recursive: true }); } fs.readdirSync(src).forEach((childItemName) => { // Exclude heavy/unnecessary folders if (['node_modules', '.git', 'bazel-out', 'bazel-bin'].includes(childItemName)) { return; } copyRecursiveSync( path.join(src, childItemName), path.join(dest, childItemName) ); }); } else { // If it's a file, just copy it fs.copyFileSync(src, dest); } } function generateDashboard(projects) { console.log('Generating dashboard HTML...'); const projectListHtml = projects.map(p => { const emoji = EMOJIS[p.name] || '📦'; const cleanName = p.name .replace(/-/g, ' ') .replace(/_/g, ' ') .replace(/\b\w/g, c => c.toUpperCase()); return `
Explore a rich collection of modular Lit Web Components, prototypes, interactive instruments, databases, and custom UI modules. Select any example from the sidebar to preview in real-time with responsive viewport sandboxing.