-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.ts
More file actions
28 lines (22 loc) · 957 Bytes
/
build.ts
File metadata and controls
28 lines (22 loc) · 957 Bytes
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
import { $ } from "bun";
import { join } from "path";
import { homedir } from "os";
import { readdir } from "fs/promises";
const projectDir = import.meta.dir;
const scriptsDir = join(projectDir, "scripts");
const files = await readdir(scriptsDir);
const scripts = files
.filter((f) => f.endsWith(".ts"))
.map((f) => f.replace(/\.ts$/, ""));
await $`rm -rf dist && mkdir dist`;
for (const script of scripts) {
const source = join(scriptsDir, `${script}.ts`);
const out = join(projectDir, "dist", script);
const destination = join(homedir(), ".local", "bin", script);
const defines: string[] = [];
if (script === "maps" && process.env.GOOGLE_MAPS_API_KEY) {
defines.push(`--define`, `process.env.GOOGLE_MAPS_API_KEY=${JSON.stringify(process.env.GOOGLE_MAPS_API_KEY)}`);
}
await $`bun build --compile --no-compile-autoload-dotenv ${defines} ${source} --outfile ${out}`;
await $`chmod +x ${out} && ln -sf ${out} ${destination}`;
}