-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.ts
More file actions
114 lines (98 loc) · 3.35 KB
/
Copy pathbuild.ts
File metadata and controls
114 lines (98 loc) · 3.35 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
import { $ } from "bun";
import pkg from "./package.json";
import { existsSync, cpSync } from "node:fs";
// 1. Configuration
const entryPoint = "./src/main.ts";
const outDir = "./dist";
const appName = "cursorscript";
const version = pkg.version;
const ALL_TARGETS: Bun.Build.CompileTarget[] = [
"bun-linux-x64",
"bun-linux-arm64",
"bun-darwin-x64",
"bun-darwin-arm64",
"bun-windows-x64-baseline",
];
const targetArg = process.argv.find((arg) => arg.startsWith("bun-"));
const targets = (
targetArg ? [targetArg] : ALL_TARGETS
) as Bun.Build.CompileTarget[];
console.log(`\n🚀 Bundling ${appName} v${version}...`);
await $`rm -rf ${outDir} && mkdir -p ${outDir}`;
const tempBundle = `${outDir}/_temp_bundle.js`;
// 2. Bundling Step (The "Bundler-based" part)
// This prepares the code, handles imports, and tree-shakes.
const buildResult = await Bun.build({
entrypoints: [entryPoint],
target: "bun", // We bundle for the bun runtime
minify: true,
external: [],
packages: "bundle",
naming: "_temp_bundle.js",
sourcemap: "external",
outdir: outDir,
});
if (!buildResult.success) {
console.error("Build failed:", buildResult.logs);
process.exit(1);
}
for (const targetId of targets) {
const isWindows = targetId.includes("windows");
const extension = isWindows ? ".exe" : "";
const baseName = `${appName}-${targetId.replace("bun-", "")}`;
const targetFolder = `${outDir}/${baseName}`;
const binPath = `${targetFolder}/cursorx${extension}`;
process.stdout.write(`📦 Target: ${targetId.padEnd(25)} ... `);
try {
// 3. Compilation & Packaging
await $`mkdir -p ${targetFolder}`;
// Compile the bundled output into a single executable
if (isWindows) {
console.log(`🔧 Patching Windows metadata for ${binPath}...`);
// await rcedit(binPath, {
// "product-version": version,
// "version-string": {
// CompanyName: "CursorScript",
// FileDescription: "CursorScript Executable",
// LegalCopyright: "© 2024 CursorScript. All rights reserved.",
// OriginalFilename: "cursorx.exe",
// ProductName: "CursorScript",
// },
// "file-version": version,
// icon: "./icon.ico",
// });
await Bun.build({
entrypoints: [tempBundle],
compile: {
outfile: binPath,
target: targetId,
windows: {
icon: "./icon.ico",
// Additional Windows metadata:
title: "CursorScript Executable",
publisher: "NaveenPoddar",
version: version,
description: "CursorScript Executable",
copyright: "© 2024 CursorScript. All rights reserved.",
},
},
});
} else {
await $`bun build ${tempBundle} --compile --target=${targetId} --outfile=${binPath}`.quiet();
}
// 4. Asset Management
const libSource = `./lib`;
if (existsSync(libSource)) {
cpSync(libSource, `${targetFolder}/lib`, { recursive: true, dereference: true });
}
console.log(`🔧 Compressing ${baseName}...`);
// 5. Compression
await $`cd ${outDir} && 7z a -tzip -mx=7 -mmt=on ${baseName}.zip ${baseName}`.quiet();
await $`rm -rf ${targetFolder}`;
console.log("✅ Done");
} catch (error) {
console.log("❌ Failed");
console.error(error);
}
}
console.log(`\n✨ All builds compressed in ${outDir}`);