build.mjs (1076B)
1 import { readFile, writeFile, mkdir, cp, readdir } from 'node:fs/promises'; 2 import { join } from 'node:path'; 3 4 const source = await readFile('src/pytml-runtime.js', 'utf8'); 5 await mkdir('dist', { recursive: true }); 6 await writeFile('pytml.js', source, 'utf8'); 7 await writeFile('dist/pytml.js', source, 'utf8'); 8 9 // Conservative whitespace minifier for the browser distribution snapshot. 10 const minified = source 11 .replace(/\/\*[\s\S]*?\*\//g, '') 12 .replace(/^[ \t]+/gm, '') 13 .replace(/\n{2,}/g, '\n') 14 .trim(); 15 await writeFile('pytml.min.js', minified, 'utf8'); 16 await writeFile('dist/pytml.min.js', minified, 'utf8'); 17 18 // Keep the website self-contained when it is deployed as a standalone folder. 19 await mkdir('website', { recursive: true }); 20 await writeFile('website/pytml.js', source, 'utf8'); 21 await writeFile('website/pytml.min.js', minified, 'utf8'); 22 23 const copyDirs = ['examples']; 24 for (const dir of copyDirs) { 25 await cp(dir, join('website', dir), { recursive: true, force: true }); 26 } 27 28 console.log(`Built Pytml ${source.length} bytes -> root, dist/, and website/`);