@aptos-labs/aptos-cli 0.2.0 → 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.
Files changed (66) hide show
  1. package/bin/aptos.ts +42 -0
  2. package/bin/tasks/install.ts +55 -0
  3. package/bin/tasks/run.ts +23 -0
  4. package/bin/tasks/update.ts +33 -0
  5. package/bin/utils/aptosExecutableIsAvailable.ts +14 -0
  6. package/bin/utils/brewOperations.ts +23 -0
  7. package/bin/utils/consts.ts +3 -0
  8. package/bin/utils/execSyncShell.ts +8 -0
  9. package/bin/utils/getAptosCliLatestVersion.ts +14 -0
  10. package/bin/utils/getLocalBinPath.ts +28 -0
  11. package/bin/utils/getUserOs.ts +18 -0
  12. package/bin/utils/ghOperations.ts +20 -0
  13. package/bin/utils/handleHelpOptions.ts +38 -0
  14. package/bin/utils/parseCommandOptions.ts +28 -0
  15. package/bin/utils/versions.ts +9 -0
  16. package/dist/aptos.d.ts +2 -0
  17. package/dist/aptos.js +24 -0
  18. package/dist/aptos.js.map +1 -0
  19. package/dist/tasks/install.d.ts +1 -0
  20. package/dist/tasks/install.js +42 -0
  21. package/dist/tasks/install.js.map +1 -0
  22. package/dist/tasks/run.d.ts +1 -0
  23. package/dist/tasks/run.js +17 -0
  24. package/dist/tasks/run.js.map +1 -0
  25. package/dist/tasks/update.d.ts +1 -0
  26. package/dist/tasks/update.js +26 -0
  27. package/dist/tasks/update.js.map +1 -0
  28. package/dist/utils/aptosExecutableIsAvailable.d.ts +1 -0
  29. package/dist/utils/aptosExecutableIsAvailable.js +11 -0
  30. package/dist/utils/aptosExecutableIsAvailable.js.map +1 -0
  31. package/dist/utils/brewOperations.d.ts +2 -0
  32. package/dist/utils/brewOperations.js +12 -0
  33. package/dist/utils/brewOperations.js.map +1 -0
  34. package/dist/utils/consts.d.ts +2 -0
  35. package/dist/utils/consts.js +3 -0
  36. package/dist/utils/consts.js.map +1 -0
  37. package/dist/utils/execSyncShell.d.ts +1 -0
  38. package/dist/utils/execSyncShell.js +5 -0
  39. package/dist/utils/execSyncShell.js.map +1 -0
  40. package/dist/utils/getAptosCliLatestVersion.d.ts +1 -0
  41. package/dist/utils/getAptosCliLatestVersion.js +12 -0
  42. package/dist/utils/getAptosCliLatestVersion.js.map +1 -0
  43. package/dist/utils/getLocalBinPath.d.ts +1 -0
  44. package/dist/utils/getLocalBinPath.js +30 -0
  45. package/dist/utils/getLocalBinPath.js.map +1 -0
  46. package/dist/utils/getUserOs.d.ts +1 -0
  47. package/dist/utils/getUserOs.js +15 -0
  48. package/dist/utils/getUserOs.js.map +1 -0
  49. package/dist/utils/ghOperations.d.ts +1 -0
  50. package/dist/utils/ghOperations.js +12 -0
  51. package/dist/utils/ghOperations.js.map +1 -0
  52. package/dist/utils/handleHelpOptions.d.ts +2 -0
  53. package/dist/utils/handleHelpOptions.js +16 -0
  54. package/dist/utils/handleHelpOptions.js.map +1 -0
  55. package/dist/utils/parseCommandOptions.d.ts +4 -0
  56. package/dist/utils/parseCommandOptions.js +21 -0
  57. package/dist/utils/parseCommandOptions.js.map +1 -0
  58. package/dist/utils/versions.d.ts +1 -0
  59. package/dist/utils/versions.js +6 -0
  60. package/dist/utils/versions.js.map +1 -0
  61. package/package.json +32 -4
  62. package/.github/workflows/run-bin-script-on-mac.yaml +0 -18
  63. package/.github/workflows/run-bin-script-on-ubuntu.yaml +0 -18
  64. package/.github/workflows/run-bin-script-on-windows.yaml +0 -19
  65. package/CONTRIBUTING.md +0 -8
  66. package/bin/aptos +0 -201
