@babelx/cli 0.2.0 → 0.2.1
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 +28 -24
- package/package.json +1 -1
package/bin/bx
CHANGED
|
@@ -4,24 +4,28 @@
|
|
|
4
4
|
* Detects platform and runs the appropriate binary
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
import { spawn } from "node:child_process";
|
|
8
|
+
import { existsSync } from "node:fs";
|
|
9
|
+
import { join, dirname } from "node:path";
|
|
10
|
+
import { fileURLToPath } from "node:url";
|
|
11
|
+
import { platform as getPlatformName, arch as getArch } from "node:os";
|
|
12
|
+
|
|
13
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
14
|
+
const __dirname = dirname(__filename);
|
|
11
15
|
|
|
12
16
|
function getPlatform() {
|
|
13
|
-
const platform =
|
|
14
|
-
const arch =
|
|
17
|
+
const platform = getPlatformName();
|
|
18
|
+
const arch = getArch();
|
|
15
19
|
|
|
16
20
|
const platformMap = {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
21
|
+
darwin: "darwin",
|
|
22
|
+
linux: "linux",
|
|
23
|
+
win32: "windows",
|
|
20
24
|
};
|
|
21
25
|
|
|
22
26
|
const archMap = {
|
|
23
|
-
|
|
24
|
-
|
|
27
|
+
x64: "x64",
|
|
28
|
+
arm64: "arm64",
|
|
25
29
|
};
|
|
26
30
|
|
|
27
31
|
const p = platformMap[platform];
|
|
@@ -37,9 +41,9 @@ function getPlatform() {
|
|
|
37
41
|
|
|
38
42
|
function getBinaryPath() {
|
|
39
43
|
const platform = getPlatform();
|
|
40
|
-
const binDir =
|
|
41
|
-
const binName = platform.startsWith(
|
|
42
|
-
const binPath =
|
|
44
|
+
const binDir = join(__dirname, "..", "vendor");
|
|
45
|
+
const binName = platform.startsWith("windows") ? "bx.exe" : "bx";
|
|
46
|
+
const binPath = join(binDir, platform, binName);
|
|
43
47
|
|
|
44
48
|
return binPath;
|
|
45
49
|
}
|
|
@@ -48,27 +52,27 @@ function main() {
|
|
|
48
52
|
const binaryPath = getBinaryPath();
|
|
49
53
|
|
|
50
54
|
// Check if binary exists
|
|
51
|
-
if (!
|
|
52
|
-
console.error(
|
|
55
|
+
if (!existsSync(binaryPath)) {
|
|
56
|
+
console.error("BabelX CLI binary not found.");
|
|
53
57
|
console.error(`Expected path: ${binaryPath}`);
|
|
54
|
-
console.error(
|
|
55
|
-
console.error(
|
|
56
|
-
console.error(
|
|
58
|
+
console.error("");
|
|
59
|
+
console.error("Please run: npm install @babelx/cli");
|
|
60
|
+
console.error("Or download the binary manually from GitHub releases.");
|
|
57
61
|
process.exit(1);
|
|
58
62
|
}
|
|
59
63
|
|
|
60
64
|
// Run the binary with all arguments
|
|
61
65
|
const child = spawn(binaryPath, process.argv.slice(2), {
|
|
62
|
-
stdio:
|
|
63
|
-
windowsHide: true
|
|
66
|
+
stdio: "inherit",
|
|
67
|
+
windowsHide: true,
|
|
64
68
|
});
|
|
65
69
|
|
|
66
|
-
child.on(
|
|
67
|
-
console.error(
|
|
70
|
+
child.on("error", (err) => {
|
|
71
|
+
console.error("Failed to start BabelX CLI:", err.message);
|
|
68
72
|
process.exit(1);
|
|
69
73
|
});
|
|
70
74
|
|
|
71
|
-
child.on(
|
|
75
|
+
child.on("exit", (code) => {
|
|
72
76
|
process.exit(code || 0);
|
|
73
77
|
});
|
|
74
78
|
}
|