-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
112 lines (96 loc) · 2.48 KB
/
Copy pathindex.js
File metadata and controls
112 lines (96 loc) · 2.48 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
#!/usr/bin/env node
/**
* Nehonix FileOnix - Professional-grade file watcher and development server
*
* This is the main entry point for the npm package.
* It detects the platform and executes the appropriate binary.
*/
const { spawn } = require("child_process");
const path = require("path");
const fs = require("fs");
const os = require("os");
/**
* Get the platform-specific binary name
*/
function getBinaryName() {
const platform = os.platform();
const arch = os.arch();
let platformName;
let archName;
let extension = "";
// Map Node.js platform names to our binary names
switch (platform) {
case "win32":
platformName = "windows";
extension = ".exe";
break;
case "darwin":
platformName = "darwin";
break;
case "linux":
platformName = "linux";
break;
default:
throw new Error(`Unsupported platform: ${platform}`);
}
// Map Node.js arch names to our binary names
switch (arch) {
case "x64":
archName = "amd64";
break;
case "arm64":
archName = "arm64";
break;
default:
throw new Error(`Unsupported architecture: ${arch}`);
}
return `fileonix-${platformName}-${archName}${extension}`;
}
/**
* Get the path to the binary
*/
function getBinaryPath() {
const binaryName = getBinaryName();
const binaryPath = path.join(__dirname, "bin", binaryName);
if (!fs.existsSync(binaryPath)) {
throw new Error(`Binary not found: ${binaryPath}`);
}
return binaryPath;
}
/**
* Execute the binary with the provided arguments
*/
function main() {
try {
const binaryPath = getBinaryPath();
const args = process.argv.slice(2);
// Spawn the binary process
const child = spawn(binaryPath, args, {
stdio: "inherit",
windowsHide: false,
});
// Handle process exit
child.on("exit", (code, signal) => {
if (signal) {
process.kill(process.pid, signal);
} else {
process.exit(code);
}
});
// Handle errors
child.on("error", (err) => {
console.error("Failed to start fileonix:", err.message);
process.exit(1);
});
} catch (error) {
console.error("Error:", error.message);
console.error("\nIf this error persists, please report it at:");
console.error("https://github.com/Nehonix-Team/FileOnix/issues");
process.exit(1);
}
}
// Only run if this file is executed directly
if (require.main === module) {
main();
}
module.exports = { getBinaryName, getBinaryPath, main };