#!/usr/bin/env node import { mkdirSync, readFileSync, writeFileSync } from "node:fs"; import { dirname, join } from "node:path"; import { fileURLToPath } from "node:url"; const rootDir = dirname(dirname(fileURLToPath(import.meta.url))); const swaggerSource = join(rootDir, "swagger.yaml"); const publicSwaggerYaml = join(rootDir, "public", "swagger.yaml"); const publicSwaggerHtml = join(rootDir, "public", "swagger.html"); const docsSwaggerYaml = join(rootDir, "docs", "api", "swagger.yaml"); const docsSwaggerHtml = join(rootDir, "docs", "api", "swagger.html"); const swaggerYaml = readFileSync(swaggerSource, "utf8"); function createSwaggerHtml({ specUrl }) { return ` Wallora Searcher API Docs
`; } function writeGeneratedFile(path, content) { mkdirSync(dirname(path), { recursive: true }); writeFileSync(path, content); } writeGeneratedFile(publicSwaggerYaml, swaggerYaml); writeGeneratedFile( publicSwaggerHtml, createSwaggerHtml({ specUrl: "/swagger.yaml" }), ); writeGeneratedFile(docsSwaggerYaml, swaggerYaml); writeGeneratedFile( docsSwaggerHtml, createSwaggerHtml({ specUrl: "./swagger.yaml" }), ); console.log("Generated Swagger docs:"); console.log(`- ${publicSwaggerHtml}`); console.log(`- ${publicSwaggerYaml}`); console.log(`- ${docsSwaggerHtml}`); console.log(`- ${docsSwaggerYaml}`);