11import shell from "shelljs" ;
2+ import * as fs from 'fs' ;
3+ import { highlight , languages } from 'prismjs' ;
4+ // Ensure required Prism languages are loaded
5+ import 'prismjs/components/prism-markup' ;
6+ import 'prismjs/components/prism-javascript' ;
7+ import 'prismjs/components/prism-jsx' ;
8+ import 'prismjs/components/prism-typescript' ;
9+ import 'prismjs/components/prism-tsx' ;
210
311// Build examples using Vite
412function buildExample ( ) {
513 // Use Vite to build examples directly to www/examples folder
614 shell . exec ( 'vite build' ) ;
715}
816
17+ // Export syntax-highlighted source code for each example into www/examples/*.html
18+ function exportCodeHtml ( lan : string , file : string , data : string ) {
19+ const html = `<!doctype html>
20+ <html>
21+ <head>
22+ <meta charset="utf-8"/>
23+ <meta name="viewport" content="width=device-width, initial-scale=1"/>
24+ <link rel="stylesheet" href="./prism-coy.css">
25+ <title>${ file } </title>
26+ <style>body{margin:0;padding:16px;box-sizing:border-box}</style>
27+ </head>
28+ <body>
29+ <pre class="language-${ lan } "><code class="language-${ lan } ">${ highlight ( data , languages [ lan ] || languages . markup , lan ) } </code></pre>
30+ </body>
31+ </html>` ;
32+ // Ensure output dir exists
33+ shell . mkdir ( '-p' , './www/examples' ) ;
34+ fs . writeFileSync ( `./www/examples/${ file } .html` , html ) ;
35+ }
36+
37+ function buildCodeHtml ( ) {
38+ const exampleDir = './example' ;
39+ const files = fs . readdirSync ( exampleDir ) ;
40+ for ( const file of files ) {
41+ // Generate code HTML for .tsx and .html examples
42+ if ( file . endsWith ( '.tsx' ) || file . endsWith ( '.html' ) ) {
43+ const data = fs . readFileSync ( `${ exampleDir } /${ file } ` , 'utf8' ) ;
44+ const lan = file . endsWith ( '.tsx' ) ? 'tsx' : 'html' ;
45+ exportCodeHtml ( lan , file , data ) ;
46+ }
47+ }
48+ }
49+
950function buildDocs ( ) {
1051 shell . exec ( 'typedoc' ) ;
1152 shell . mv ( './temp-doc/*' , './www' ) ;
@@ -19,6 +60,10 @@ function main() {
1960 shell . rm ( '-rf' , './www/assets' ) ;
2061 buildDocs ( ) ;
2162 buildExample ( ) ;
63+ if ( fs . existsSync ( './example/prism-coy.css' ) ) {
64+ shell . cp ( './example/prism-coy.css' , './www/examples/prism-coy.css' ) ;
65+ }
66+ buildCodeHtml ( ) ;
2267}
2368
2469main ( ) ;
0 commit comments