package/bin/aptos.ts ADDED
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env node
2
+
3
+ // On MacOS we install the CLI with brew. There are two main reasons for this:
4
+ // 1. Brew builds the CLI for the native CPU architecture for the user, which
5
+ // eliminates any issues arising from using x86 binaries on ARM machines.
6
+ // 2. Brew handles dependency management for us. This isn't relevant right now but
7
+ // might become necessary later if we reintroduce OpenSSL as a dep for the CLI.
8
+ //
9
+ // On Linux and Windows we just query the GH API for the latest CLI release and
10
+ // download and extract that.
11
+
12
+ import { program } from "commander";
13
+
14
+ import { parseCommandOptions } from "./utils/parseCommandOptions.js";
15
+ import { runCLI } from "./tasks/run.js";
16
+
17
+ program
18
+ .name("aptos")
19
+ .helpOption(false)
20
+ .option("-i, --install", "install the latest version of the CLI")
21
+ .option("-u, --update", "update the CLI to the latest version")
22
+ .allowUnknownOption();
23
+
24
+ program.parse(process.argv);
25
+
26
+ const main = async () => {
27
+ const options = {
28
+ install: program.opts().install,
29
+ update: program.opts().update,
30
+ };
31
+ const unknownOptions = program.args;
32
+
33
+ // Manually check for `--help` and handle the CLI `--help`
34
+ if (process.argv.includes("--help")) {
35
+ // Forward to the CLI
36
+ return runCLI(unknownOptions);
37
+ }
38
+
39
+ await parseCommandOptions(options, unknownOptions);
40
+ };
41
+
42
+ main().catch(console.error);
@@ -0,0 +1,55 @@
1
+ import { execSync } from "child_process";
2
+ import { existsSync } from "fs";
3
+
4
+ import { GH_CLI_DOWNLOAD_URL, PNAME } from "../utils/consts.js";
5
+ import { execSyncShell } from "../utils/execSyncShell.js";
6
+ import { getCurrentOpenSSLVersion } from "../utils/versions.js";
7
+ import { getOS } from "../utils/getUserOs.js";
8
+ import { getLatestVersion } from "../utils/getAptosCliLatestVersion.js";
9
+ import { getLocalBinPath } from "../utils/getLocalBinPath.js";
10
+
11
+ // Install the CLI.
12
+ export const installCli = async () => {
13
+ const path = getLocalBinPath();
14
+ if (existsSync(path)) {
15
+ console.log("Aptos CLI is already installed");
16
+ return;
17
+ }
18
+ // Look up the latest version.
19
+ const latestCLIVersion = await getLatestVersion();
20
+ console.log(`Downloading aptos CLI version ${latestCLIVersion}`);
21
+ const os = getOS();
22
+
23
+ if (os === "Windows") {
24
+ const url = `${GH_CLI_DOWNLOAD_URL}/${PNAME}-v${latestCLIVersion}/${PNAME}-${latestCLIVersion}-${os}-x86_64.zip`;
25
+ // Download the zip file, extract it, and move the binary to the correct location.
26
+ execSync(
27
+ `powershell -Command "if (!(Test-Path -Path 'C:\\tmp')) { New-Item -ItemType Directory -Path 'C:\\tmp' } ; Invoke-RestMethod -Uri ${url} -OutFile C:\\tmp\\aptos.zip; Expand-Archive -Path C:\\tmp\\aptos.zip -DestinationPath C:\\tmp -Force; Move-Item -Path C:\\tmp\\aptos.exe -Destination \"${path}\""`
28
+ );
29
+ } else if (os === "MacOS") {
30
+ // Install the CLI with brew.
31
+ execSyncShell("brew install aptos", { encoding: "utf8" });
32
+ } else {
33
+ // On Linux, we check what version of OpenSSL we're working with to figure out
34
+ // which binary to download.
35
+ let osVersion = "x86_64";
36
+ let opensSslVersion = "1.0.0";
37
+ try {
38
+ opensSslVersion = getCurrentOpenSSLVersion();
39
+ } catch (error) {
40
+ console.log(
41
+ "Could not determine OpenSSL version, assuming older version (1.x.x)"
42
+ );
43
+ }
44
+
45
+ if (opensSslVersion.startsWith("3.")) {
46
+ osVersion = "22.04-x86_64";
47
+ }
48
+ console.log(`Downloading CLI binary ${os}-${osVersion}`);
49
+ const url = `${GH_CLI_DOWNLOAD_URL}/${PNAME}-v${latestCLIVersion}/${PNAME}-${latestCLIVersion}-${os}-${osVersion}.zip`;
50
+ // Download the zip file, extract it, and move the binary to the correct location.
51
+ execSync(
52
+ `curl -L -o /tmp/aptos.zip ${url}; unzip -o -q /tmp/aptos.zip -d /tmp; mv /tmp/aptos ${path};`
53
+ );
54
+ }
55
+ };
@@ -0,0 +1,23 @@
1
+ import { spawn } from "child_process";
2
+ import { existsSync } from "fs";
3
+
4
+ import { getOS } from "../utils/getUserOs.js";
5
+ import { getLocalBinPath } from "../utils/getLocalBinPath.js";
6
+
7
+ export const runCLI = async (args: string[] = []) => {
8
+ const path = getLocalBinPath();
9
+ if (!existsSync(path)) {
10
+ console.log(
11
+ "Aptos CLI not installed, run `npx aptos --install` to install"
12
+ );
13
+ return;
14
+ }
15
+ const os = getOS();
16
+
17
+ // Spawn a child process to execute the binary with the provided arguments.
18
+ // Spawn the child process to run the real CLI executable with the forwarded arguments
19
+ spawn(path, args, {
20
+ stdio: "inherit", // Forward the stdio so output is visible
21
+ shell: os === "Windows", // Use shell on Windows
22
+ });
23
+ };
@@ -0,0 +1,33 @@
1
+ import { existsSync } from "fs";
2
+
3
+ import { execSyncShell } from "../utils/execSyncShell.js";
4
+ import { getLatestVersion } from "../utils/getAptosCliLatestVersion.js";
5
+ import { installCli } from "./install.js";
6
+ import { getLocalBinPath } from "../utils/getLocalBinPath.js";
7
+
8
+ export const updateCli = async () => {
9
+ const path = getLocalBinPath();
10
+ if (!existsSync(path)) {
11
+ console.log(
12
+ "Aptos CLI not installed, run `npx aptos --install` to install"
13
+ );
14
+ return;
15
+ }
16
+ // Look up the latest version.
17
+ const latestVersion = await getLatestVersion();
18
+ // Get the current version of the CLI.
19
+ const currentVersion = execSyncShell(`${path} --version`, {
20
+ encoding: "utf8",
21
+ })
22
+ .trim()
23
+ .split(" ")[1];
24
+ // Check if the installed version is the latest version.
25
+ if (currentVersion !== latestVersion) {
26
+ console.log(
27
+ `A newer version of the CLI is available: ${latestVersion}, installing...`
28
+ );
29
+ installCli();
30
+ } else {
31
+ console.log(`CLI is up to date`);
32
+ }
33
+ };
@@ -0,0 +1,14 @@
1
+ import { execSyncShell } from "./execSyncShell.js";
2
+
3
+ /**
4
+ * Only works on Unix systems. This is fine because we only need to check for brew on
5
+ * MacOS.
6
+ */
7
+ export const executableIsAvailable = (name) => {
8
+ try {
9
+ execSyncShell(`which ${name}`, { encoding: "utf8" });
10
+ return true;
11
+ } catch (error) {
12
+ return false;
13
+ }
14
+ };
@@ -0,0 +1,23 @@
1
+ import { execSyncShell } from "./execSyncShell.js";
2
+
3
+ /**
4
+ * Based on the installation path of the aptos formula, determine the path where the
5
+ * CLI should be installed.
6
+ */
7
+ export const getCliPathBrew = () => {
8
+ const directory = execSyncShell("brew --prefix aptos", { encoding: "utf8" })
9
+ .toString()
10
+ .trim();
11
+ return `${directory}/bin/aptos`;
12
+ };
13
+
14
+ /**
15
+ * Use brew to find the latest version of the CLI. Make sure to confirm that brew
16
+ * is installed before calling this function.
17
+ */
18
+ export const getLatestVersionBrew = () => {
19
+ const out = JSON.parse(
20
+ execSyncShell("brew info --json aptos", { encoding: "utf8" })
21
+ );
22
+ return out[0].versions.stable;
23
+ };
@@ -0,0 +1,3 @@
1
+ export const PNAME = "aptos-cli";
2
+ export const GH_CLI_DOWNLOAD_URL =
3
+ "https://github.com/aptos-labs/aptos-core/releases/download";
@@ -0,0 +1,8 @@
1
+ import { execSync } from "child_process";
2
+
3
+ /**
4
+ * Wrapper around execSync that uses the shell.
5
+ */
6
+ export const execSyncShell = (command, options) => {
7
+ return execSync(command, { shell: true, ...options });
8
+ };
@@ -0,0 +1,14 @@
1
+ import { getLatestVersionBrew } from "./brewOperations.js";
2
+ import { getOS } from "./getUserOs.js";
3
+ import { getLatestVersionGh } from "./ghOperations.js";
4
+
5
+ /**
6
+ * Determine the latest version of the CLI.
7
+ */
8
+ export const getLatestVersion = async () => {
9
+ if (getOS() === "MacOS") {
10
+ return getLatestVersionBrew();
11
+ } else {
12
+ return getLatestVersionGh();
13
+ }
14
+ };
@@ -0,0 +1,28 @@
1
+ import { dirname } from "path";
2
+ import { executableIsAvailable } from "./aptosExecutableIsAvailable.js";
3
+ import { getCliPathBrew } from "./brewOperations.js";
4
+ import { PNAME } from "./consts.js";
5
+ import { getOS } from "./getUserOs.js";
6
+ import { fileURLToPath } from "url";
7
+
8
+ export const getLocalBinPath = () => {
9
+ let path;
10
+ const os = getOS();
11
+ if (os === "MacOS") {
12
+ // Confirm brew is installed.
13
+ const brewInstalled = executableIsAvailable("brew");
14
+ if (!brewInstalled) {
15
+ throw "Please install brew to continue: https://brew.sh/";
16
+ }
17
+ try {
18
+ path = getCliPathBrew();
19
+ } catch (e) {
20
+ path = "";
21
+ }
22
+ } else if (os === "Windows") {
23
+ path = `${dirname(fileURLToPath(import.meta.url))}\\${PNAME}.exe`;
24
+ } else {
25
+ path = `${dirname(fileURLToPath(import.meta.url))}/${PNAME}`;
26
+ }
27
+ return path;
28
+ };
@@ -0,0 +1,18 @@
1
+ import { platform } from "os";
2
+
3
+ /**
4
+ * Determine what OS we're running on.
5
+ */
6
+ export const getOS = () => {
7
+ const osPlatform = platform();
8
+ switch (osPlatform) {
9
+ case "darwin":
10
+ return "MacOS";
11
+ case "linux":
12
+ return "Ubuntu";
13
+ case "win32":
14
+ return "Windows";
15
+ default:
16
+ throw new Error(`Unsupported OS ${osPlatform}`);
17
+ }
18
+ };
@@ -0,0 +1,20 @@
1
+ import { PNAME } from "./consts.js";
2
+
3
+ /**
4
+ * Query the GitHub API to find the latest CLI release. We assume that the CLI is in
5
+ * the last 100 releases so we don't paginate through the releases.
6
+ */
7
+ export const getLatestVersionGh = async () => {
8
+ const prefix = `${PNAME}-v`;
9
+ const response = await (
10
+ await fetch(
11
+ "https://api.github.com/repos/aptos-labs/aptos-core/releases?per_page=100"
12
+ )
13
+ ).json();
14
+ for (const release of response) {
15
+ if (release["tag_name"].startsWith(`${prefix}`)) {
16
+ return release.tag_name.replace(`${prefix}`, "");
17
+ }
18
+ }
19
+ throw "Could not determine latest version of Aptos CLI";
20
+ };
@@ -0,0 +1,38 @@
1
+ import { spawnSync } from "child_process";
2
+ import { Command } from "commander";
3
+
4
+ /**
5
+ * Handle the `--help` option for the Aptos CLI. This function is used to combine
6
+ * the Aptos CLI help output with the Commander help output.
7
+ * @param program - The Commander program instance.
8
+ * @param unknownOptions - The unknown options passed to the CLI.
9
+ * @returns void
10
+ */
11
+ export const handleHelpOptions = (
12
+ program: Command,
13
+ unknownOptions: string[]
14
+ ) => {
15
+ // Capture the Aptos CLI help output
16
+ const cliHelp = spawnSync(`aptos`, unknownOptions, {
17
+ stdio: "pipe",
18
+ encoding: "utf-8",
19
+ });
20
+ // Generate Commander help text
21
+ const commanderHelp = program.helpInformation();
22
+
23
+ // Remove the "Usage" and "Options" lines from the Commander output
24
+ const commanderOptionsOnly = commanderHelp
25
+ .split("\n")
26
+ .filter((line) => !line.startsWith("Usage") && !line.startsWith("Options"))
27
+ .join("\n");
28
+
29
+ // Find where the CLI options start and append the Commander options to the existing CLI options
30
+ const combinedHelp = cliHelp.stdout.replace(
31
+ "Options:",
32
+ `Options:\n${commanderOptionsOnly.trim()}`
33
+ );
34
+
35
+ // Output the combined help
36
+ console.log(combinedHelp);
37
+ return;
38
+ };
@@ -0,0 +1,28 @@
1
+ import { existsSync } from "fs";
2
+ import { installCli } from "../tasks/install.js";
3
+ import { runCLI } from "../tasks/run.js";
4
+ import { updateCli } from "../tasks/update.js";
5
+ import { getLocalBinPath } from "./getLocalBinPath.js";
6
+
7
+ export const parseCommandOptions = async (
8
+ options: { install: boolean; update: boolean },
9
+ unknownOptions: string[]
10
+ ) => {
11
+ // if `--install` flag is set, only install the cli and dont run it
12
+ if (options.install) {
13
+ await installCli();
14
+ return;
15
+ }
16
+ // if `--update` flag is set, update the cli and dont run it
17
+ if (options.update) {
18
+ await updateCli();
19
+ return;
20
+ }
21
+
22
+ // if no flags are set, install and run the cli
23
+ const path = getLocalBinPath();
24
+ if (!existsSync(path)) {
25
+ await installCli();
26
+ }
27
+ await runCLI(unknownOptions);
28
+ };
@@ -0,0 +1,9 @@
1
+ import { execSyncShell } from "./execSyncShell.js";
2
+
3
+ /**
4
+ * Determine the current SSL version
5
+ */
6
+ export const getCurrentOpenSSLVersion = () => {
7
+ const out = execSyncShell("openssl version", { encoding: "utf8" });
8
+ return out.split(" ")[1].trim();
9
+ };
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/aptos.js ADDED
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env node
2
+ import { program } from "commander";
3
+ import { parseCommandOptions } from "./utils/parseCommandOptions.js";
4
+ import { runCLI } from "./tasks/run.js";
5
+ program
6
+ .name("aptos")
7
+ .helpOption(false)
8
+ .option("-i, --install", "install the latest version of the CLI")
9
+ .option("-u, --update", "update the CLI to the latest version")
10
+ .allowUnknownOption();
11
+ program.parse(process.argv);
12
+ const main = async () => {
13
+ const options = {
14
+ install: program.opts().install,
15
+ update: program.opts().update,
16
+ };
17
+ const unknownOptions = program.args;
18
+ if (process.argv.includes("--help")) {
19
+ return runCLI(unknownOptions);
20
+ }
21
+ await parseCommandOptions(options, unknownOptions);
22
+ };
23
+ main().catch(console.error);
24
+ //# sourceMappingURL=aptos.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aptos.js","sourceRoot":"","sources":["../bin/aptos.ts"],"names":[],"mappings":";AAWA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAExC,OAAO;KACJ,IAAI,CAAC,OAAO,CAAC;KACb,UAAU,CAAC,KAAK,CAAC;KACjB,MAAM,CAAC,eAAe,EAAE,uCAAuC,CAAC;KAChE,MAAM,CAAC,cAAc,EAAE,sCAAsC,CAAC;KAC9D,kBAAkB,EAAE,CAAC;AAExB,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AAE5B,MAAM,IAAI,GAAG,KAAK,IAAI,EAAE;IACtB,MAAM,OAAO,GAAG;QACd,OAAO,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC,OAAO;QAC/B,MAAM,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC,MAAM;KAC9B,CAAC;IACF,MAAM,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAGpC,IAAI,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;QAEpC,OAAO,MAAM,CAAC,cAAc,CAAC,CAAC;IAChC,CAAC;IAED,MAAM,mBAAmB,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;AACrD,CAAC,CAAC;AAEF,IAAI,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export declare const installCli: () => Promise<void>;
@@ -0,0 +1,42 @@
1
+ import { execSync } from "child_process";
2
+ import { existsSync } from "fs";
3
+ import { GH_CLI_DOWNLOAD_URL, PNAME } from "../utils/consts.js";
4
+ import { execSyncShell } from "../utils/execSyncShell.js";
5
+ import { getCurrentOpenSSLVersion } from "../utils/versions.js";
6
+ import { getOS } from "../utils/getUserOs.js";
7
+ import { getLatestVersion } from "../utils/getAptosCliLatestVersion.js";
8
+ import { getLocalBinPath } from "../utils/getLocalBinPath.js";
9
+ export const installCli = async () => {
10
+ const path = getLocalBinPath();
11
+ if (existsSync(path)) {
12
+ console.log("Aptos CLI is already installed");
13
+ return;
14
+ }
15
+ const latestCLIVersion = await getLatestVersion();
16
+ console.log(`Downloading aptos CLI version ${latestCLIVersion}`);
17
+ const os = getOS();
18
+ if (os === "Windows") {
19
+ const url = `${GH_CLI_DOWNLOAD_URL}/${PNAME}-v${latestCLIVersion}/${PNAME}-${latestCLIVersion}-${os}-x86_64.zip`;
20
+ execSync(`powershell -Command "if (!(Test-Path -Path 'C:\\tmp')) { New-Item -ItemType Directory -Path 'C:\\tmp' } ; Invoke-RestMethod -Uri ${url} -OutFile C:\\tmp\\aptos.zip; Expand-Archive -Path C:\\tmp\\aptos.zip -DestinationPath C:\\tmp -Force; Move-Item -Path C:\\tmp\\aptos.exe -Destination \"${path}\""`);
21
+ }
22
+ else if (os === "MacOS") {
23
+ execSyncShell("brew install aptos", { encoding: "utf8" });
24
+ }
25
+ else {
26
+ let osVersion = "x86_64";
27
+ let opensSslVersion = "1.0.0";
28
+ try {
29
+ opensSslVersion = getCurrentOpenSSLVersion();
30
+ }
31
+ catch (error) {
32
+ console.log("Could not determine OpenSSL version, assuming older version (1.x.x)");
33
+ }
34
+ if (opensSslVersion.startsWith("3.")) {
35
+ osVersion = "22.04-x86_64";
36
+ }
37
+ console.log(`Downloading CLI binary ${os}-${osVersion}`);
38
+ const url = `${GH_CLI_DOWNLOAD_URL}/${PNAME}-v${latestCLIVersion}/${PNAME}-${latestCLIVersion}-${os}-${osVersion}.zip`;
39
+ execSync(`curl -L -o /tmp/aptos.zip ${url}; unzip -o -q /tmp/aptos.zip -d /tmp; mv /tmp/aptos ${path};`);
40
+ }
41
+ };
42
+ //# sourceMappingURL=install.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"install.js","sourceRoot":"","sources":["../../bin/tasks/install.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAEhC,OAAO,EAAE,mBAAmB,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AAChE,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AACxE,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAG9D,MAAM,CAAC,MAAM,UAAU,GAAG,KAAK,IAAI,EAAE;IACnC,MAAM,IAAI,GAAG,eAAe,EAAE,CAAC;IAC/B,IAAI,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QACrB,OAAO,CAAC,GAAG,CAAC,gCAAgC,CAAC,CAAC;QAC9C,OAAO;IACT,CAAC;IAED,MAAM,gBAAgB,GAAG,MAAM,gBAAgB,EAAE,CAAC;IAClD,OAAO,CAAC,GAAG,CAAC,iCAAiC,gBAAgB,EAAE,CAAC,CAAC;IACjE,MAAM,EAAE,GAAG,KAAK,EAAE,CAAC;IAEnB,IAAI,EAAE,KAAK,SAAS,EAAE,CAAC;QACrB,MAAM,GAAG,GAAG,GAAG,mBAAmB,IAAI,KAAK,KAAK,gBAAgB,IAAI,KAAK,IAAI,gBAAgB,IAAI,EAAE,aAAa,CAAC;QAEjH,QAAQ,CACN,oIAAoI,GAAG,4JAA4J,IAAI,KAAK,CAC7S,CAAC;IACJ,CAAC;SAAM,IAAI,EAAE,KAAK,OAAO,EAAE,CAAC;QAE1B,aAAa,CAAC,oBAAoB,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;IAC5D,CAAC;SAAM,CAAC;QAGN,IAAI,SAAS,GAAG,QAAQ,CAAC;QACzB,IAAI,eAAe,GAAG,OAAO,CAAC;QAC9B,IAAI,CAAC;YACH,eAAe,GAAG,wBAAwB,EAAE,CAAC;QAC/C,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,GAAG,CACT,qEAAqE,CACtE,CAAC;QACJ,CAAC;QAED,IAAI,eAAe,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;YACrC,SAAS,GAAG,cAAc,CAAC;QAC7B,CAAC;QACD,OAAO,CAAC,GAAG,CAAC,0BAA0B,EAAE,IAAI,SAAS,EAAE,CAAC,CAAC;QACzD,MAAM,GAAG,GAAG,GAAG,mBAAmB,IAAI,KAAK,KAAK,gBAAgB,IAAI,KAAK,IAAI,gBAAgB,IAAI,EAAE,IAAI,SAAS,MAAM,CAAC;QAEvH,QAAQ,CACN,6BAA6B,GAAG,uDAAuD,IAAI,GAAG,CAC/F,CAAC;IACJ,CAAC;AACH,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export declare const runCLI: (args?: string[]) => Promise<void>;
@@ -0,0 +1,17 @@
1
+ import { spawn } from "child_process";
2
+ import { existsSync } from "fs";
3
+ import { getOS } from "../utils/getUserOs.js";
4
+ import { getLocalBinPath } from "../utils/getLocalBinPath.js";
5
+ export const runCLI = async (args = []) => {
6
+ const path = getLocalBinPath();
7
+ if (!existsSync(path)) {
8
+ console.log("Aptos CLI not installed, run `npx aptos --install` to install");
9
+ return;
10
+ }
11
+ const os = getOS();
12
+ spawn(path, args, {
13
+ stdio: "inherit",
14
+ shell: os === "Windows",
15
+ });
16
+ };
17
+ //# sourceMappingURL=run.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run.js","sourceRoot":"","sources":["../../bin/tasks/run.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAEhC,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAE9D,MAAM,CAAC,MAAM,MAAM,GAAG,KAAK,EAAE,OAAiB,EAAE,EAAE,EAAE;IAClD,MAAM,IAAI,GAAG,eAAe,EAAE,CAAC;IAC/B,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QACtB,OAAO,CAAC,GAAG,CACT,+DAA+D,CAChE,CAAC;QACF,OAAO;IACT,CAAC;IACD,MAAM,EAAE,GAAG,KAAK,EAAE,CAAC;IAInB,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE;QAChB,KAAK,EAAE,SAAS;QAChB,KAAK,EAAE,EAAE,KAAK,SAAS;KACxB,CAAC,CAAC;AACL,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export declare const updateCli: () => Promise<void>;
@@ -0,0 +1,26 @@
1
+ import { existsSync } from "fs";
2
+ import { execSyncShell } from "../utils/execSyncShell.js";
3
+ import { getLatestVersion } from "../utils/getAptosCliLatestVersion.js";
4
+ import { installCli } from "./install.js";
5
+ import { getLocalBinPath } from "../utils/getLocalBinPath.js";
6
+ export const updateCli = async () => {
7
+ const path = getLocalBinPath();
8
+ if (!existsSync(path)) {
9
+ console.log("Aptos CLI not installed, run `npx aptos --install` to install");
10
+ return;
11
+ }
12
+ const latestVersion = await getLatestVersion();
13
+ const currentVersion = execSyncShell(`${path} --version`, {
14
+ encoding: "utf8",
15
+ })
16
+ .trim()
17
+ .split(" ")[1];
18
+ if (currentVersion !== latestVersion) {
19
+ console.log(`A newer version of the CLI is available: ${latestVersion}, installing...`);
20
+ installCli();
21
+ }
22
+ else {
23
+ console.log(`CLI is up to date`);
24
+ }
25
+ };
26
+ //# sourceMappingURL=update.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"update.js","sourceRoot":"","sources":["../../bin/tasks/update.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAEhC,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AACxE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAE9D,MAAM,CAAC,MAAM,SAAS,GAAG,KAAK,IAAI,EAAE;IAClC,MAAM,IAAI,GAAG,eAAe,EAAE,CAAC;IAC/B,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QACtB,OAAO,CAAC,GAAG,CACT,+DAA+D,CAChE,CAAC;QACF,OAAO;IACT,CAAC;IAED,MAAM,aAAa,GAAG,MAAM,gBAAgB,EAAE,CAAC;IAE/C,MAAM,cAAc,GAAG,aAAa,CAAC,GAAG,IAAI,YAAY,EAAE;QACxD,QAAQ,EAAE,MAAM;KACjB,CAAC;SACC,IAAI,EAAE;SACN,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAEjB,IAAI,cAAc,KAAK,aAAa,EAAE,CAAC;QACrC,OAAO,CAAC,GAAG,CACT,4CAA4C,aAAa,iBAAiB,CAC3E,CAAC;QACF,UAAU,EAAE,CAAC;IACf,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;IACnC,CAAC;AACH,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export declare const executableIsAvailable: (name: any) => boolean;
@@ -0,0 +1,11 @@
1
+ import { execSyncShell } from "./execSyncShell.js";
2
+ export const executableIsAvailable = (name) => {
3
+ try {
4
+ execSyncShell(`which ${name}`, { encoding: "utf8" });
5
+ return true;
6
+ }
7
+ catch (error) {
8
+ return false;
9
+ }
10
+ };
11
+ //# sourceMappingURL=aptosExecutableIsAvailable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aptosExecutableIsAvailable.js","sourceRoot":"","sources":["../../bin/utils/aptosExecutableIsAvailable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAMnD,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,IAAI,EAAE,EAAE;IAC5C,IAAI,CAAC;QACH,aAAa,CAAC,SAAS,IAAI,EAAE,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;QACrD,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const getCliPathBrew: () => string;
2
+ export declare const getLatestVersionBrew: () => any;
@@ -0,0 +1,12 @@
1
+ import { execSyncShell } from "./execSyncShell.js";
2
+ export const getCliPathBrew = () => {
3
+ const directory = execSyncShell("brew --prefix aptos", { encoding: "utf8" })
4
+ .toString()
5
+ .trim();
6
+ return `${directory}/bin/aptos`;
7
+ };
8
+ export const getLatestVersionBrew = () => {
9
+ const out = JSON.parse(execSyncShell("brew info --json aptos", { encoding: "utf8" }));
10
+ return out[0].versions.stable;
11
+ };
12
+ //# sourceMappingURL=brewOperations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"brewOperations.js","sourceRoot":"","sources":["../../bin/utils/brewOperations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAMnD,MAAM,CAAC,MAAM,cAAc,GAAG,GAAG,EAAE;IACjC,MAAM,SAAS,GAAG,aAAa,CAAC,qBAAqB,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;SACzE,QAAQ,EAAE;SACV,IAAI,EAAE,CAAC;IACV,OAAO,GAAG,SAAS,YAAY,CAAC;AAClC,CAAC,CAAC;AAMF,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAAG,EAAE;IACvC,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CACpB,aAAa,CAAC,wBAAwB,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAC9D,CAAC;IACF,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC;AAChC,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const PNAME = "aptos-cli";
2
+ export declare const GH_CLI_DOWNLOAD_URL = "https://github.com/aptos-labs/aptos-core/releases/download";
@@ -0,0 +1,3 @@
1
+ export const PNAME = "aptos-cli";
2
+ export const GH_CLI_DOWNLOAD_URL = "https://github.com/aptos-labs/aptos-core/releases/download";
3
+ //# sourceMappingURL=consts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consts.js","sourceRoot":"","sources":["../../bin/utils/consts.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,KAAK,GAAG,WAAW,CAAC;AACjC,MAAM,CAAC,MAAM,mBAAmB,GAC9B,4DAA4D,CAAC"}
@@ -0,0 +1 @@
1
+ export declare const execSyncShell: (command: any, options: any) => string;
@@ -0,0 +1,5 @@
1
+ import { execSync } from "child_process";
2
+ export const execSyncShell = (command, options) => {
3
+ return execSync(command, { shell: true, ...options });
4
+ };
5
+ //# sourceMappingURL=execSyncShell.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execSyncShell.js","sourceRoot":"","sources":["../../bin/utils/execSyncShell.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAKzC,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE;IAChD,OAAO,QAAQ,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;AACxD,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export declare const getLatestVersion: () => Promise<any>;
@@ -0,0 +1,12 @@
1
+ import { getLatestVersionBrew } from "./brewOperations.js";
2
+ import { getOS } from "./getUserOs.js";
3
+ import { getLatestVersionGh } from "./ghOperations.js";
4
+ export const getLatestVersion = async () => {
5
+ if (getOS() === "MacOS") {
6
+ return getLatestVersionBrew();
7
+ }
8
+ else {
9
+ return getLatestVersionGh();
10
+ }
11
+ };
12
+ //# sourceMappingURL=getAptosCliLatestVersion.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getAptosCliLatestVersion.js","sourceRoot":"","sources":["../../bin/utils/getAptosCliLatestVersion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAKvD,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,IAAI,EAAE;IACzC,IAAI,KAAK,EAAE,KAAK,OAAO,EAAE,CAAC;QACxB,OAAO,oBAAoB,EAAE,CAAC;IAChC,CAAC;SAAM,CAAC;QACN,OAAO,kBAAkB,EAAE,CAAC;IAC9B,CAAC;AACH,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export declare const getLocalBinPath: () => any;
@@ -0,0 +1,30 @@
1
+ import { dirname } from "path";
2
+ import { executableIsAvailable } from "./aptosExecutableIsAvailable.js";
3
+ import { getCliPathBrew } from "./brewOperations.js";
4
+ import { PNAME } from "./consts.js";
5
+ import { getOS } from "./getUserOs.js";
6
+ import { fileURLToPath } from "url";
7
+ export const getLocalBinPath = () => {
8
+ let path;
9
+ const os = getOS();
10
+ if (os === "MacOS") {
11
+ const brewInstalled = executableIsAvailable("brew");
12
+ if (!brewInstalled) {
13
+ throw "Please install brew to continue: https://brew.sh/";
14
+ }
15
+ try {
16
+ path = getCliPathBrew();
17
+ }
18
+ catch (e) {
19
+ path = "";
20
+ }
21
+ }
22
+ else if (os === "Windows") {
23
+ path = `${dirname(fileURLToPath(import.meta.url))}\\${PNAME}.exe`;
24
+ }
25
+ else {
26
+ path = `${dirname(fileURLToPath(import.meta.url))}/${PNAME}`;
27
+ }
28
+ return path;
29
+ };
30
+ //# sourceMappingURL=getLocalBinPath.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getLocalBinPath.js","sourceRoot":"","sources":["../../bin/utils/getLocalBinPath.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC/B,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AAEpC,MAAM,CAAC,MAAM,eAAe,GAAG,GAAG,EAAE;IAClC,IAAI,IAAI,CAAC;IACT,MAAM,EAAE,GAAG,KAAK,EAAE,CAAC;IACnB,IAAI,EAAE,KAAK,OAAO,EAAE,CAAC;QAEnB,MAAM,aAAa,GAAG,qBAAqB,CAAC,MAAM,CAAC,CAAC;QACpD,IAAI,CAAC,aAAa,EAAE,CAAC;YACnB,MAAM,mDAAmD,CAAC;QAC5D,CAAC;QACD,IAAI,CAAC;YACH,IAAI,GAAG,cAAc,EAAE,CAAC;QAC1B,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,IAAI,GAAG,EAAE,CAAC;QACZ,CAAC;IACH,CAAC;SAAM,IAAI,EAAE,KAAK,SAAS,EAAE,CAAC;QAC5B,IAAI,GAAG,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,KAAK,MAAM,CAAC;IACpE,CAAC;SAAM,CAAC;QACN,IAAI,GAAG,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,KAAK,EAAE,CAAC;IAC/D,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export declare const getOS: () => "MacOS" | "Ubuntu" | "Windows";
@@ -0,0 +1,15 @@
1
+ import { platform } from "os";
2
+ export const getOS = () => {
3
+ const osPlatform = platform();
4
+ switch (osPlatform) {
5
+ case "darwin":
6
+ return "MacOS";
7
+ case "linux":
8
+ return "Ubuntu";
9
+ case "win32":
10
+ return "Windows";
11
+ default:
12
+ throw new Error(`Unsupported OS ${osPlatform}`);
13
+ }
14
+ };
15
+ //# sourceMappingURL=getUserOs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getUserOs.js","sourceRoot":"","sources":["../../bin/utils/getUserOs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AAK9B,MAAM,CAAC,MAAM,KAAK,GAAG,GAAG,EAAE;IACxB,MAAM,UAAU,GAAG,QAAQ,EAAE,CAAC;IAC9B,QAAQ,UAAU,EAAE,CAAC;QACnB,KAAK,QAAQ;YACX,OAAO,OAAO,CAAC;QACjB,KAAK,OAAO;YACV,OAAO,QAAQ,CAAC;QAClB,KAAK,OAAO;YACV,OAAO,SAAS,CAAC;QACnB;YACE,MAAM,IAAI,KAAK,CAAC,kBAAkB,UAAU,EAAE,CAAC,CAAC;IACpD,CAAC;AACH,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export declare const getLatestVersionGh: () => Promise<any>;
@@ -0,0 +1,12 @@
1
+ import { PNAME } from "./consts.js";
2
+ export const getLatestVersionGh = async () => {
3
+ const prefix = `${PNAME}-v`;
4
+ const response = await (await fetch("https://api.github.com/repos/aptos-labs/aptos-core/releases?per_page=100")).json();
5
+ for (const release of response) {
6
+ if (release["tag_name"].startsWith(`${prefix}`)) {
7
+ return release.tag_name.replace(`${prefix}`, "");
8
+ }
9
+ }
10
+ throw "Could not determine latest version of Aptos CLI";
11
+ };
12
+ //# sourceMappingURL=ghOperations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ghOperations.js","sourceRoot":"","sources":["../../bin/utils/ghOperations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAMpC,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,IAAI,EAAE;IAC3C,MAAM,MAAM,GAAG,GAAG,KAAK,IAAI,CAAC;IAC5B,MAAM,QAAQ,GAAG,MAAM,CACrB,MAAM,KAAK,CACT,0EAA0E,CAC3E,CACF,CAAC,IAAI,EAAE,CAAC;IACT,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,IAAI,OAAO,CAAC,UAAU,CAAC,CAAC,UAAU,CAAC,GAAG,MAAM,EAAE,CAAC,EAAE,CAAC;YAChD,OAAO,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC;QACnD,CAAC;IACH,CAAC;IACD,MAAM,iDAAiD,CAAC;AAC1D,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { Command } from "commander";
2
+ export declare const handleHelpOptions: (program: Command, unknownOptions: string[]) => void;
@@ -0,0 +1,16 @@
1
+ import { spawnSync } from "child_process";
2
+ export const handleHelpOptions = (program, unknownOptions) => {
3
+ const cliHelp = spawnSync(`aptos`, unknownOptions, {
4
+ stdio: "pipe",
5
+ encoding: "utf-8",
6
+ });
7
+ const commanderHelp = program.helpInformation();
8
+ const commanderOptionsOnly = commanderHelp
9
+ .split("\n")
10
+ .filter((line) => !line.startsWith("Usage") && !line.startsWith("Options"))
11
+ .join("\n");
12
+ const combinedHelp = cliHelp.stdout.replace("Options:", `Options:\n${commanderOptionsOnly.trim()}`);
13
+ console.log(combinedHelp);
14
+ return;
15
+ };
16
+ //# sourceMappingURL=handleHelpOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handleHelpOptions.js","sourceRoot":"","sources":["../../bin/utils/handleHelpOptions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAU1C,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,OAAgB,EAChB,cAAwB,EACxB,EAAE;IAEF,MAAM,OAAO,GAAG,SAAS,CAAC,OAAO,EAAE,cAAc,EAAE;QACjD,KAAK,EAAE,MAAM;QACb,QAAQ,EAAE,OAAO;KAClB,CAAC,CAAC;IAEH,MAAM,aAAa,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC;IAGhD,MAAM,oBAAoB,GAAG,aAAa;SACvC,KAAK,CAAC,IAAI,CAAC;SACX,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;SAC1E,IAAI,CAAC,IAAI,CAAC,CAAC;IAGd,MAAM,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,OAAO,CACzC,UAAU,EACV,aAAa,oBAAoB,CAAC,IAAI,EAAE,EAAE,CAC3C,CAAC;IAGF,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;IAC1B,OAAO;AACT,CAAC,CAAC"}
@@ -0,0 +1,4 @@
1
+ export declare const parseCommandOptions: (options: {
2
+ install: boolean;
3
+ update: boolean;
4
+ }, unknownOptions: string[]) => Promise<void>;
@@ -0,0 +1,21 @@
1
+ import { existsSync } from "fs";
2
+ import { installCli } from "../tasks/install.js";
3
+ import { runCLI } from "../tasks/run.js";
4
+ import { updateCli } from "../tasks/update.js";
5
+ import { getLocalBinPath } from "./getLocalBinPath.js";
6
+ export const parseCommandOptions = async (options, unknownOptions) => {
7
+ if (options.install) {
8
+ await installCli();
9
+ return;
10
+ }
11
+ if (options.update) {
12
+ await updateCli();
13
+ return;
14
+ }
15
+ const path = getLocalBinPath();
16
+ if (!existsSync(path)) {
17
+ await installCli();
18
+ }
19
+ await runCLI(unknownOptions);
20
+ };
21
+ //# sourceMappingURL=parseCommandOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parseCommandOptions.js","sourceRoot":"","sources":["../../bin/utils/parseCommandOptions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAChC,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,EACtC,OAA8C,EAC9C,cAAwB,EACxB,EAAE;IAEF,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;QACpB,MAAM,UAAU,EAAE,CAAC;QACnB,OAAO;IACT,CAAC;IAED,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;QACnB,MAAM,SAAS,EAAE,CAAC;QAClB,OAAO;IACT,CAAC;IAGD,MAAM,IAAI,GAAG,eAAe,EAAE,CAAC;IAC/B,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QACtB,MAAM,UAAU,EAAE,CAAC;IACrB,CAAC;IACD,MAAM,MAAM,CAAC,cAAc,CAAC,CAAC;AAC/B,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export declare const getCurrentOpenSSLVersion: () => string;
@@ -0,0 +1,6 @@
1
+ import { execSyncShell } from "./execSyncShell.js";
2
+ export const getCurrentOpenSSLVersion = () => {
3
+ const out = execSyncShell("openssl version", { encoding: "utf8" });
4
+ return out.split(" ")[1].trim();
5
+ };
6
+ //# sourceMappingURL=versions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"versions.js","sourceRoot":"","sources":["../../bin/utils/versions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAKnD,MAAM,CAAC,MAAM,wBAAwB,GAAG,GAAG,EAAE;IAC3C,MAAM,GAAG,GAAG,aAAa,CAAC,iBAAiB,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;IACnE,OAAO,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;AAClC,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,10 +1,38 @@
1
1
  {
2
2
  "name": "@aptos-labs/aptos-cli",
3
- "version": "0.2.0",
3
+ "version": "1.0.1",
4
4
  "description": "Aptos CLI available from npmjs",
5
5
  "bin": {
6
- "aptos": "bin/aptos"
6
+ "aptos": "./dist/aptos.js"
7
7
  },
8
- "author": "",
9
- "license": "ISC"
8
+ "type": "module",
9
+ "author": "aptoslabs.com",
10
+ "keywords": [
11
+ "aptos node cli",
12
+ "aptos"
13
+ ],
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/aptos-labs/aptos-cli"
17
+ },
18
+ "bugs": {
19
+ "url": "https://github.com/aptos-labs/aptos-cli/issues"
20
+ },
21
+ "license": "Apache-2.0",
22
+ "scripts": {
23
+ "clean": "rm -rf dist",
24
+ "build": "npm run clean && tsc",
25
+ "dev": "npm run build && node ./dist/aptos.js"
26
+ },
27
+ "files": [
28
+ "bin",
29
+ "dist"
30
+ ],
31
+ "dependencies": {
32
+ "commander": "^12.1.0"
33
+ },
34
+ "devDependencies": {
35
+ "@types/node": "^20.5.0",
36
+ "typescript": "^5.6.2"
37
+ }
10
38
  }
