GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — bespoke_email-simulator/scripts/pack-dist.mjs at main · CodeSignal/bespoke_email-simulator Expand file tree/ Copy pathpack-dist.mjsMore file actions 186 lines (170 loc) · 5.62 KB / Copy pathpack-dist.mjsFile metadata and controls186 lines (170 loc) · 5.62 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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 #!/usr/bin/env node /** * Builds a runnable release tree into dist/ and archives it as dist.tar.gz. * * The tarball is the client bundle + a single-file server bundle + the static * files Express serves. No node_modules. Extract and `node server.js`. * * Usage: * node scripts/pack-dist.mjs */ import { execFileSync } from 'node:child_process'; import fs from 'node:fs'; import path from 'node:path'; import { fileURLToPath, pathToFileURL } from 'node:url'; import * as esbuild from 'esbuild'; const __dirname = path.dirname(fileURLToPath(import.meta.url)); const ROOT = path.resolve(__dirname, '..'); const DIST = path.join(ROOT, 'dist'); const TAR = path.join(ROOT, 'dist.tar.gz'); function copy(src, dest, filter) { fs.cpSync(src, dest, { recursive: true, filter }); } function bytes(file) { return fs.statSync(file).size; } function formatSize(n) { if (n >= 1024 * 1024) return `${(n / (1024 * 1024)).toFixed(1)} MB`; if (n >= 1024) return `${(n / 1024).toFixed(0)} KB`; return `${n} B`; } function distSize(rel) { const full = path.join(DIST, rel); if (!fs.existsSync(full)) return 0; const st = fs.statSync(full); if (!st.isDirectory()) return st.size; let total = 0; for (const entry of fs.readdirSync(full, { withFileTypes: true })) { const child = path.join(rel, entry.name); total += distSize(child); } return total; } fs.rmSync(DIST, { recursive: true, force: true }); fs.mkdirSync(path.join(DIST, 'public'), { recursive: true }); await esbuild.build({ absWorkingDir: ROOT, entryPoints: ['public/app.js'], bundle: true, outfile: 'dist/public/app.bundle.js', format: 'esm', platform: 'browser', minify: true, logLevel: 'warning', }); await esbuild.build({ absWorkingDir: ROOT, entryPoints: ['server.js'], bundle: true, outfile: 'dist/server.js', format: 'esm', platform: 'node', minify: true, banner: { js: "import { createRequire } from 'module'; const require = createRequire(import.meta.url);", }, logLevel: 'warning', }); await esbuild.build({ absWorkingDir: ROOT, entryPoints: ['extract-conversations.js'], bundle: true, outfile: 'dist/extract-conversations.js', format: 'esm', platform: 'node', minify: true, banner: { js: "import { createRequire } from 'module'; const require = createRequire(import.meta.url);", }, logLevel: 'warning', }); // Everything Express serves from public/, except the unbundled source and a // local app.bundle.js (esbuild already wrote the minified one into dist/). const publicSrc = path.join(ROOT, 'public'); copy(publicSrc, path.join(DIST, 'public'), (src) => { const base = path.basename(src); if (base === '.DS_Store') return false; if (src === publicSrc) return true; return base !== 'app.js' && base !== 'app.bundle.js'; }); // Packed releases have no node_modules. Dev serves this from the Rive package; // the release serves it from public/ via express.static. copy( path.join(ROOT, 'node_modules/@rive-app/canvas/rive.wasm'), path.join(DIST, 'public/vendor/rive.wasm'), ); copy(path.join(ROOT, 'design-system'), path.join(DIST, 'design-system'), (src) => { const rel = path.relative(path.join(ROOT, 'design-system'), src); return !rel.split(path.sep).includes('.git'); }); copy(path.join(ROOT, 'i18n'), path.join(DIST, 'i18n')); copy(path.join(ROOT, 'current-models.txt'), path.join(DIST, 'current-models.txt')); copy(path.join(ROOT, '.env.example'), path.join(DIST, '.env.example')); copy(path.join(ROOT, 'scenario.example.json'), path.join(DIST, 'scenario.example.json')); const pkg = JSON.parse(fs.readFileSync(path.join(ROOT, 'package.json'), 'utf8')); fs.writeFileSync( path.join(DIST, 'package.json'), `${JSON.stringify( { name: pkg.name, version: pkg.version, private: true, type: 'module', scripts: { start: 'node server.js', extract: 'node extract-conversations.js', report: 'node extract-conversations.js --mode report --print-settings', 'report:chronological': 'node extract-conversations.js --mode report --print-settings --order chronological', }, }, null, 2, )}\n`, ); for (const rel of [ 'public/app.bundle.js', 'public/app.css', 'public/global.css', 'public/index.html', 'public/animations/thinking.riv', 'public/icons/mail-logo.svg', 'public/vendor/rive.wasm', 'server.js', 'extract-conversations.js', ]) { if (!fs.existsSync(path.join(DIST, rel))) throw new Error(`missing ${rel} in dist/`); } process.env.NODE_ENV = 'test'; process.env.SCENARIO_FILE = path.join(DIST, 'scenario.example.json'); process.env.SESSIONS_FILE = path.join(DIST, '.pack-sessions.json'); const { app } = await import(pathToFileURL(path.join(DIST, 'server.js')).href); const server = await new Promise((resolve, reject) => { const s = app.listen(0, '127.0.0.1', () => resolve(s)); s.on('error', reject); }); try { const port = server.address().port; const health = await fetch(`http://127.0.0.1:${port}/api/health`); if (!health.ok) throw new Error(`health check failed (${health.status})`); await health.json(); } finally { server.closeAllConnections?.(); await new Promise((resolve) => server.close(resolve)); fs.rmSync(process.env.SESSIONS_FILE, { force: true }); } if (fs.existsSync(TAR)) fs.unlinkSync(TAR); execFileSync('tar', ['-czf', TAR, '-C', DIST, '.'], { cwd: ROOT }); const entries = [ 'server.js', 'extract-conversations.js', 'public/app.bundle.js', 'public', 'design-system', 'i18n', ]; console.log('Packed dist/ (no node_modules):'); for (const rel of entries) { console.log(` ${rel.padEnd(24)} ${formatSize(distSize(rel))}`); } console.log(` ${'dist.tar.gz'.padEnd(24)} ${formatSize(bytes(TAR))}`); |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |