import type { Faces, SeedReport } from "#types/lesson.types"; import { MODELS_FOLDER, MODEL_TEMPLATE, OPERATOR_PROFILE, UTF8 } from "#configuration/constants/source.constants"; import { absolutePath, relativePath } from "@ssot/paths"; import { readFileSync, readdirSync } from "node:fs"; import { MODEL_EXTENSION } from "#configuration/constants/seed.constants"; import type { SourceText } from "#types/inventory.types"; import { createAlgoGrammar } from "@govlab/context/algo"; import { createArchRelations } from "@govlab/context/arch"; import { join } from "node:path"; import { readJsonOrNull } from "#core/persistence/report.persistence"; export const loadFaces = function loadFaces(): Faces { return { algo: createAlgoGrammar(), arch: createArchRelations() }; }; export const readModelTemplate = function readModelTemplate(): string { return readFileSync(absolutePath("collaboration", MODEL_TEMPLATE), UTF8); }; export const readModels = function readModels(): SourceText[] { const folder = absolutePath("collaboration", MODELS_FOLDER); return readdirSync(folder) .filter((name) => name.endsWith(MODEL_EXTENSION)) .sort((a, b) => a.localeCompare(b)) .map((name) => ({ path: relativePath("collaboration", MODELS_FOLDER, name), text: readFileSync(join(folder, name), UTF8), })); }; export const readOperatorProfile = function readOperatorProfile(): SourceText { return { path: relativePath("docArch.references", OPERATOR_PROFILE), text: readFileSync(absolutePath("docArch.references", OPERATOR_PROFILE), UTF8), }; }; export const seedsTarget = function seedsTarget(): string { return absolutePath("govlabHost.reports.content.seeds"); }; const isSeedReport = function isSeedReport(value: unknown): value is SeedReport { return typeof value === "object" && value !== null && Array.isArray(Reflect.get(value, "seeds")); }; export const readSeeds = function readSeeds(): SeedReport | null { const parsed = readJsonOrNull(seedsTarget()); return isSeedReport(parsed) ? parsed : null; };