// Rebuilds referee/sgs.mjs and viewer/ from this folder's src/ and the upstream source. // git clone https://github.com/wmzy/sanguosha && cd sanguosha && git checkout 8f4b693 && pnpm install --frozen-lockfile // node /src/build.mjs (built with Node 22.19.0, pnpm 10.28.2) // src/ is copied into /shoal/ so it imports the upstream as ../src/..., and the upstream's own Vite builds // it: the engine as one ES module for Node 20+ (and referee/generals.json from it), the viewer as static files with // relative paths. `--engine` skips the viewer. viewer/art/ (the art pack) is built apart, by src/art.py, and kept. import { cpSync, rmSync, mkdirSync, copyFileSync, readdirSync, writeFileSync } from 'node:fs'; import { execFileSync } from 'node:child_process'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; const SRC = path.dirname(fileURLToPath(import.meta.url)); const GAME = path.dirname(SRC); const UP = path.resolve(process.argv[2] ?? ''); const vite = path.join(UP, 'node_modules/.bin/vite'); rmSync(path.join(UP, 'shoal'), { recursive: true, force: true }); cpSync(SRC, path.join(UP, 'shoal'), { recursive: true }); const run = (cfg) => execFileSync(vite, ['build', '-c', `shoal/${cfg}`], { cwd: UP, stdio: 'inherit' }); run('vite.engine.config.ts'); copyFileSync(path.join(UP, 'dist/shoal-engine/sgs.mjs'), path.join(GAME, 'referee/sgs.mjs')); const { catalog } = await import(`${path.join(GAME, 'referee/sgs.mjs')}?${Date.now()}`); writeFileSync(path.join(GAME, 'referee/generals.json'), `${JSON.stringify(await catalog(), null, 1)}\n`); if (process.argv[3] !== '--engine') { run('vite.viewer.config.ts'); const out = path.join(UP, 'dist/shoal-viewer'); for (const f of readdirSync(path.join(GAME, 'viewer'))) if (!['bridge.js', 'NOTICE', 'art'].includes(f)) rmSync(path.join(GAME, 'viewer', f), { recursive: true }); mkdirSync(path.join(GAME, 'viewer'), { recursive: true }); for (const f of readdirSync(out)) cpSync(path.join(out, f), path.join(GAME, 'viewer', f), { recursive: true }); }