const fs = require('fs'); const path = require('path'); // Configuration const ROOT_DIR = path.join(__dirname, '..'); const DIST_DIR = path.join(__dirname, 'dist'); const FILES_DIR = path.join(DIST_DIR, 'files'); const METADATA_DIR = path.join(ROOT_DIR, 'metadata'); // Directories to exclude from scanning const EXCLUDED_DIRS = ['.git', 'node_modules', 'site', 'assets']; // File extensions to include const INCLUDED_EXTENSIONS = ['.txt', '.json', '.md']; // Utility function to escape HTML function escapeHtml(text) { const map = { '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }; return text.replace(/[&<>"']/g, m => map[m]); } // Load metadata files function loadMetadata() { const metadata = []; if (!fs.existsSync(METADATA_DIR)) { return metadata; } const files = fs.readdirSync(METADATA_DIR); for (const file of files) { if (file.endsWith('.json') && file !== 'README.md') { try { const content = fs.readFileSync(path.join(METADATA_DIR, file), 'utf-8'); metadata.push(JSON.parse(content)); } catch (error) { console.warn(`Warning: Could not load metadata from ${file}`); } } } return metadata; } // Generate enhanced HTML for individual file pages function generateFileHTML(filePath, content, fileInfo, metadata) { const relativePath = path.relative(ROOT_DIR, filePath); const extension = path.extname(filePath); const language = extension === '.json' ? 'json' : extension === '.md' ? 'markdown' : 'text'; const lines = content.split('\n'); return ` ${escapeHtml(relativePath)} - System Prompts

${escapeHtml(path.basename(filePath))}

Path: ${escapeHtml(relativePath)}
Size: ${fileInfo.size.toLocaleString()} bytes
Lines: ${lines.length.toLocaleString()}
Type: ${language}
${language}
${escapeHtml(content)}
← Back to Index ⬇ Download
`; } // Generate enhanced index HTML with search and filters function generateIndexHTML(fileTree, stats, metadata) { const metadataJson = JSON.stringify(metadata, null, 2); return ` System Prompts and Models of AI Tools

šŸ“œ System Prompts and Models of AI Tools

A comprehensive collection of system prompts and configurations from 30+ AI coding tools

${stats.totalFiles} Total Files
${stats.totalDirectories} Tool Directories
${Math.round(stats.totalSize / 1024)}KB Total Size
${metadata.length} Tools Documented
${generateFileTreeHTML(fileTree)}
${generateToolCardsHTML(metadata)}
${generateComparisonTableHTML(metadata)}
`; } // Generate file tree HTML function generateFileTreeHTML(tree) { let html = ''; const sortedDirs = Object.keys(tree).sort(); for (const dir of sortedDirs) { const files = tree[dir]; if (files.length === 0) continue; html += `
šŸ“ ${escapeHtml(dir)} ā–¼
`; } return html || '
No files found
'; } // Generate tool cards HTML function generateToolCardsHTML(metadata) { if (metadata.length === 0) { return '
No tools found
'; } let html = ''; for (const tool of metadata) { const tags = tool.tags || []; const tagsHTML = tags.slice(0, 3).map(tag => `${escapeHtml(tag)}`).join(''); html += `

${escapeHtml(tool.name)}

${escapeHtml(tool.description || 'No description available')}

