scratchPath

tcmts.studio.scratchPath · #yrvjbort · term · runs on the server

uses node:path

The scratch file named file (only a name, of one in scratchDir: a .ts or .tsx file, or a file kept as written being edited, as keptFile says), as a path.

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

export function scratchPath(cb: Codebase, file: string, text?: string): string {
  if (!/^[\w-][\w.-]*\.[A-Za-z0-9]+$/.test(file) || file.endsWith(".d.ts"))
    throw new HttpError(400, `${file} isn't a scratch file's name: a file beside the codebase.`);
  const abs = path.join(scratchDir(cb), file);
  if (!/\.tsx?$/.test(file) && !keptFile(cb, abs, text))
    throw new HttpError(
      400,
      `${file} isn't a scratch file: they're code (.ts, .tsx), or files kept as written being edited (Edit, on their page).`,
    );
  return abs;
}

uses

used by