Play liveChoose your opponent
Join
54be506
31 lines · 2.0 KB Raw Permalink History
1// Rebuilds referee/sgs.mjs and viewer/ from this folder's src/ and the upstream source.
2// git clone https://github.com/wmzy/sanguosha && cd sanguosha && git checkout 8f4b693 && pnpm install --frozen-lockfile
3// node <this folder>/src/build.mjs <that checkout> (built with Node 22.19.0, pnpm 10.28.2)
4// src/ is copied into <checkout>/shoal/ so it imports the upstream as ../src/..., and the upstream's own Vite builds
5// it: the engine as one ES module for Node 20+ (and referee/generals.json from it), the viewer as static files with
6// relative paths. `--engine` skips the viewer. viewer/art/ (the art pack) is built apart, by src/art.py, and kept.
7import { cpSync, rmSync, mkdirSync, copyFileSync, readdirSync, writeFileSync } from 'node:fs';
8import { execFileSync } from 'node:child_process';
9import path from 'node:path';
10import { fileURLToPath } from 'node:url';
11
12const SRC = path.dirname(fileURLToPath(import.meta.url));
13const GAME = path.dirname(SRC);
14const UP = path.resolve(process.argv[2] ?? '');
15const vite = path.join(UP, 'node_modules/.bin/vite');
16rmSync(path.join(UP, 'shoal'), { recursive: true, force: true });
17cpSync(SRC, path.join(UP, 'shoal'), { recursive: true });
18const run = (cfg) => execFileSync(vite, ['build', '-c', `shoal/${cfg}`], { cwd: UP, stdio: 'inherit' });
19
20run('vite.engine.config.ts');
21copyFileSync(path.join(UP, 'dist/shoal-engine/sgs.mjs'), path.join(GAME, 'referee/sgs.mjs'));
22const { catalog } = await import(`${path.join(GAME, 'referee/sgs.mjs')}?${Date.now()}`);
23writeFileSync(path.join(GAME, 'referee/generals.json'), `${JSON.stringify(await catalog(), null, 1)}\n`);
24
25if (process.argv[3] !== '--engine') {
26 run('vite.viewer.config.ts');
27 const out = path.join(UP, 'dist/shoal-viewer');
28 for (const f of readdirSync(path.join(GAME, 'viewer'))) if (!['bridge.js', 'NOTICE', 'art'].includes(f)) rmSync(path.join(GAME, 'viewer', f), { recursive: true });
29 mkdirSync(path.join(GAME, 'viewer'), { recursive: true });
30 for (const f of readdirSync(out)) cpSync(path.join(out, f), path.join(GAME, 'viewer', f), { recursive: true });
31}