import fs from "fs";
import grabDirNames from "./grab-dir-names";
import { TCIGlobalConfig } from "@/src/types";

export default function grabTurboCiConfig() {
    const { TURBOCI_CONFIG_JSON_FILE } = grabDirNames();

    if (!fs.existsSync(TURBOCI_CONFIG_JSON_FILE)) {
        throw new Error(`TurboCI config JSON file not found!`);
    }

    const config = JSON.parse(
        fs.readFileSync(TURBOCI_CONFIG_JSON_FILE, "utf-8"),
    ) as TCIGlobalConfig;

    return config;
}
