core/loaders/seed.loader.ts
core/loaders/seed.loader.ts is a file in Bane's Lab Content. 41 lines of code and 9 definitions.
import type { Faces, SeedReport } from "#types/lesson.types";
import { MODELS_FOLDER, OPERATOR_PROFILE, UTF8 } from "#configuration/constants/source.constants";
import { absolutePath, relativePath } from "@ssot/paths";
import { createAlgoGrammar, createArchRelations, createLexicon } from "@govlab/context";
import { readFileSync, readdirSync } from "node:fs";
import { MODEL_EXTENSION } from "#configuration/constants/seed.constants";
import type { SourceText } from "#types/inventory.types";
import { join } from "node:path";
import { readJsonOrNull } from "#core/persistence/report.persistence";
export const loadFaces = function loadFaces(): Faces {
return { algo: createAlgoGrammar(), arch: createArchRelations(), lex: createLexicon() };
};
export const readModelTemplate = function readModelTemplate(): string {
return readFileSync(absolutePath("app.coordination", "templates/model.template.md"), UTF8);
};
export const readModels = function readModels(): SourceText[] {
const folder = absolutePath("app.coordination", MODELS_FOLDER);
return readdirSync(folder)
.filter((name) => name.endsWith(MODEL_EXTENSION))
.sort((a, b) => a.localeCompare(b))
.map((name) => ({
path: relativePath("app.coordination", 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;
};