runtime/entrypoints/template.entrypoint.ts
runtime/entrypoints/template.entrypoint.ts is a file in Bane's Lab Content. 43 lines of code and 8 definitions.
import { CLEAN_TEMPLATES, NO_TEMPLATES, unresolvedTemplateRef } from "#configuration/strings/template.strings";
import { ROOT, absolutePath } from "@ssot/paths";
import { conclude, refuse } from "#core/reporters/derivation.reporter";
import { createGovlabContext, unresolvedTemplateRefsOf } from "@govlab/context";
import { existsSync, readFileSync, readdirSync } from "node:fs";
import { join, relative, sep } from "node:path";
import type { Finding } from "#types/derivation.types";
import { STRINGS_SUFFIX } from "#configuration/constants/tone.constants";
import { TEMPLATE_COMMAND } from "#configuration/constants/contract.constants";
import { TEMPLATE_SUFFIX } from "#configuration/constants/template.constants";
import { TEMPLATE_SUMMARY } from "#configuration/strings/contract.strings";
import { defineCheck } from "@govlab/context/check";
import { packageFiles } from "#core/loaders/coordination.loader";
import { resolveArgv } from "@govlab/argv";
import { stringsFolders } from "#core/loaders/strings.loader";
defineCheck({ detects: [], enforces: ["architecture:traceability"] });
resolveArgv({ command: TEMPLATE_COMMAND, flags: [], summary: TEMPLATE_SUMMARY });
const hostTemplates = absolutePath("docArch.templates");
const coordination = absolutePath("app.coordination");
const filesUnder = function filesUnder(folder: string): string[] {
return existsSync(folder)
? readdirSync(folder, { encoding: "utf8", recursive: true }).map((name) => join(folder, name))
: [];
};
const templates = [
...filesUnder(hostTemplates),
...(existsSync(coordination) ? packageFiles(coordination) : []),
].filter((file) => file.endsWith(TEMPLATE_SUFFIX));
const stringsModules = stringsFolders()
.flatMap((folder) => filesUnder(folder))
.filter((file) => file.endsWith(STRINGS_SUFFIX));
const files = [...templates, ...stringsModules];
if (files.length === 0) {
refuse(`${NO_TEMPLATES}${hostTemplates}`);
}
const members = createGovlabContext().reason.kindMembers();
const findings: Finding[] = files.flatMap((file) =>
unresolvedTemplateRefsOf(readFileSync(file, "utf8"), members).map((ref) => ({
file: relative(ROOT, file).split(sep).join("/"),
message: unresolvedTemplateRef(ref.line, ref.kind, ref.id),
})),
);
conclude(TEMPLATE_COMMAND, findings, CLEAN_TEMPLATES);