@@ -1,18 +0,0 @@
1
- name: Run bin script on Mac
2
-
3
- on:
4
- pull_request:
5
- push:
6
- branches:
7
- - main
8
-
9
- jobs:
10
- build:
11
- runs-on: macos-latest
12
- concurrency: ci-${{ github.ref }}-${{ github.workflow }}
13
- steps:
14
- - name: Checkout repository
15
- uses: actions/checkout@v3
16
-
17
- - name: Run the bin script on Mac
18
- run: node bin/aptos
@@ -1,18 +0,0 @@
1
- name: Run bin script on Ubuntu
2
-
3
- on:
4
- pull_request:
5
- push:
6
- branches:
7
- - main
8
-
9
- jobs:
10
- build:
11
- runs-on: ubuntu-latest
12
- concurrency: ci-${{ github.ref }}-${{ github.workflow }}
13
- steps:
14
- - name: Checkout repository
15
- uses: actions/checkout@v3
16
-
17
- - name: Run the bin script on Ubuntu
18
- run: node bin/aptos
@@ -1,19 +0,0 @@
1
- name: Run bin script on Windows
2
-
3
- on:
4
- pull_request:
5
- push:
6
- branches:
7
- - main
8
-
9
- jobs:
10
- build:
11
- runs-on: windows-latest
12
- concurrency: ci-${{ github.ref }}-${{ github.workflow }}
13
- steps:
14
- - name: Checkout repository
15
- uses: actions/checkout@v3
16
-
17
- - name: Run the bin script on Windows
18
- run: node bin/aptos
19
- shell: cmd
package/CONTRIBUTING.md DELETED
@@ -1,8 +0,0 @@
1
- # Contributing
2
-
3
- ## Testing
4
- To test changes to the script, do this:
5
- ```
6
- pnpm install
7
- ./bin/aptos
8
- ```
package/bin/aptos DELETED
@@ -1,201 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- // On MacOS we install the CLI with brew. There are two main reasons for this:
4
- // 1. Brew builds the CLI for the native CPU architecture for the user, which
5
- // eliminates any issues arising from using x86 binaries on ARM machines.
6
- // 2. Brew handles dependency management for us. This isn't relevant right now but
7
- // might become necessary later if we reintroduce OpenSSL as a dep for the CLI.
8
- //
9
- // On Linux and Windows we just query the GH API for the latest CLI release and
10
- // download and extract that.
11
-
12
- const { execSync, spawn } = require("child_process");
13
- const fs = require("fs");
14
- const os = require("os");
15
-
16
- const PNAME = "aptos-cli";
17
- const GH_CLI_DOWNLOAD_URL =
18
- "https://github.com/aptos-labs/aptos-core/releases/download";
19
-
20
- // Wrapper around execSync that uses the shell.
21
- const execSyncShell = (command, options) => {
22
- return execSync(command, { shell: true, ...options });
23
- };
24
-
25
- // Determine what OS we're running on.
26
- const getOS = () => {
27
- const platform = os.platform();
28
- switch (platform) {
29
- case "darwin":
30
- return "MacOS";
31
- case "linux":
32
- return "Ubuntu";
33
- case "win32":
34
- return "Windows";
35
- default:
36
- throw new Error(`Unsupported OS ${platform}`);
37
- }
38
- };
39
-
40
- // Only works on Unix systems. This is fine because we only need to check for brew on
41
- // MacOS.
42
- const executableIsAvailable = (name) => {
43
- try {
44
- execSyncShell(`which ${name}`, { encoding: "utf8" });
45
- return true;
46
- } catch (error) {
47
- return false;
48
- }
49
- };
50
-
51
- // Query the GitHub API to find the latest CLI release. We assume that the CLI is in
52
- // the last 100 releases so we don't paginate through the releases.
53
- const getLatestVersionGh = async () => {
54
- const prefix = `${PNAME}-v`;
55
- const response = await (
56
- await fetch(
57
- "https://api.github.com/repos/aptos-labs/aptos-core/releases?per_page=100"
58
- )
59
- ).json();
60
- for (release of response) {
61
- if (release["tag_name"].startsWith(`${prefix}`)) {
62
- return release.tag_name.replace(`${prefix}`, "");
63
- }
64
- }
65
- throw "Could not determine latest version of Aptos CLI";
66
- };
67
-
68
- // Use brew to find the latest version of the CLI. Make sure to confirm that brew
69
- // is installed before calling this function.
70
- const getLatestVersionBrew = () => {
71
- const out = JSON.parse(
72
- execSyncShell("brew info --json aptos", { encoding: "utf8" })
73
- );
74
- return out[0].versions.stable;
75
- };
76
-
77
- // Determine the latest version of the CLI.
78
- const getLatestVersion = async () => {
79
- if (getOS() === "MacOS") {
80
- return getLatestVersionBrew();
81
- } else {
82
- return getLatestVersionGh();
83
- }
84
- };
85
-
86
- // Determine the current SSL version
87
- const getCurrentOpenSSLVersion = () => {
88
- const out = execSyncShell("openssl version", { encoding: "utf8" });
89
- return out.split(" ")[1].trim();
90
- };
91
-
92
- // Based on the installation path of the aptos formula, determine the path where the
93
- // CLI should be installed.
94
- const getCliPathBrew = () => {
95
- const directory = execSyncShell("brew --prefix aptos", { encoding: "utf8" })
96
- .toString()
97
- .trim();
98
- return `${directory}/bin/aptos`;
99
- };
100
-
101
- // Install or update the CLI.
102
- const installCli = (os, path, latestCLIVersion) => {
103
- console.log(`Downloading aptos CLI version ${latestCLIVersion}`);
104
- if (os === "Windows") {
105
- const url = `${GH_CLI_DOWNLOAD_URL}/${PNAME}-v${latestCLIVersion}/${PNAME}-${latestCLIVersion}-${os}-x86_64.zip`;
106
- // Download the zip file, extract it, and move the binary to the correct location.
107
- execSync(
108
- `powershell -Command "if (!(Test-Path -Path 'C:\\tmp')) { New-Item -ItemType Directory -Path 'C:\\tmp' } ; Invoke-RestMethod -Uri ${url} -OutFile C:\\tmp\\aptos.zip; Expand-Archive -Path C:\\tmp\\aptos.zip -DestinationPath C:\\tmp -Force; Move-Item -Path C:\\tmp\\aptos.exe -Destination ${path}"`
109
- );
110
- } else if (os === "MacOS") {
111
- // Install the CLI with brew.
112
- execSyncShell("brew install aptos");
113
- // Get the path of the CLI.
114
- path = getCliPathBrew();
115
- } else {
116
- // On Linux, we check what version of OpenSSL we're working with to figure out
117
- // which binary to download.
118
- let osVersion = "x86_64";
119
- let opensSslVersion = "1.0.0";
120
- try {
121
- opensSslVersion = getCurrentOpenSSLVersion();
122
- } catch (error) {
123
- console.log(
124
- "Could not determine OpenSSL version, assuming older version (1.x.x)"
125
- );
126
- }
127
-
128
- if (opensSslVersion.startsWith("3.")) {
129
- osVersion = "22.04-x86_64";
130
- }
131
- console.log(`Downloading CLI binary ${os}-${osVersion}`);
132
- const url = `${GH_CLI_DOWNLOAD_URL}/${PNAME}-v${latestCLIVersion}/${PNAME}-${latestCLIVersion}-${os}-${osVersion}.zip`;
133
- // Download the zip file, extract it, and move the binary to the correct location.
134
- execSync(
135
- `curl -L -o /tmp/aptos.zip ${url}; unzip -o -q /tmp/aptos.zip -d /tmp; mv /tmp/aptos ${path};`
136
- );
137
- }
138
- };
139
-
140
- const main = async () => {
141
- const os = getOS();
142
-
143
- let path;
144
- if (os === "MacOS") {
145
- // Confirm brew is installed.
146
- const brewInstalled = executableIsAvailable("brew");
147
- if (!brewInstalled) {
148
- throw "Please install brew to continue: https://brew.sh/";
149
- }
150
- try {
151
- path = getCliPathBrew();
152
- } catch (e) {
153
- path = "";
154
- }
155
- } else if (os === "Windows") {
156
- path = `${__dirname}\\${PNAME}.exe`;
157
- } else {
158
- path = `${__dirname}/${PNAME}`;
159
- }
160
-
161
- // Look up the latest version.
162
- const latestVersion = await getLatestVersion();
163
-
164
- // If binary does not exist, download it.
165
- if (!fs.existsSync(path)) {
166
- console.log("CLI not installed");
167
- // Install the latest version.
168
- installCli(os, path, latestVersion);
169
- } else {
170
- // Get the current version of the CLI.
171
- const currentVersion = execSyncShell(`${path} --version`, {
172
- encoding: "utf8",
173
- })
174
- .trim()
175
- .split(" ")[1];
176
- console.log(
177
- `Previously installed CLI version ${currentVersion}, checking for updates`
178
- );
179
- // Check if the installed version is the latest version.
180
- if (currentVersion !== latestVersion) {
181
- console.log(`A newer version of the CLI is available: ${latestVersion}`);
182
- installCli(os, path, latestVersion);
183
- } else {
184
- console.log(`CLI is up to date`);
185
- }
186
- }
187
-
188
- // Spawn a child process to execute the binary with the provided arguments.
189
- if (os === "Windows") {
190
- spawn(path, process.argv.slice(2), {
191
- stdio: "inherit",
192
- shell: true,
193
- });
194
- } else {
195
- spawn(path, process.argv.slice(2), {
196
- stdio: "inherit",
197
- });
198
- }
199
- };
200
-
201
- main().catch(console.error);