runtime/entrypoints/coordination.entrypoint.ts

runtime/entrypoints/coordination.entrypoint.ts is a file in Bane's Lab Content. 59 lines of code and 6 definitions.

import {
    ACCUMULATOR_FILE,
    HOST_LOCATION_KEYS,
    HOST_TERMS,
    INDEX_FILE,
} from "#configuration/constants/coordination.constants";
import {
    BOUND_SEAT_LEAD,
    CLEAN_COORDINATION,
    FILED_ENTRY_LEAD,
    HOST_TERM_LEAD,
    NO_PACKAGE,
    POPULATED_FOLDER_LEAD,
    SCHEDULED_AGENDA,
} from "#configuration/strings/coordination.strings";
import { ROOT, absolutePath, relativePath } from "@ssot/paths";
import { boundSeats, filedEntries, hostTermsIn, schedulesRows } from "#core/validators/coordination.validator";
import { conclude, refuse } from "#core/reporters/derivation.reporter";
import { existsSync, readFileSync } from "node:fs";
import { packageFiles, packagePath, populatedFolders } from "#core/loaders/coordination.loader";
import { COORDINATION_COMMAND } from "#configuration/constants/contract.constants";
import { COORDINATION_SUMMARY } from "#configuration/strings/contract.strings";
import type { Finding } from "#types/derivation.types";
import { defineCheck } from "@govlab/context/check";
import { join } from "node:path";
import { resolveArgv } from "@govlab/argv";

defineCheck({ detects: [], enforces: ["architecture:platform-independence"] });

resolveArgv({ command: COORDINATION_COMMAND, flags: [], summary: COORDINATION_SUMMARY });

const root = absolutePath("app.coordination");
if (!existsSync(root)) {
    refuse(`${NO_PACKAGE}${root}`);
}

const readAt = function readAt(path: string): string {
    return existsSync(path) ? readFileSync(path, "utf8") : "";
};

const read = function read(file: string): string {
    return readAt(join(root, file));
};

const agendaConfig = absolutePath("app.coordination", "config/agenda.config.ts");

const findings: Finding[] = [];

const terms = [...HOST_TERMS, ...HOST_LOCATION_KEYS.map((key) => relativePath(key)), ROOT];

for (const file of packageFiles(root)) {
    for (const term of hostTermsIn(readFileSync(file, "utf8"), terms)) {
        findings.push({ file: packagePath(root, file), message: `${HOST_TERM_LEAD}${term}` });
    }
}

for (const file of populatedFolders(root)) {
    findings.push({ file, message: `${POPULATED_FOLDER_LEAD}${file}` });
}

for (const letter of boundSeats(read(INDEX_FILE))) {
    findings.push({ file: INDEX_FILE, message: `${BOUND_SEAT_LEAD}${letter}` });
}

for (const heading of filedEntries(read(ACCUMULATOR_FILE))) {
    findings.push({ file: ACCUMULATOR_FILE, message: `${FILED_ENTRY_LEAD}${heading}` });
}

if (schedulesRows(readAt(agendaConfig))) {
    findings.push({ file: packagePath(root, agendaConfig), message: SCHEDULED_AGENDA });
}

conclude(COORDINATION_COMMAND, findings, CLEAN_COORDINATION);