-
Notifications
You must be signed in to change notification settings - Fork 913
Expand file tree
/
Copy pathbuild.ts
More file actions
executable file
·58 lines (47 loc) · 1.82 KB
/
build.ts
File metadata and controls
executable file
·58 lines (47 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env bun
import { Rendered, Providers } from "../src/render";
import fs from "fs/promises";
import path from "path";
import { $ } from "bun";
await fs.rm("./dist", { recursive: true, force: true });
await Bun.build({
entrypoints: ["./index.html"],
outdir: "dist",
target: "bun",
});
for await (const file of new Bun.Glob("./public/*").scan()) {
await Bun.write(file.replace("./public/", "./dist/"), Bun.file(file));
}
// Copy provider logos to dist/logos/
await fs.mkdir("./dist/logos", { recursive: true });
// First, copy the default logo
const defaultLogoPath = "../../providers/logo.svg";
const defaultLogo = Bun.file(defaultLogoPath);
if (await defaultLogo.exists()) {
await Bun.write("./dist/logos/default.svg", defaultLogo);
}
// Then copy provider-specific logos
const providersDir = "../../providers";
const entries = await fs.readdir(providersDir, { withFileTypes: true });
for (const entry of entries) {
if (entry.isDirectory()) {
const provider = entry.name;
const logoPath = path.join(providersDir, provider, "logo.svg");
const logoFile = Bun.file(logoPath);
if (await logoFile.exists()) {
await Bun.write(`./dist/logos/${provider}.svg`, logoFile);
}
}
}
let html = await Bun.file("./dist/index.html").text();
html = html.replace("<!--static-->", Rendered);
// Inline model data JSON into the script tag (escape closing tags for safety)
const modelDataJson = JSON.stringify(Providers).replace(/<\/script/gi, "<\\/script");
html = html.replace(
'<script id="model-data" type="application/json"></script>',
`<script id="model-data" type="application/json">${modelDataJson}</script>`
);
await Bun.write("./dist/index.html", html);
await Bun.write("./dist/api.json", JSON.stringify(Providers));
await $`mv ./dist/index.html ./dist/_index.html`;
await $`mv ./dist/api.json ./dist/_api.json`;