import fs from 'node:fs'; import path from 'node:path'; const root = process.cwd(); const dist = path.join(root, 'dist'); const indexPath = path.join(dist, 'index.html'); const outPath = path.join(dist, 'standalone-preview.html'); const index = fs.readFileSync(indexPath, 'utf8'); const scriptMatch = index.match(/]+src="([^"]+)"[^>]*><\/script>/); const styleMatch = index.match(/]+href="([^"]+)"[^>]*>/); if (!scriptMatch || !styleMatch) { throw new Error('Could not find built JS/CSS assets in dist/index.html'); } const toAssetPath = (assetUrl) => path.join(dist, assetUrl.replace(/^\/ui\//, '').replace(/^\.\//, '')); let js = fs.readFileSync(toAssetPath(scriptMatch[1]), 'utf8'); const css = fs.readFileSync(toAssetPath(styleMatch[1]), 'utf8'); js = js.replace(/(["'`])\/ui\/assets\/([^"'`]+\.(png|jpg|jpeg|webp|gif))\1/g, (match, quote, assetName, extension) => { const assetPath = path.join(dist, 'assets', assetName); if (!fs.existsSync(assetPath)) { return match; } return `${quote}/gradio_api/file=dist/assets/${assetName}${quote}`; }); const html = ` CultureLens Preview
`; fs.writeFileSync(outPath, html); console.log(outPath);