-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.js
More file actions
135 lines (112 loc) · 3.57 KB
/
Copy pathbuild.js
File metadata and controls
135 lines (112 loc) · 3.57 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
import { execSync } from "child_process";
import rcedit from "rcedit";
import { existsSync, unlinkSync, mkdirSync, rmSync, cpSync } from "fs";
import { createWriteStream } from "fs";
import archiver from "archiver";
import path from "path";
import readline from "readline";
const APP_NAME = "zerx";
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
console.log(`🚀 Building ${APP_NAME}...\n`);
const VERSION = await new Promise((resolve) => {
rl.question("Enter version number (e.g., 1.0.0): ", (answer) => {
const version = answer.trim() || "1.0.0";
rl.close();
resolve(version);
});
});
console.log(`\n📦 Building ${APP_NAME} v${VERSION}...`);
const buildDir = "build";
const exeName = `${APP_NAME}.exe`;
const exePath = path.join(buildDir, exeName);
const zipName = `${APP_NAME}-v${VERSION}-windows-x64.zip`;
const zipPath = zipName;
if (existsSync(buildDir)) {
try {
rmSync(buildDir, { recursive: true, force: true });
console.log("Removed existing build directory");
} catch (error) {
console.log("Could not remove existing build directory");
console.log("Please close any running instances and try again");
process.exit(1);
}
}
if (existsSync(zipPath)) {
try {
unlinkSync(zipPath);
console.log("Removed existing zip file");
} catch (error) {
console.log("Could not remove existing zip file");
}
}
mkdirSync(buildDir, { recursive: true });
try {
execSync(
`bun build src/index.ts --compile --outfile ${exePath} --target bun-windows-x64`,
{ stdio: "inherit" }
);
console.log("Executable built successfully");
} catch (error) {
console.error("Failed to build executable:", error.message);
process.exit(1);
}
const iconPath = "assets/icon.ico";
if (!existsSync(iconPath)) {
console.log(`Warning: Icon file not found at ${iconPath}`);
console.log("Skipping icon setting...");
} else {
console.log("Adding icon and metadata...");
await new Promise((resolve) => setTimeout(resolve, 1000));
try {
await rcedit(exePath, {
icon: iconPath,
"version-string": {
FileDescription: "Zerx Emulator Manager",
ProductName: "Zerx",
CompanyName: "nopjo",
FileVersion: VERSION,
ProductVersion: VERSION,
OriginalFilename: exeName,
InternalName: "Zerx",
},
});
console.log("Icon and metadata added!");
} catch (error) {
console.error("Failed to add resources:", error.message);
console.log("The executable was built but without custom icon/metadata");
}
}
const scriptsPath = "scripts";
const targetScriptsPath = path.join(buildDir, "scripts");
if (existsSync(scriptsPath)) {
try {
cpSync(scriptsPath, targetScriptsPath, { recursive: true });
console.log("Scripts folder copied successfully");
} catch (error) {
console.error("Failed to copy scripts folder:", error.message);
console.log("Continuing without scripts folder...");
}
} else {
console.log("Warning: Scripts folder not found, skipping copy");
}
console.log("Creating zip file...");
const output = createWriteStream(zipPath);
const archive = archiver("zip", {
zlib: { level: 9 },
});
output.on("close", function () {
console.log(`✅ Release package created: ${zipName}`);
console.log(` Size: ${(archive.pointer() / 1024 / 1024).toFixed(2)} MB`);
console.log(` Version: ${VERSION}`);
console.log("🎉 Build complete!");
});
archive.on("error", function (err) {
console.error("Failed to create zip file:", err.message);
process.exit(1);
});
archive.pipe(output);
archive.directory(buildDir, false);
archive.finalize();