const path = require('path'); const fs = require('fs'); const express = require('express'); function findSvgFiles(dir, relativePath = '') { let svgFiles = []; const items = fs.readdirSync(dir, { withFileTypes: true }); for (const item of items) { const fullPath = path.resolve(dir, item.name); const relativeItemPath = path.join(relativePath, item.name); if (item.isDirectory()) { const nestedSvgs = findSvgFiles(fullPath, relativeItemPath); svgFiles = svgFiles.concat(nestedSvgs); } else if (item.isFile() && item.name.endsWith('.svg')) { svgFiles.push(relativeItemPath); } } return svgFiles; } const svgDir = path.resolve(__dirname, '../../packages/web/components/common/Icon/icons'); const svgPaths = findSvgFiles(svgDir); const app = express(); app.use('/icons', express.static(svgDir)); app.get('/', (req, res) => { let iconHtml = ``; svgPaths.forEach((filePath) => { const name = filePath.split('.')[0]; const icon = fs.readFileSync(`${svgDir}/${filePath}`, 'utf8'); iconHtml += `
${icon}
${name}
`; }); const html = ` SVG Icons
${iconHtml}
`; res.send(html); }); const PORT = process.env.PORT || 3005; app.listen(PORT, () => { console.log(`Preview icons server running at http://localhost:${PORT}`); });