-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.ts
More file actions
136 lines (113 loc) · 3.33 KB
/
build.ts
File metadata and controls
136 lines (113 loc) · 3.33 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import solidPlugin from "@opentui/solid/bun-plugin";
import { existsSync, mkdirSync } from "fs";
const RELEASES_DIR = "./dist/releases";
// Supported compilation targets
type CompileTarget =
| "bun-darwin-arm64"
| "bun-darwin-x64"
| "bun-linux-x64"
| "bun-linux-arm64";
async function bundle() {
console.log("📦 Bundling tailcode CLI...");
const result = await Bun.build({
entrypoints: ["./bin/tailcode.ts"],
outdir: "./dist",
target: "bun",
conditions: ["browser"],
plugins: [solidPlugin],
minify: true,
sourcemap: "linked",
});
if (!result.success) {
console.error("❌ Bundle failed:");
for (const log of result.logs) {
console.error(log);
}
process.exit(1);
}
console.log(`✅ Bundled to dist/tailcode.js (${result.outputs.length} files)`);
return result;
}
async function compile(target: CompileTarget, bundlePath: string) {
const isWindows = target.includes("windows");
const ext = isWindows ? ".exe" : "";
const outputName = `tailcode-${target.replace("bun-", "")}${ext}`;
const outputPath = `${RELEASES_DIR}/${outputName}`;
console.log(`🔨 Compiling for ${target}...`);
const result = await Bun.build({
entrypoints: [bundlePath],
compile: {
target,
outfile: outputPath,
autoloadBunfig: false,
autoloadTsconfig: false,
autoloadPackageJson: false,
},
minify: true,
});
if (!result.success) {
console.error(`❌ Compile failed for ${target}:`);
for (const log of result.logs) {
console.error(log);
}
return false;
}
console.log(`✅ Compiled: ${outputPath}`);
return true;
}
async function main() {
const args = process.argv.slice(2);
const command = args[0] || "bundle";
// Ensure dist directories exist
if (!existsSync("./dist")) {
mkdirSync("./dist", { recursive: true });
}
if (!existsSync(RELEASES_DIR)) {
mkdirSync(RELEASES_DIR, { recursive: true });
}
switch (command) {
case "bundle": {
await bundle();
break;
}
case "compile": {
const bundlePath = "./dist/tailcode.js";
if (!existsSync(bundlePath)) {
console.log("📦 Bundle not found, bundling first...");
await bundle();
}
const platform = process.platform;
const arch = process.arch;
let target: CompileTarget | null = null;
if (platform === "darwin") {
if (arch === "arm64") target = "bun-darwin-arm64";
else if (arch === "x64") target = "bun-darwin-x64";
} else if (platform === "linux") {
if (arch === "x64") target = "bun-linux-x64";
else if (arch === "arm64") target = "bun-linux-arm64";
}
if (!target) {
console.error(`❌ Unsupported platform: ${platform} ${arch}`);
process.exit(1);
}
const success = await compile(target, bundlePath);
if (!success) {
console.error(`❌ Failed to compile for ${target}`);
process.exit(1);
}
break;
}
default: {
console.log("Usage: bun run build.ts [bundle|compile]");
console.log("");
console.log("Commands:");
console.log(" bundle - Bundle to dist/tailcode.js");
console.log(" compile - Compile for current platform");
process.exit(1);
}
}
}
main().catch((err) => {
console.error("❌ Build failed:", err);
process.exit(1);
});