UNPKG

1.16 kBPlain TextView Raw
1import * as fs from "node:fs/promises";
2import * as path from "node:path";
3import { createRequire } from "node:module";
4
5import { __PRODUCTION__ } from "./lib/__PRODUCTION__";
6import { defineAkteFiles } from "./defineAkteFiles";
7import { NotFoundError } from "./errors";
8
9/**
10 * Akte welcome page shown in development when the Akte app does not have any
11 * othe Akte files registered.
12 *
13 * @remarks
14 * The HTML code below is highlighted and uglified manually to prevent the
15 * introduction of extra dependencies just for the sake of having a welcome
16 * page.
17 */
18export const akteWelcome = __PRODUCTION__
19 ? null
20 : defineAkteFiles().from({
21 path: "/",
22 async data() {
23 try {
24 const require = createRequire(path.resolve("index.js"));
25 const aktePath = require.resolve("akte/package.json");
26 const htmlPath = path.resolve(aktePath, "../dist/akteWelcome.html");
27
28 return {
29 html: await fs.readFile(htmlPath, "utf-8"),
30 };
31 } catch (error) {
32 throw new NotFoundError("/");
33 }
34 },
35 bulkData() {
36 // Never build the file
37 return {};
38 },
39 render(context) {
40 return context.data.html;
41 },
42 });