@moltcorp/cli 1.0.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/install.js +87 -0
- package/package.json +17 -0
- package/run.js +18 -0
package/install.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
const https = require("https");
|
|
5
|
+
const http = require("http");
|
|
6
|
+
const fs = require("fs");
|
|
7
|
+
const path = require("path");
|
|
8
|
+
|
|
9
|
+
const DOWNLOAD_BASE = "https://get.instantcli.com/moltcorp";
|
|
10
|
+
|
|
11
|
+
const PLATFORM_MAP = {
|
|
12
|
+
darwin: "darwin",
|
|
13
|
+
linux: "linux",
|
|
14
|
+
win32: "windows",
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const ARCH_MAP = {
|
|
18
|
+
x64: "x64",
|
|
19
|
+
arm64: "arm64",
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
function getBinaryName() {
|
|
23
|
+
const platform = PLATFORM_MAP[process.platform];
|
|
24
|
+
const arch = ARCH_MAP[process.arch];
|
|
25
|
+
|
|
26
|
+
if (!platform || !arch) {
|
|
27
|
+
throw new Error(
|
|
28
|
+
`Unsupported platform: ${process.platform} ${process.arch}`
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const ext = process.platform === "win32" ? ".exe" : "";
|
|
33
|
+
return `cli-${platform}-${arch}${ext}`;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function download(url) {
|
|
37
|
+
return new Promise((resolve, reject) => {
|
|
38
|
+
const client = url.startsWith("https") ? https : http;
|
|
39
|
+
client
|
|
40
|
+
.get(url, (res) => {
|
|
41
|
+
// Follow redirects
|
|
42
|
+
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
|
43
|
+
return download(res.headers.location).then(resolve, reject);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (res.statusCode !== 200) {
|
|
47
|
+
reject(new Error(`Download failed with status ${res.statusCode}`));
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const chunks = [];
|
|
52
|
+
res.on("data", (chunk) => chunks.push(chunk));
|
|
53
|
+
res.on("end", () => resolve(Buffer.concat(chunks)));
|
|
54
|
+
res.on("error", reject);
|
|
55
|
+
})
|
|
56
|
+
.on("error", reject);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async function main() {
|
|
61
|
+
try {
|
|
62
|
+
const binaryName = getBinaryName();
|
|
63
|
+
const url = `${DOWNLOAD_BASE}/${binaryName}`;
|
|
64
|
+
const dest = path.join(
|
|
65
|
+
__dirname,
|
|
66
|
+
process.platform === "win32" ? "cli-binary.exe" : "cli-binary"
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
console.log(`Downloading ${binaryName}...`);
|
|
70
|
+
const data = await download(url);
|
|
71
|
+
|
|
72
|
+
fs.writeFileSync(dest, data);
|
|
73
|
+
|
|
74
|
+
if (process.platform !== "win32") {
|
|
75
|
+
fs.chmodSync(dest, 0o755);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
console.log("Installation complete.");
|
|
79
|
+
} catch (err) {
|
|
80
|
+
console.warn(`Warning: failed to download binary: ${err.message}`);
|
|
81
|
+
console.warn("You may need to install the binary manually.");
|
|
82
|
+
// Exit 0 so npm install doesn't fail
|
|
83
|
+
process.exit(0);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
main();
|
package/package.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@moltcorp/cli",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "CLI tool (auto-generated by InstantCLI)",
|
|
5
|
+
"bin": {
|
|
6
|
+
"moltcorp": "./run.js"
|
|
7
|
+
},
|
|
8
|
+
"scripts": {
|
|
9
|
+
"postinstall": "node install.js"
|
|
10
|
+
},
|
|
11
|
+
"os": ["darwin", "linux", "win32"],
|
|
12
|
+
"cpu": ["x64", "arm64"],
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=16"
|
|
15
|
+
},
|
|
16
|
+
"files": ["install.js", "run.js", "package.json"]
|
|
17
|
+
}
|
package/run.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
const { execFileSync } = require("child_process");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
|
|
7
|
+
const ext = process.platform === "win32" ? ".exe" : "";
|
|
8
|
+
const binary = path.join(__dirname, `cli-binary${ext}`);
|
|
9
|
+
|
|
10
|
+
try {
|
|
11
|
+
execFileSync(binary, process.argv.slice(2), { stdio: "inherit" });
|
|
12
|
+
} catch (err) {
|
|
13
|
+
if (err.status !== undefined) {
|
|
14
|
+
process.exit(err.status);
|
|
15
|
+
}
|
|
16
|
+
console.error(`Failed to run CLI: ${err.message}`);
|
|
17
|
+
process.exit(1);
|
|
18
|
+
}
|