@aptos-labs/aptos-cli 0.1.2 → 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/bin/aptos +29 -14
- package/package.json +2 -2
package/bin/aptos
CHANGED
|
@@ -18,7 +18,7 @@ const PNAME = "aptos-cli";
|
|
|
18
18
|
// Wrapper around execSync that uses the shell.
|
|
19
19
|
const execSyncShell = (command, options) => {
|
|
20
20
|
return execSync(command, { shell: true, ...options });
|
|
21
|
-
}
|
|
21
|
+
};
|
|
22
22
|
|
|
23
23
|
// Determine what OS we're running on.
|
|
24
24
|
const getOS = () => {
|
|
@@ -44,34 +44,42 @@ const executableIsAvailable = (name) => {
|
|
|
44
44
|
} catch (error) {
|
|
45
45
|
return false;
|
|
46
46
|
}
|
|
47
|
-
}
|
|
47
|
+
};
|
|
48
48
|
|
|
49
49
|
// Query the GitHub API to find the latest CLI release. We assume that the CLI is in
|
|
50
50
|
// the last 100 releases so we don't paginate through the releases.
|
|
51
51
|
const getLatestVersionGh = async () => {
|
|
52
52
|
const prefix = `${PNAME}-v`;
|
|
53
|
-
const response = await (
|
|
53
|
+
const response = await (
|
|
54
|
+
await fetch(
|
|
55
|
+
"https://api.github.com/repos/aptos-labs/aptos-core/releases?per_page=100"
|
|
56
|
+
)
|
|
57
|
+
).json();
|
|
54
58
|
for (release of response) {
|
|
55
59
|
if (release["tag_name"].startsWith(`${prefix}`)) {
|
|
56
60
|
return release.tag_name.replace(`${prefix}`, "");
|
|
57
61
|
}
|
|
58
62
|
}
|
|
59
63
|
throw "Could not determine latest version of Aptos CLI";
|
|
60
|
-
}
|
|
64
|
+
};
|
|
61
65
|
|
|
62
66
|
// Use brew to find the latest version of the CLI. Make sure to confirm that brew
|
|
63
67
|
// is installed before calling this function.
|
|
64
68
|
const getLatestVersionBrew = () => {
|
|
65
|
-
const out = JSON.parse(
|
|
69
|
+
const out = JSON.parse(
|
|
70
|
+
execSyncShell("brew info --json aptos", { encoding: "utf8" })
|
|
71
|
+
);
|
|
66
72
|
return out[0].versions.stable;
|
|
67
|
-
}
|
|
73
|
+
};
|
|
68
74
|
|
|
69
75
|
// Based on the installation path of the aptos formula, determine the path where the
|
|
70
76
|
// CLI should be installed.
|
|
71
77
|
const getCliPathBrew = () => {
|
|
72
|
-
const directory = execSyncShell("brew --prefix aptos", { encoding: "utf8" })
|
|
78
|
+
const directory = execSyncShell("brew --prefix aptos", { encoding: "utf8" })
|
|
79
|
+
.toString()
|
|
80
|
+
.trim();
|
|
73
81
|
return `${directory}/bin/aptos`;
|
|
74
|
-
}
|
|
82
|
+
};
|
|
75
83
|
|
|
76
84
|
const main = async () => {
|
|
77
85
|
const os = getOS();
|
|
@@ -89,7 +97,7 @@ const main = async () => {
|
|
|
89
97
|
path = "";
|
|
90
98
|
}
|
|
91
99
|
} else {
|
|
92
|
-
path = `${__dirname}
|
|
100
|
+
path = `${__dirname}\\${PNAME}.exe`;
|
|
93
101
|
}
|
|
94
102
|
|
|
95
103
|
// If binary does not exist, download it.
|
|
@@ -108,7 +116,7 @@ const main = async () => {
|
|
|
108
116
|
if (os === "Windows") {
|
|
109
117
|
// Download the zip file, extract it, and move the binary to the correct location.
|
|
110
118
|
execSync(
|
|
111
|
-
`curl -L -o C:/tmp/aptos.zip ${url} & powershell Expand-Archive -Path C:/tmp/aptos.zip -DestinationPath C:/tmp -Force & move C:\\tmp\\aptos.exe ${path}
|
|
119
|
+
`curl -L -o C:/tmp/aptos.zip ${url} & powershell Expand-Archive -Path C:/tmp/aptos.zip -DestinationPath C:/tmp -Force & move C:\\tmp\\aptos.exe ${path}.exe`
|
|
112
120
|
);
|
|
113
121
|
} else if (os === "MacOS") {
|
|
114
122
|
// Install the CLI with brew.
|
|
@@ -118,15 +126,22 @@ const main = async () => {
|
|
|
118
126
|
} else {
|
|
119
127
|
// Download the zip file, extract it, and move the binary to the correct location.
|
|
120
128
|
execSync(
|
|
121
|
-
`curl -L -o /tmp/aptos.zip ${url}; unzip -o -q /tmp/aptos.zip -d /tmp; mv /tmp/aptos ${path}
|
|
129
|
+
`curl -L -o /tmp/aptos.zip ${url}; unzip -o -q /tmp/aptos.zip -d /tmp; mv /tmp/aptos ${path};`
|
|
122
130
|
);
|
|
123
131
|
}
|
|
124
132
|
}
|
|
125
133
|
|
|
126
134
|
// Spawn a child process to execute the binary with the provided arguments.
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
135
|
+
if (os === "MacOS") {
|
|
136
|
+
spawn(path, process.argv.slice(2), {
|
|
137
|
+
stdio: "inherit",
|
|
138
|
+
});
|
|
139
|
+
} else {
|
|
140
|
+
spawn(path, process.argv.slice(2), {
|
|
141
|
+
stdio: "inherit",
|
|
142
|
+
shell: true,
|
|
143
|
+
});
|
|
144
|
+
}
|
|
130
145
|
};
|
|
131
146
|
|
|
132
147
|
main().catch(console.error);
|