2025-01-21 09:38:14 +01:00
|
|
|
const { join, dirname } = require("node:path");
|
|
|
|
const { promises: fs } = require("node:fs");
|
2024-09-17 14:08:14 +03:30
|
|
|
|
|
|
|
const api = require("./api");
|
|
|
|
|
|
|
|
const Template = (output, { api, title, redoc }) =>
|
|
|
|
fs.writeFile(output,
|
|
|
|
`<DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<meta charset="UTF-8" />
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
|
|
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
|
|
|
|
<title>${title}</title>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<redoc spec-url="${api}" />
|
|
|
|
<script src="${redoc}"></script>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
`);
|
|
|
|
|
|
|
|
const Api = output =>
|
|
|
|
fs.writeFile(output, JSON.stringify(api));
|
|
|
|
|
|
|
|
const Redoc = output =>
|
|
|
|
fs.copyFile(join(
|
2025-01-21 09:38:14 +01:00
|
|
|
dirname(require.resolve("redoc")),
|
|
|
|
"redoc.standalone.js"),
|
2024-09-17 14:08:14 +03:30
|
|
|
output);
|
|
|
|
|
|
|
|
module.exports = (async () => {
|
2025-01-21 09:38:14 +01:00
|
|
|
const out = join(__dirname, "static");
|
|
|
|
const apiFile = "api.json";
|
|
|
|
const redocFile = "redoc.js";
|
2024-09-17 14:08:14 +03:30
|
|
|
await fs.mkdir(out, { recursive: true });
|
|
|
|
return Promise.all([
|
|
|
|
Api(join(out, apiFile)),
|
|
|
|
Redoc(join(out, redocFile)),
|
2025-01-21 09:38:14 +01:00
|
|
|
Template(join(out, "index.html"), {
|
2024-09-17 14:08:14 +03:30
|
|
|
api: apiFile,
|
|
|
|
title: api.info.title,
|
|
|
|
redoc: redocFile
|
|
|
|
}),
|
|
|
|
|
|
|
|
]);
|
|
|
|
})();
|