-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild.ts
More file actions
74 lines (64 loc) · 1.8 KB
/
build.ts
File metadata and controls
74 lines (64 loc) · 1.8 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import solidPlugin from "@opentui/solid/bun-plugin";
const result = await Bun.build({
entrypoints: ["./src/index.ts"],
target: "bun",
outdir: "./dist",
format: "esm",
sourcemap: "external",
plugins: [solidPlugin],
});
if (!result.success) {
console.error("Build failed");
for (const log of result.logs) {
console.error(log);
}
process.exit(1);
}
console.log("Build successful");
const indexPath = "./dist/index.js";
const indexContent = await Bun.file(indexPath).text();
const updatedContent = indexContent.replace(
"#!/usr/bin/env node",
"#!/usr/bin/env bun"
);
await Bun.write(indexPath, updatedContent);
console.log("Updated shebang");
const tscResult = Bun.spawnSync([
"tsc",
"--emitDeclarationOnly",
"--declaration",
"--outDir",
"dist",
]);
if (tscResult.exitCode !== 0) {
console.error("Type generation failed");
process.exit(1);
}
console.log("Generated type definitions");
// Build commander-ui (Vite) then copy into dist/ for npm packaging
const uiDir = "./src/commander-ui";
const uiSrc = "./src/commander-ui/dist";
const uiDest = "./dist/commander-ui";
const installResult = Bun.spawnSync(["bun", "install"], {
cwd: uiDir,
stdio: ["ignore", "inherit", "inherit"],
});
if (installResult.exitCode !== 0) {
console.warn("Warning: commander-ui install failed, skipping UI build");
} else {
const viteBuild = Bun.spawnSync(["bun", "run", "build"], {
cwd: uiDir,
stdio: ["ignore", "inherit", "inherit"],
});
if (viteBuild.exitCode !== 0) {
console.error("commander-ui build failed");
process.exit(1);
}
console.log("Built commander-ui");
}
const cpResult = Bun.spawnSync(["cp", "-r", uiSrc, uiDest]);
if (cpResult.exitCode !== 0) {
console.warn("Warning: commander-ui dist not found, skipping copy");
} else {
console.log("Copied commander-ui dist");
}