|
1 | 1 | // website-src/build.js |
2 | 2 | const fs = require("fs"); |
3 | 3 | const path = require("path"); |
4 | | -const { marked } = require("marked"); |
5 | | - |
6 | | -// Read README.md |
7 | | -const readmeContent = fs.readFileSync("README.md", "utf8"); |
8 | | - |
9 | | -// Read HTML template |
10 | | -const template = fs.readFileSync("website/index.html", "utf8"); |
11 | | - |
12 | | -// Configure marked for GitHub-style rendering |
13 | | -marked.setOptions({ |
14 | | - gfm: true, |
15 | | - breaks: true, |
16 | | - headerIds: true, |
17 | | - mangle: false, |
18 | | -}); |
19 | | - |
20 | | -// Convert markdown to HTML |
21 | | -const htmlContent = marked(readmeContent); |
22 | | - |
23 | | -// Read specs files |
24 | | -const specsDir = "docs/specs"; |
25 | | -const specsFiles = fs |
26 | | - .readdirSync(specsDir) |
27 | | - .filter((file) => file.endsWith(".md")); |
28 | | -const specs = {}; |
29 | | - |
30 | | -specsFiles.forEach((file) => { |
31 | | - const filePath = path.join(specsDir, file); |
32 | | - const content = fs.readFileSync(filePath, "utf8"); |
33 | | - const htmlContent = marked(content); |
34 | | - const fileName = path.basename(file, ".md"); |
35 | | - specs[fileName] = { |
36 | | - title: |
37 | | - fileName.charAt(0).toUpperCase() + fileName.slice(1).replace(/-/g, " "), |
38 | | - content: htmlContent, |
39 | | - }; |
40 | | -}); |
41 | | - |
42 | | -// Generate specs data for frontend |
43 | | -const specsData = `const specsData = ${JSON.stringify(specs)};`; |
44 | | -fs.writeFileSync("build/specs-data.js", specsData); |
45 | | - |
46 | | -// Replace placeholder in template |
47 | | -const finalHtml = template.replace("{{CONTENT}}", htmlContent); |
48 | | - |
49 | | -// Write to build directory |
50 | | -fs.writeFileSync("build/index.html", finalHtml); |
51 | | - |
52 | | -console.log("✅ Website built successfully!"); |
| 4 | + |
| 5 | +(async () => { |
| 6 | + // Dynamically import ESM-only marked |
| 7 | + const { marked } = await import("marked"); |
| 8 | + |
| 9 | + // Read README.md |
| 10 | + const readmeContent = fs.readFileSync("README.md", "utf8"); |
| 11 | + |
| 12 | + // Read HTML template |
| 13 | + const template = fs.readFileSync("website/index.html", "utf8"); |
| 14 | + |
| 15 | + // Configure marked for GitHub-style rendering |
| 16 | + marked.setOptions({ |
| 17 | + gfm: true, |
| 18 | + breaks: true, |
| 19 | + headerIds: true, |
| 20 | + mangle: false, |
| 21 | + }); |
| 22 | + |
| 23 | + // Convert markdown to HTML |
| 24 | + const htmlContent = marked(readmeContent); |
| 25 | + |
| 26 | + // Read specs files |
| 27 | + const specsDir = "docs/specs"; |
| 28 | + const specsFiles = fs |
| 29 | + .readdirSync(specsDir) |
| 30 | + .filter((file) => file.endsWith(".md")); |
| 31 | + const specs = {}; |
| 32 | + |
| 33 | + specsFiles.forEach((file) => { |
| 34 | + const filePath = path.join(specsDir, file); |
| 35 | + const content = fs.readFileSync(filePath, "utf8"); |
| 36 | + const htmlSpec = marked(content); |
| 37 | + const fileName = path.basename(file, ".md"); |
| 38 | + specs[fileName] = { |
| 39 | + title: |
| 40 | + fileName.charAt(0).toUpperCase() + fileName.slice(1).replace(/-/g, " "), |
| 41 | + content: htmlSpec, |
| 42 | + }; |
| 43 | + }); |
| 44 | + |
| 45 | + // Generate specs data for frontend |
| 46 | + const specsData = `const specsData = ${JSON.stringify(specs)};`; |
| 47 | + fs.writeFileSync("build/specs-data.js", specsData); |
| 48 | + |
| 49 | + // Replace placeholder in template |
| 50 | + const finalHtml = template.replace("{{CONTENT}}", htmlContent); |
| 51 | + |
| 52 | + // Write to build directory |
| 53 | + fs.writeFileSync("build/index.html", finalHtml); |
| 54 | + |
| 55 | + console.log("✅ Website built successfully!"); |
| 56 | +})(); |
0 commit comments