@aptos-labs/aptos-cli 0.1.7 → 0.1.9
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 +53 -25
- package/package.json +1 -1
package/bin/aptos
CHANGED
|
@@ -72,6 +72,15 @@ const getLatestVersionBrew = () => {
|
|
|
72
72
|
return out[0].versions.stable;
|
|
73
73
|
};
|
|
74
74
|
|
|
75
|
+
// Determine the latest version of the CLI.
|
|
76
|
+
const getLatestVersion = async () => {
|
|
77
|
+
if (os === "MacOS") {
|
|
78
|
+
return getLatestVersionBrew();
|
|
79
|
+
} else {
|
|
80
|
+
return getLatestVersionGh();
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
75
84
|
// Based on the installation path of the aptos formula, determine the path where the
|
|
76
85
|
// CLI should be installed.
|
|
77
86
|
const getCliPathBrew = () => {
|
|
@@ -81,6 +90,29 @@ const getCliPathBrew = () => {
|
|
|
81
90
|
return `${directory}/bin/aptos`;
|
|
82
91
|
};
|
|
83
92
|
|
|
93
|
+
// Install or update the CLI.
|
|
94
|
+
const installCli = (os, path, latestVersion) => {
|
|
95
|
+
const url = `https://github.com/aptos-labs/aptos-core/releases/download/${PNAME}-v${latestVersion}/${PNAME}-${latestVersion}-${os}-x86_64.zip`;
|
|
96
|
+
|
|
97
|
+
console.log(`Downloading aptos CLI version ${latestVersion}`);
|
|
98
|
+
if (os === "Windows") {
|
|
99
|
+
// Download the zip file, extract it, and move the binary to the correct location.
|
|
100
|
+
execSync(
|
|
101
|
+
`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}"`
|
|
102
|
+
);
|
|
103
|
+
} else if (os === "MacOS") {
|
|
104
|
+
// Install the CLI with brew.
|
|
105
|
+
execSyncShell("brew install aptos");
|
|
106
|
+
// Get the path of the CLI.
|
|
107
|
+
path = getCliPathBrew();
|
|
108
|
+
} else {
|
|
109
|
+
// Download the zip file, extract it, and move the binary to the correct location.
|
|
110
|
+
execSync(
|
|
111
|
+
`curl -L -o /tmp/aptos.zip ${url}; unzip -o -q /tmp/aptos.zip -d /tmp; mv /tmp/aptos ${path};`
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
|
|
84
116
|
const main = async () => {
|
|
85
117
|
const os = getOS();
|
|
86
118
|
|
|
@@ -102,34 +134,30 @@ const main = async () => {
|
|
|
102
134
|
path = `${__dirname}/${PNAME}`;
|
|
103
135
|
}
|
|
104
136
|
|
|
137
|
+
// Look up the latest version.
|
|
138
|
+
const latestVersion = await getLatestVersion();
|
|
139
|
+
|
|
105
140
|
// If binary does not exist, download it.
|
|
106
141
|
if (!fs.existsSync(path)) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
console.log(
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
);
|
|
123
|
-
|
|
124
|
-
// Install the CLI with brew.
|
|
125
|
-
execSyncShell("brew install aptos");
|
|
126
|
-
// Get the path of the CLI.
|
|
127
|
-
path = getCliPathBrew();
|
|
142
|
+
console.log("CLI not installed");
|
|
143
|
+
// Install the latest version.
|
|
144
|
+
installCli(os, path, latestVersion);
|
|
145
|
+
} else {
|
|
146
|
+
// Get the current version of the CLI.
|
|
147
|
+
const currentVersion = execSyncShell(`${path} --version`, {
|
|
148
|
+
encoding: "utf8",
|
|
149
|
+
})
|
|
150
|
+
.trim()
|
|
151
|
+
.split(" ")[1];
|
|
152
|
+
console.log(
|
|
153
|
+
`Previously installed CLI version ${currentVersion}, checking for updates`
|
|
154
|
+
);
|
|
155
|
+
// Check if the installed version is the latest version.
|
|
156
|
+
if (currentVersion !== latestVersion) {
|
|
157
|
+
console.log(`A newer version of the CLI is available: ${latestVersion}`);
|
|
158
|
+
installCli(os, path, latestVersion);
|
|
128
159
|
} else {
|
|
129
|
-
|
|
130
|
-
execSync(
|
|
131
|
-
`curl -L -o /tmp/aptos.zip ${url}; unzip -o -q /tmp/aptos.zip -d /tmp; mv /tmp/aptos ${path};`
|
|
132
|
-
);
|
|
160
|
+
console.log(`CLI is up to date`);
|
|
133
161
|
}
|
|
134
162
|
}
|
|
135
163
|
|