🔗 Free Modern URL Shortener. https://kutt.it/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.0 KiB

  1. import { join, dirname } from 'path';
  2. import { promises as fs } from 'fs';
  3. import api from './api';
  4. const Template = (output, { api, title, redoc }) =>
  5. fs.writeFile(output,
  6. `<DOCTYPE html>
  7. <html>
  8. <head>
  9. <meta charset="UTF-8" />
  10. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  11. <meta http-equiv="X-UA-Compatible" content="ie=edge" />
  12. <title>${title}</title>
  13. </head>
  14. <body>
  15. <redoc spec-url="${api}" />
  16. <script src="${redoc}"></script>
  17. </body>
  18. </html>
  19. `);
  20. const Api = output =>
  21. fs.writeFile(output, JSON.stringify(api));
  22. const Redoc = output =>
  23. fs.copyFile(join(
  24. dirname(require.resolve('redoc')),
  25. 'redoc.standalone.js'),
  26. output);
  27. export default (async () => {
  28. const out = join(__dirname, 'static');
  29. const apiFile = 'api.json';
  30. const redocFile = 'redoc.js';
  31. await fs.mkdir(out, { recursive: true });
  32. return Promise.all([
  33. Api(join(out, apiFile)),
  34. Redoc(join(out, redocFile)),
  35. Template(join(out, 'index.html'), {
  36. api: apiFile,
  37. title: api.info.title,
  38. redoc: redocFile
  39. }),
  40. ]);
  41. })();