keepAssets
uses node:path
Move a build's assets (<out>/assets) into the shared directory, compressed: the ones there already stay (the
same name is the same content). Their names. Its chunks' source maps go apart (mapsDir), as they're not to be
served.
import type { Codebase } from "#codebase/tcmts/cli/codebase"; import { assetsDir, mapsDir, precompress } from "#codebase/tcmts/cli/web"; import fs from "node:fs"; import path from "node:path"; export function keepAssets(cb: Codebase, out: string): string[] { const from = path.join(out, "assets"); if (!fs.existsSync(from)) return []; const to = assetsDir(cb); fs.mkdirSync(to, { recursive: true }); const maps = mapsDir(cb); for (const name of fs.readdirSync(from).filter((n) => n.endsWith(".map"))) { fs.mkdirSync(maps, { recursive: true }); const dest = path.join(maps, name); if (!fs.existsSync(dest)) fs.renameSync(path.join(from, name), dest); else fs.rmSync(path.join(from, name)); } const names = fs.readdirSync(from).sort(); for (const name of names) { const dest = path.join(to, name); if (!fs.existsSync(dest)) fs.renameSync(path.join(from, name), dest); precompress(dest); } return names; }