/** * Write the built files into the game copy folder. */ import { mkdirSync, rmSync, writeFileSync } from 'node:fs'; import { dirname, join } from 'node:path'; import type { GameCopyFile } from './build-game-copy.ts'; /** Writes every file and returns the full paths written, in order. */ export function writeGameCopy(copyFolder: string, files: readonly GameCopyFile[]): string[] { return files.map((file) => { const path = join(copyFolder, file.path); mkdirSync(dirname(path), { recursive: true }); // Remove before writing: a read-only file is replaced instead of failing with EPERM, and a // file hard-linked to the stock folder gets a new file of its own instead of changing the // stock one through the link. rmSync(path, { force: true }); writeFileSync(path, file.content); return path; }); }