-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.ts
More file actions
57 lines (46 loc) · 1.25 KB
/
build.ts
File metadata and controls
57 lines (46 loc) · 1.25 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
import { argv, listen } from "bun"
import { getAllSites } from "./mapper/main"
import FS from 'fs/promises'
import Path from 'path'
import { watch } from "fs"
import AppConfig from "./config";
const baseSite = AppConfig.masterSite
const outputDir = "dist/"
const sites = await getAllSites(baseSite)
const sitesDir = Path.join(outputDir, "sites")
async function build() {
console.log("Build")
if (await FS.exists(outputDir)) {
await FS.rm(outputDir, { recursive: true })
}
var siteRefs: Record<string, string[]> = {};
sites.forEach(site => {
siteRefs[site.url] = site.refs
})
await Bun.build({
"entrypoints": [
"index.html",
],
files: {
"./refs.json": JSON.stringify(siteRefs)
},
outdir: outputDir
})
await FS.mkdir(sitesDir, { recursive: true })
sites.forEach(async site => {
await FS.writeFile(Path.join(sitesDir, site.url + ".json"), JSON.stringify(site))
})
}
if (argv.includes("--watch")) {
await build()
watch("src/", {recursive:true},async ()=> {
try {
console.log("Update")
await build()
} catch (e) {
console.error("Error", e)
}
})
} else {
await build();
}