@openwhale/openwhale-admin 0.1.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/README.md +18 -0
- package/bin/openwhale-admin.js +7 -0
- package/bin/run-binary.js +102 -0
- package/package.json +37 -0
package/README.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# @openwhale/openwhale-admin npm package
|
|
2
|
+
|
|
3
|
+
This package installs one command:
|
|
4
|
+
|
|
5
|
+
1. `openwhale-admin`
|
|
6
|
+
|
|
7
|
+
This main package does not download binaries during install.
|
|
8
|
+
It depends on platform packages via `optionalDependencies`:
|
|
9
|
+
|
|
10
|
+
1. `@openwhale/openwhale-darwin-x64`
|
|
11
|
+
2. `@openwhale/openwhale-darwin-arm64`
|
|
12
|
+
3. `@openwhale/openwhale-linux-x64`
|
|
13
|
+
4. `@openwhale/openwhale-linux-arm64`
|
|
14
|
+
|
|
15
|
+
## Supported platforms
|
|
16
|
+
|
|
17
|
+
1. `darwin` + `x64|arm64`
|
|
18
|
+
2. `linux` + `x64|arm64`
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
'use strict';
|
|
4
|
+
|
|
5
|
+
const fs = require('node:fs');
|
|
6
|
+
const path = require('node:path');
|
|
7
|
+
const { spawnSync } = require('node:child_process');
|
|
8
|
+
|
|
9
|
+
const PACKAGE_BY_TUPLE = Object.freeze({
|
|
10
|
+
'darwin:x64': '@openwhale/openwhale-darwin-x64',
|
|
11
|
+
'darwin:arm64': '@openwhale/openwhale-darwin-arm64',
|
|
12
|
+
'linux:x64': '@openwhale/openwhale-linux-x64',
|
|
13
|
+
'linux:arm64': '@openwhale/openwhale-linux-arm64',
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
function selectPlatformPackage(platform, arch) {
|
|
17
|
+
return PACKAGE_BY_TUPLE[`${platform}:${arch}`] || '';
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function supportedPlatformLabel() {
|
|
21
|
+
return 'darwin/x64, darwin/arm64, linux/x64, linux/arm64';
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function createDefaultDeps() {
|
|
25
|
+
return {
|
|
26
|
+
resolvePackageJSON(packageName) {
|
|
27
|
+
return require.resolve(`${packageName}/package.json`);
|
|
28
|
+
},
|
|
29
|
+
dirname: path.dirname,
|
|
30
|
+
join: path.join,
|
|
31
|
+
existsSync: fs.existsSync,
|
|
32
|
+
spawnSync,
|
|
33
|
+
getArgs() {
|
|
34
|
+
return process.argv.slice(2);
|
|
35
|
+
},
|
|
36
|
+
logError(msg) {
|
|
37
|
+
console.error(msg);
|
|
38
|
+
},
|
|
39
|
+
exit(code) {
|
|
40
|
+
process.exit(code);
|
|
41
|
+
},
|
|
42
|
+
signalProcess(sig) {
|
|
43
|
+
process.kill(process.pid, sig);
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function resolveBinaryPath(binaryName, platform = process.platform, arch = process.arch, deps = createDefaultDeps()) {
|
|
49
|
+
const packageName = selectPlatformPackage(platform, arch);
|
|
50
|
+
if (!packageName) {
|
|
51
|
+
throw new Error(
|
|
52
|
+
`[openwhale-admin] unsupported platform: ${platform}/${arch} (supported: ${supportedPlatformLabel()})`,
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
let packageJSONPath = '';
|
|
57
|
+
try {
|
|
58
|
+
packageJSONPath = deps.resolvePackageJSON(packageName);
|
|
59
|
+
} catch (err) {
|
|
60
|
+
if (err && err.code === 'MODULE_NOT_FOUND') {
|
|
61
|
+
throw new Error(
|
|
62
|
+
`[openwhale-admin] missing platform package ${packageName} for ${platform}/${arch}; run: npm i -g @openwhale/openwhale-admin`,
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
throw err;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const packageDir = deps.dirname(packageJSONPath);
|
|
69
|
+
const suffix = platform === 'win32' ? '.exe' : '';
|
|
70
|
+
const binaryPath = deps.join(packageDir, 'bin', binaryName + suffix);
|
|
71
|
+
if (!deps.existsSync(binaryPath)) {
|
|
72
|
+
throw new Error(`[openwhale-admin] missing native binary in ${packageName}: ${binaryPath}`);
|
|
73
|
+
}
|
|
74
|
+
return { packageName, binaryPath };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function runBinary(binaryName, deps = createDefaultDeps()) {
|
|
78
|
+
let binaryPath = '';
|
|
79
|
+
try {
|
|
80
|
+
({ binaryPath } = resolveBinaryPath(binaryName, process.platform, process.arch, deps));
|
|
81
|
+
} catch (err) {
|
|
82
|
+
deps.logError(err.message);
|
|
83
|
+
deps.exit(1);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const child = deps.spawnSync(binaryPath, deps.getArgs(), { stdio: 'inherit' });
|
|
88
|
+
if (child.error) {
|
|
89
|
+
deps.logError(`[openwhale-admin] launch failed: ${child.error.message}`);
|
|
90
|
+
deps.exit(1);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
if (child.signal) {
|
|
94
|
+
deps.signalProcess(child.signal);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
deps.exit(typeof child.status === 'number' ? child.status : 1);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
module.exports = runBinary;
|
|
101
|
+
module.exports.selectPlatformPackage = selectPlatformPackage;
|
|
102
|
+
module.exports.resolveBinaryPath = resolveBinaryPath;
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@openwhale/openwhale-admin",
|
|
3
|
+
"version": "0.1.4",
|
|
4
|
+
"description": "OpenWhale admin CLI distribution package.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"bin": {
|
|
7
|
+
"openwhale-admin": "bin/openwhale-admin.js"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"test": "node --test"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"bin",
|
|
14
|
+
"README.md",
|
|
15
|
+
"package.json"
|
|
16
|
+
],
|
|
17
|
+
"optionalDependencies": {
|
|
18
|
+
"@openwhale/openwhale-darwin-arm64": "0.1.4",
|
|
19
|
+
"@openwhale/openwhale-darwin-x64": "0.1.4",
|
|
20
|
+
"@openwhale/openwhale-linux-arm64": "0.1.4",
|
|
21
|
+
"@openwhale/openwhale-linux-x64": "0.1.4"
|
|
22
|
+
},
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=18"
|
|
25
|
+
},
|
|
26
|
+
"os": [
|
|
27
|
+
"darwin",
|
|
28
|
+
"linux"
|
|
29
|
+
],
|
|
30
|
+
"cpu": [
|
|
31
|
+
"x64",
|
|
32
|
+
"arm64"
|
|
33
|
+
],
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public"
|
|
36
|
+
}
|
|
37
|
+
}
|