${tagsHTML}
View Details →
`; } return html; } // Generate comparison table HTML function generateComparisonTableHTML(metadata) { if (metadata.length === 0) { return '
No tools available for comparison
'; } let html = `
`; for (const tool of metadata) { html += ` `; } html += `
Tool Type Pricing Agent Mode Parallel TODO System Memory
${escapeHtml(tool.name)} ${escapeHtml(tool.type)} ${escapeHtml(tool.pricing?.model || 'Unknown')} ${tool.features?.agentMode ? 'āœ…' : 'āŒ'} ${tool.features?.parallelExecution ? 'āœ…' : 'āŒ'} ${tool.features?.todoTracking ? 'āœ…' : 'āŒ'} ${tool.features?.memorySystem ? 'āœ…' : 'āŒ'}
`; return html; } // Scan directory recursively function scanDirectory(dir, baseDir = dir, fileTree = {}, stats = { totalFiles: 0, totalDirectories: 0, totalSize: 0 }) { const items = fs.readdirSync(dir); for (const item of items) { const fullPath = path.join(dir, item); const relativePath = path.relative(baseDir, fullPath); // Skip excluded directories if (EXCLUDED_DIRS.some(excluded => relativePath.startsWith(excluded))) { continue; } const stat = fs.statSync(fullPath); if (stat.isDirectory()) { stats.totalDirectories++; scanDirectory(fullPath, baseDir, fileTree, stats); } else if (stat.isFile()) { const ext = path.extname(fullPath); if (INCLUDED_EXTENSIONS.includes(ext)) { const dirName = path.dirname(relativePath); const displayDir = dirName === '.' ? 'Root' : dirName; if (!fileTree[displayDir]) { fileTree[displayDir] = []; } stats.totalFiles++; stats.totalSize += stat.size; fileTree[displayDir].push({ name: path.basename(fullPath), path: fullPath, relativePath: relativePath, id: Buffer.from(relativePath).toString('base64').replace(/[^a-zA-Z0-9]/g, '_'), size: stat.size }); } } } return { fileTree, stats }; } // Main build function function build() { console.log('šŸš€ Starting enhanced build process...\n'); // Clean and create dist directories if (fs.existsSync(DIST_DIR)) { fs.rmSync(DIST_DIR, { recursive: true }); } fs.mkdirSync(DIST_DIR, { recursive: true }); fs.mkdirSync(FILES_DIR, { recursive: true }); console.log('šŸ“‚ Scanning repository...'); const { fileTree, stats } = scanDirectory(ROOT_DIR); console.log('šŸ“Š Loading metadata...'); const metadata = loadMetadata(); console.log(`\nšŸ“Š Statistics:`); console.log(` - Total files: ${stats.totalFiles}`); console.log(` - Total directories: ${stats.totalDirectories}`); console.log(` - Total size: ${Math.round(stats.totalSize / 1024)}KB`); console.log(` - Tools with metadata: ${metadata.length}\n`); // Generate individual file pages console.log('šŸ“ Generating file pages...'); let generatedPages = 0; for (const dir in fileTree) { for (const file of fileTree[dir]) { try { const content = fs.readFileSync(file.path, 'utf-8'); const html = generateFileHTML(file.path, content, { size: file.size }, metadata); const outputPath = path.join(FILES_DIR, `${file.id}.html`); fs.writeFileSync(outputPath, html); generatedPages++; } catch (error) { console.error(` āš ļø Error processing ${file.relativePath}: ${error.message}`); } } } console.log(` āœ“ Generated ${generatedPages} file pages`); // Generate index page console.log('\nšŸ“„ Generating enhanced index page...'); const indexHTML = generateIndexHTML(fileTree, stats, metadata); fs.writeFileSync(path.join(DIST_DIR, 'index.html'), indexHTML); console.log(' āœ“ Index page generated with search, filters, and comparison'); console.log('\n✨ Enhanced build completed successfully!'); console.log(`\nšŸ“ Output directory: ${DIST_DIR}`); console.log('🌐 Open dist/index.html to view the site\n'); console.log('✨ New features:'); console.log(' • šŸ” Search across all files and tools'); console.log(' • šŸŽØ Dark/Light theme toggle'); console.log(' • šŸ·ļø Filter by type, pricing, and features'); console.log(' • šŸ“‹ Copy code with one click'); console.log(' • šŸ“Š Comparison table view'); console.log(' • šŸ“± Mobile-responsive design\n'); } // Run build try { build(); } catch (error) { console.error('āŒ Build failed:', error); process.exit(1); }