changedFiles

tcmts.cli.mirror.changedFiles · #z54nnsst · term · runs on the server

uses node:fs

The mirror's files changed since tcm last wrote or read them (by hand, or by git: a pull, a checkout), or added or removed.

import { assetFiles, sha, sourceFiles } from "#codebase/tcmts/cli/mirror";
import type { Mirror } from "#codebase/tcmts/cli/mirror";
import fs from "node:fs";
import path from "node:path";

export function changedFiles(m: Mirror): string[] {
  const out = Object.entries(m.files)
    .filter(([rel, f]) => !fs.existsSync(path.join(m.dir, rel)) || sha(fs.readFileSync(path.join(m.dir, rel), "utf8")) !== f.sha)
    .map(([rel]) => rel);
  const exclude = new Set(m.exclude.map((e) => path.resolve(m.dir, e)));
  for (const f of [...sourceFiles(m.dir, exclude, m.tests), ...assetFiles(m.dir, exclude)]) {
    if (!(path.relative(m.dir, f) in m.files)) out.push(path.relative(m.dir, f));
  }
  return out;
}

uses

used by