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'); // 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]); } // Generate HTML for individual file pages function generateFileHTML(filePath, content, fileInfo) { const relativePath = path.relative(ROOT_DIR, filePath); const extension = path.extname(filePath); const language = extension === '.json' ? 'json' : extension === '.md' ? 'markdown' : 'text'; return ` ${escapeHtml(relativePath)} - System Prompts

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

Path: ${escapeHtml(relativePath)}
Size: ${fileInfo.size} bytes
Lines: ${content.split('\\n').length}
${escapeHtml(content)}
← Back to Index
`; } // Generate HTML for index page function generateIndexHTML(fileTree, stats) { return ` System Prompts and Models of AI Tools

šŸ“œ System Prompts and Models of AI Tools

A comprehensive collection of system prompts and configurations

${stats.totalFiles} Total Files
${stats.totalDirectories} Directories
${Math.round(stats.totalSize / 1024)}KB Total Size
${generateFileTreeHTML(fileTree)}
`; } // Generate HTML for file tree 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; } // 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 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(`\nšŸ“Š Statistics:`); console.log(` - Total files: ${stats.totalFiles}`); console.log(` - Total directories: ${stats.totalDirectories}`); console.log(` - Total size: ${Math.round(stats.totalSize / 1024)}KB\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 }); 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 index page...'); const indexHTML = generateIndexHTML(fileTree, stats); fs.writeFileSync(path.join(DIST_DIR, 'index.html'), indexHTML); console.log(' āœ“ Index page generated'); console.log('\n✨ Build completed successfully!'); console.log(`\nšŸ“ Output directory: ${DIST_DIR}`); console.log('🌐 Run "npm run preview" to view the site locally\n'); } // Run build try { build(); } catch (error) { console.error('āŒ Build failed:', error); process.exit(1); }