keepAssets

tcmts.cli.web.keepAssets · #taysm4uv · term · runs on the server

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.

import type { Codebase } from "#codebase/tcmts/cli/codebase";
import { assetsDir, 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 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;
}

uses

used by