-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
31 lines (26 loc) · 1.04 KB
/
index.js
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
const path = require("path");
const childProcess = require("child_process");
// Lookup table for all platforms and binary distribution packages
const BINARY_DISTRIBUTION_PACKAGES = {
'linux-x64': 'paseto_cli-linux-x64',
'darwin-x64': 'paseto_cli-darwin-x64',
'darwin-aarch64': 'paseto_cli-darwin-aarch64',
'win32-x64': 'paseto_cli-win32-x64'
};
// Windows binaries end with .exe so we need to special case them.
const binaryName = process.platform === "win32" ? "paseto_cli.exe" : "paseto_cli";
// Determine package name for this platform
const platformSpecificPackageName = BINARY_DISTRIBUTION_PACKAGES[process.platform];
function getBinaryPath() {
try {
// Resolving will fail if the optionalDependency was not installed
return require.resolve(`${platformSpecificPackageName}/bin/${binaryName}`);
} catch (e) {
return path.join(__dirname, "..", binaryName);
}
}
module.exports.runBinary = function (...args) {
childProcess.execFileSync(getBinaryPath(), args, {
stdio: "inherit",
});
};