writeAllViews

tcmts.cli.views.writeAllViews · #6k2jmtfi · term · runs on the server

uses node:fs

import type { CodebaseCore } from "#codebase/tcmts/cli/codebase";
import { Placement } from "#codebase/tcmts/cli/placement";
import { srcDir, writeView, writeViewsConfig } from "#codebase/tcmts/cli/views";
import fs from "node:fs";
import path_1 from "node:path";

export function writeAllViews(cb: CodebaseCore) {
  const placement = new Placement(cb);
  const keep = new Set<string>();
  for (const n of cb.store.names()) {
    const w = writeView(cb, n.hash, placement);
    if (w) keep.add(w.file);
  }
  const walk = (dir: string): string[] =>
    fs.existsSync(dir)
      ? fs
          .readdirSync(dir, { withFileTypes: true })
          .flatMap((e) =>
            e.isDirectory() ? walk(path_1.join(dir, e.name)) : [path_1.join(dir, e.name)],
          )
      : [];
  for (const f of walk(srcDir(cb)))
    if (
      !keep.has(f) &&
      !path_1.basename(f).startsWith("@") &&
      path_1.basename(f) !== "tsconfig.json"
    )
      fs.rmSync(f);
  writeViewsConfig(cb);
}

uses

used by