#!/usr/bin/env node /** * Serves storybook-static on port 6007 for Playwright/audit. * If storybook-static is missing, serves a stub so index.json returns { entries: {} } * and tests can skip with "Run npm run build-storybook first". */ const http = require('http'); const fs = require('fs'); const path = require('path'); const { spawn } = require('child_process'); const PORT = 6007; const staticDir = path.join(process.cwd(), 'storybook-static'); const indexPath = path.join(staticDir, 'index.json'); if (fs.existsSync(indexPath)) { const proc = spawn('npx', ['serve', 'storybook-static', '-l', String(PORT)], { stdio: 'inherit', shell: true, cwd: process.cwd(), }); proc.on('error', (err) => { console.error(err); process.exit(1); }); proc.on('exit', (code) => process.exit(code ?? 0)); } else { const stubIndex = JSON.stringify({ entries: {} }); const server = http.createServer((req, res) => { if (req.url === '/index.json' || req.url === '/') { res.setHeader('Content-Type', 'application/json'); res.end(stubIndex); return; } res.statusCode = 404; res.end('Not found. Run npm run build-storybook first.'); }); server.listen(PORT, () => { console.log(`Stub Storybook server at http://localhost:${PORT} (no storybook-static; run build-storybook first)`); }); }