viewsBranchOf

tcmts.cli.views.viewsBranchOf · #j664iygf · term · runs on the server

uses node:path

Whose views a file is in, if it's a view (of whichever branch, srcDir): .tcm/src is the codebase's own branch's, .tcm/sessions/<dir>/src that session's (null: a session whose branch is gone).

import { sessionDirFor } from "#codebase/tcmts/cli/codebase";
import type { CodebaseCore } from "#codebase/tcmts/cli/codebase";
import path_1 from "node:path";

export function viewsBranchOf(cb: CodebaseCore, file: string): string | null | undefined {
  const rel = path_1.relative(cb.lay.tcmDir, path_1.resolve(file)).split(path_1.sep);
  if (rel[0] === "src" && rel.length > 1) return cb.store.getSetting("branch") ?? null;
  if (rel[0] === "sessions" && rel[2] === "src" && rel.length > 3)
    return (
      cb.store.branches().find((b) => path_1.basename(sessionDirFor(cb.lay.root, b)) === rel[1]) ??
      null
    );
  return undefined;
}

uses

used by