@aptos-labs/aptos-cli 0.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/bin/.gitkeep +0 -0
- package/bin/aptos +69 -0
- package/package.json +10 -0
package/bin/.gitkeep
ADDED
|
File without changes
|
package/bin/aptos
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { spawn } = require("child_process");
|
|
4
|
+
const fs = require("fs");
|
|
5
|
+
const os = require("os");
|
|
6
|
+
|
|
7
|
+
const PNAME = "aptos-cli";
|
|
8
|
+
const VERSION = "2.0.2";
|
|
9
|
+
|
|
10
|
+
// Get all arguments passed to the script
|
|
11
|
+
const getOS = () => {
|
|
12
|
+
const platform = os.platform();
|
|
13
|
+
switch (platform) {
|
|
14
|
+
case "darwin":
|
|
15
|
+
return "MacOSX";
|
|
16
|
+
case "linux":
|
|
17
|
+
return "Ubuntu";
|
|
18
|
+
case "win32":
|
|
19
|
+
return "Windows";
|
|
20
|
+
default:
|
|
21
|
+
throw new Error(`Unsupported OS ${platform}`);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const main = async () => {
|
|
26
|
+
const os = getOS();
|
|
27
|
+
const binaryName = `${PNAME}-${VERSION}-${os}`;
|
|
28
|
+
|
|
29
|
+
// If binary does not exist, download it
|
|
30
|
+
if (!fs.existsSync(`${__dirname}/${binaryName}`)) {
|
|
31
|
+
await new Promise((resolve, reject) => {
|
|
32
|
+
const url = `https://github.com/aptos-labs/aptos-core/releases/download/${PNAME}-v${VERSION}/${PNAME}-${VERSION}-${os}-x86_64.zip`;
|
|
33
|
+
console.log("Downloading aptos CLI...");
|
|
34
|
+
let downloadProcess;
|
|
35
|
+
if (os === "Windows") {
|
|
36
|
+
downloadProcess = spawn(
|
|
37
|
+
`curl -L -o C:/tmp/aptos.zip ${url} & powershell Expand-Archive -Path C:/tmp/aptos.zip -DestinationPath C:/tmp -Force & move C:/tmp/aptos ${__dirname}/${binaryName}`,
|
|
38
|
+
{
|
|
39
|
+
stdio: "inherit",
|
|
40
|
+
shell: true,
|
|
41
|
+
}
|
|
42
|
+
);
|
|
43
|
+
} else {
|
|
44
|
+
downloadProcess = spawn(
|
|
45
|
+
`curl -L -o /tmp/aptos.zip ${url}; unzip -o -q /tmp/aptos.zip -d /tmp; mv /tmp/aptos ${__dirname}/${binaryName};`,
|
|
46
|
+
{
|
|
47
|
+
stdio: "inherit",
|
|
48
|
+
shell: true,
|
|
49
|
+
}
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
downloadProcess.on("close", (code) => {
|
|
54
|
+
if (code !== 0) {
|
|
55
|
+
reject("Error occurred while downloading aptos CLI");
|
|
56
|
+
}
|
|
57
|
+
console.log("Download complete");
|
|
58
|
+
resolve();
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Spawn a child process to execute the binary with the provided arguments
|
|
64
|
+
spawn(`${__dirname}/${binaryName}`, process.argv.slice(2), {
|
|
65
|
+
stdio: "inherit",
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
main().catch(console.error);
|