import { execFile } from "node:child_process"; import { glob, readFile, writeFile } from "node:fs/promises"; import { promisify, stripVTControlCharacters } from "node:util"; const execFileAsync = promisify(execFile); const __dirname = import.meta.dirname; const postgraphileBase = { cwd: "postgraphile/postgraphile", extraArgs: ["-C", "graphile.config.vanilla.ts"], }; const OPTIONS = { grafserv: { cwd: "grafast/grafserv", scope: "grafserv", }, grafast: { cwd: "grafast/grafast", scope: "grafast", }, ruru: { cwd: "grafast/ruru", scope: "ruru", extraArgs: ["-C", "graphile.config.mts"], }, postgraphile_inflection: { ...postgraphileBase, scope: "inflection", }, postgraphile_gather: { ...postgraphileBase, scope: "gather", }, postgraphile_schema: { ...postgraphileBase, scope: "schema", }, postgraphile_grafast: { ...postgraphileBase, scope: "grafast", }, postgraphile_grafserv: { ...postgraphileBase, scope: "grafserv", }, postgraphile_ruru: { ...postgraphileBase, scope: "ruru", }, }; const INFLECTION = { postgraphile: { ...postgraphileBase, }, }; const START = ""; const END = "`); } } async function getContentForOptions(project) { const config = OPTIONS[project]; if (!config) { throw new Error(`Unknown options scope ${JSON.stringify(project)}`); } const { cwd, scope, extraArgs = [] } = config; return graphile(cwd, ["config", "options", ...extraArgs, scope]); } async function getContentForInflection(project) { const config = INFLECTION[project]; if (!config) { throw new Error(`Unknown inflection scope ${JSON.stringify(project)}`); } const { cwd, extraArgs = [] } = config; return graphile(cwd, ["inflection", "list", "--quiet", ...extraArgs]); } async function graphile(cwd, flags) { const result = await execFileAsync( `${__dirname}/../utils/graphile/dist/cli-run.js`, flags, { cwd, encoding: "utf8" }, ); if (result.stderr.trim().length > 0) { console.error(result.stderr); } return stripVTControlCharacters(result.stdout).trim(); }