-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-static.mjs
More file actions
59 lines (49 loc) · 2.61 KB
/
Copy pathbuild-static.mjs
File metadata and controls
59 lines (49 loc) · 2.61 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
// Assemble a self-contained static site into ./build for static hosting (e.g. DigitalOcean App Platform).
//
// In dev, Vite serves the repo root + public/ at the web root, so the app loads everything from absolute paths
// (/styles.css, /dist/bundle.js, /scope-worker.js, /clock-worklet.js, /scratch-worklet.js, /sync-worklet.js,
// /mespeak-worker.js, /mespeak/*). A static host serves ONE directory, so we collect exactly those runtime
// files (no node_modules, no src, no tests) into ./build with the same paths.
//
// Run AFTER `npm run build` (which compiles src/main.tish -> dist/bundle.js and the scope worker). The
// `build:static` npm script chains both.
import { cpSync, mkdirSync, rmSync, existsSync, readdirSync } from 'node:fs'
import { join, dirname } from 'node:path'
import { fileURLToPath } from 'node:url'
const root = join(dirname(fileURLToPath(import.meta.url)), '..')
const out = join(root, 'build')
rmSync(out, { recursive: true, force: true })
mkdirSync(join(out, 'dist'), { recursive: true })
function copy(from, to) {
const src = join(root, from)
if (!existsSync(src)) {
console.error(`build-static: required file missing — ${from} (did \`npm run build\` run first?)`)
process.exit(1)
}
cpSync(src, join(out, to), { recursive: true })
}
// Entry HTML + global stylesheet.
copy('index.html', 'index.html')
copy('styles.css', 'styles.css')
// The compiled app bundle (index.html loads it from `dist/bundle.js`).
copy('dist/bundle.js', 'dist/bundle.js')
// Workers + audio worklets the app loads from the web root ("/...").
copy('scope-worker.js', 'scope-worker.js')
copy('clock-worklet.js', 'clock-worklet.js')
copy('scratch-worklet.js', 'scratch-worklet.js')
// public/ assets are served at the web root in dev (Vite) — mirror that: mespeak/ (TTS engine + voices)
// and mespeak-worker.js. Copy each top-level entry so they land at /<name>, not /public/<name>.
// (sync-worklet.js used to live here; it ships inside @spacedevin/deck-synths as a Blob URL now.)
const publicDir = join(root, 'public')
for (const entry of readdirSync(publicDir)) {
cpSync(join(publicDir, entry), join(out, entry), { recursive: true })
}
// Docs + llms.txt are generated into public/ by build:docs (run before this script).
if (!existsSync(join(out, 'docs', 'index.html'))) {
console.warn('build-static: warning — public/docs missing; run `npm run build:docs` first for /docs')
}
if (!existsSync(join(out, 'llms.txt'))) {
console.warn('build-static: warning — public/llms.txt missing')
}
console.log(`build-static: assembled static site → ${out}`)
console.log(`build-static: contents → ${readdirSync(out).sort().join(', ')}`)