2025-11-01 20:03:53 +02:00
|
|
|
import BuildContext from "./context";
|
|
|
|
|
import { join } from "path";
|
2025-11-01 20:15:38 +02:00
|
|
|
import { execSync } from "child_process";
|
2025-11-01 20:22:17 +02:00
|
|
|
import { mkdirSync } from "fs";
|
2025-11-01 20:03:53 +02:00
|
|
|
|
2025-11-01 20:22:17 +02:00
|
|
|
interface BuildInfo {
|
|
|
|
|
specPath: string;
|
|
|
|
|
outDir: string;
|
|
|
|
|
}
|
2025-11-01 20:15:38 +02:00
|
|
|
|
2025-11-02 20:12:50 +02:00
|
|
|
const DIR_PREFIX = "rest-api";
|
2025-11-01 21:35:18 +02:00
|
|
|
|
2025-11-01 20:22:17 +02:00
|
|
|
const buildInfos: BuildInfo[] = [
|
|
|
|
|
{
|
2025-11-01 20:37:03 +02:00
|
|
|
// Paths are relative to Git root.
|
2025-11-02 18:14:03 +02:00
|
|
|
specPath: "apps/server/internal.openapi.yaml",
|
2025-11-01 21:35:18 +02:00
|
|
|
outDir: `${DIR_PREFIX}/internal`
|
2025-11-01 20:22:17 +02:00
|
|
|
},
|
|
|
|
|
{
|
2025-11-02 18:14:03 +02:00
|
|
|
specPath: "apps/server/etapi.openapi.yaml",
|
2025-11-01 21:35:18 +02:00
|
|
|
outDir: `${DIR_PREFIX}/etapi`
|
2025-11-01 20:22:17 +02:00
|
|
|
}
|
|
|
|
|
];
|
|
|
|
|
|
2025-11-01 20:37:03 +02:00
|
|
|
export default function buildSwagger({ baseDir, gitRootDir }: BuildContext) {
|
2025-11-01 20:22:17 +02:00
|
|
|
for (const { specPath, outDir } of buildInfos) {
|
2025-11-01 20:37:03 +02:00
|
|
|
const absSpecPath = join(gitRootDir, specPath);
|
2025-11-01 20:22:17 +02:00
|
|
|
const targetDir = join(baseDir, outDir);
|
2025-11-01 21:47:07 +02:00
|
|
|
mkdirSync(targetDir, { recursive: true });
|
2025-11-01 20:37:03 +02:00
|
|
|
execSync(`pnpm redocly build-docs ${absSpecPath} -o ${targetDir}/index.html`, { stdio: "inherit" });
|
2025-11-01 20:22:17 +02:00
|
|
|
}
|
2025-11-01 20:03:53 +02:00
|
|
|
}
|