scratchFiles

tcmts.studio.scratchFiles · #dzriccvp · term · runs on the server

uses node:fs

The scratch files there are, newest first: each .ts or .tsx file in scratchDir, and the files kept as written being edited there (keptFile); when each last changed.

import type { Codebase } from "#codebase/tcmts/cli/codebase";
import { keptFile, scratchDir } from "#codebase/tcmts/studio";
import fs from "node:fs";
import path from "node:path";

export function scratchFiles(cb: Codebase): { file: string; at: number }[] {
  const dir = scratchDir(cb);
  if (!fs.existsSync(dir)) return [];
  return fs
    .readdirSync(dir)
    .filter((f) =>
      /\.tsx?$/.test(f)
        ? !f.endsWith(".d.ts")
        : fs.statSync(path.join(dir, f)).isFile() && !!keptFile(cb, path.join(dir, f)),
    )
    .map((f) => ({ file: f, at: fs.statSync(path.join(dir, f)).mtimeMs }))
    .sort((a, b) => b.at - a.at);
}

uses

used by