-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-standalone.js
More file actions
36 lines (26 loc) · 1.28 KB
/
Copy pathbuild-standalone.js
File metadata and controls
36 lines (26 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env node
const fs = require('fs');
const path = require('path');
console.log('🔨 Building standalone HTML file...');
try {
// Read the separate files
const htmlContent = fs.readFileSync('index.html', 'utf8');
const cssContent = fs.readFileSync('styles.css', 'utf8');
const jsContent = fs.readFileSync('app.js', 'utf8');
console.log('✅ Read source files successfully');
// Parse HTML and replace external references with inline content
let standaloneHtml = htmlContent;
// Replace CSS link with inline styles
const cssLinkRegex = /<link rel="stylesheet" href="styles\.css">/;
standaloneHtml = standaloneHtml.replace(cssLinkRegex, `<style>\n ${cssContent}\n </style>`);
// Replace JS script with inline script
const jsScriptRegex = /<script src="app\.js"><\/script>/;
standaloneHtml = standaloneHtml.replace(jsScriptRegex, `<script>\n ${jsContent}\n </script>`);
// Write the standalone file
fs.writeFileSync('chess-game-standalone.html', standaloneHtml);
console.log('✅ Successfully built chess-game-standalone.html');
console.log('🎯 Ready to share!');
} catch (error) {
console.error('❌ Error building standalone file:', error.message);
process.exit(1);
}