@babelx/cli 0.2.3 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/bx +61 -3
- package/package.json +1 -1
package/bin/bx
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import { spawn } from "node:child_process";
|
|
8
|
-
import { createWriteStream, existsSync, mkdirSync } from "node:fs";
|
|
8
|
+
import { createWriteStream, existsSync, mkdirSync, readFileSync, writeFileSync, unlinkSync } from "node:fs";
|
|
9
9
|
import { join, dirname } from "node:path";
|
|
10
10
|
import { fileURLToPath } from "node:url";
|
|
11
11
|
import { platform as getPlatformName, arch as getArch } from "node:os";
|
|
@@ -53,6 +53,53 @@ function getBinaryPath() {
|
|
|
53
53
|
return join(binDir, platform, binName);
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
+
function getVersionFilePath() {
|
|
57
|
+
const platform = getPlatform();
|
|
58
|
+
const binDir = join(__dirname, "..", "vendor");
|
|
59
|
+
return join(binDir, platform, ".version");
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function getPackageVersion() {
|
|
63
|
+
try {
|
|
64
|
+
const packageJson = JSON.parse(
|
|
65
|
+
readFileSync(join(__dirname, "..", "package.json"), "utf-8"),
|
|
66
|
+
);
|
|
67
|
+
return packageJson.version;
|
|
68
|
+
} catch {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function getBinaryVersion() {
|
|
74
|
+
try {
|
|
75
|
+
return readFileSync(getVersionFilePath(), "utf-8").trim();
|
|
76
|
+
} catch {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function saveBinaryVersion(version) {
|
|
82
|
+
try {
|
|
83
|
+
writeFileSync(getVersionFilePath(), version);
|
|
84
|
+
} catch {
|
|
85
|
+
// Ignore write errors
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function removeOldBinary(binaryPath) {
|
|
90
|
+
try {
|
|
91
|
+
if (existsSync(binaryPath)) {
|
|
92
|
+
unlinkSync(binaryPath);
|
|
93
|
+
}
|
|
94
|
+
const versionFile = getVersionFilePath();
|
|
95
|
+
if (existsSync(versionFile)) {
|
|
96
|
+
unlinkSync(versionFile);
|
|
97
|
+
}
|
|
98
|
+
} catch {
|
|
99
|
+
// Ignore errors
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
56
103
|
async function downloadBinary(platform, destPath) {
|
|
57
104
|
const binaryName = getBinaryName();
|
|
58
105
|
const packageJson = JSON.parse(
|
|
@@ -137,12 +184,23 @@ function makeExecutable(filePath) {
|
|
|
137
184
|
async function main() {
|
|
138
185
|
const binaryPath = getBinaryPath();
|
|
139
186
|
const platform = getPlatform();
|
|
187
|
+
const packageVersion = getPackageVersion();
|
|
188
|
+
const binaryVersion = getBinaryVersion();
|
|
189
|
+
|
|
190
|
+
// Check if binary needs update (new version or doesn't exist)
|
|
191
|
+
const needsDownload = !existsSync(binaryPath) || !binaryVersion || binaryVersion !== packageVersion;
|
|
192
|
+
|
|
193
|
+
if (needsDownload && packageVersion) {
|
|
194
|
+
// Remove old binary if exists
|
|
195
|
+
if (binaryVersion && binaryVersion !== packageVersion) {
|
|
196
|
+
console.log(`📦 Updating BabelX CLI: v${binaryVersion} → v${packageVersion}`);
|
|
197
|
+
removeOldBinary(binaryPath);
|
|
198
|
+
}
|
|
140
199
|
|
|
141
|
-
// Download binary if it doesn't exist (lazy loading)
|
|
142
|
-
if (!existsSync(binaryPath)) {
|
|
143
200
|
try {
|
|
144
201
|
await downloadBinary(platform, binaryPath);
|
|
145
202
|
makeExecutable(binaryPath);
|
|
203
|
+
saveBinaryVersion(packageVersion);
|
|
146
204
|
console.log(`✅ BabelX CLI installed successfully!\n`);
|
|
147
205
|
} catch (error) {
|
|
148
206
|
console.error("❌ Failed to download BabelX CLI binary.");
|