@@ -14,16 +14,21 @@ const { version } = require("../../package.json");
14
14
*/
15
15
const isInstalledViaNpm = () => {
16
16
try {
17
- // Check if we're in a global npm installation
18
- const execPath = process.argv[0];
19
17
const scriptPath = process.argv[1];
20
18
21
19
// Common indicators of npm global installation
22
20
if (scriptPath.includes('node_modules') && scriptPath.includes('appwrite-cli')) {
23
21
return true;
24
22
}
25
23
26
- // Check if npm is available and appwrite-cli is installed globally
24
+ // Check for npm global paths
25
+ if (scriptPath.includes('/usr/local/lib/node_modules/') ||
26
+ scriptPath.includes('/opt/homebrew/lib/node_modules/') ||
27
+ scriptPath.includes('/.npm-global/') ||
28
+ scriptPath.includes('/node_modules/.bin/')) {
29
+ return true;
30
+ }
31
+
27
32
return false;
28
33
} catch (e) {
29
34
return false;
@@ -110,8 +115,14 @@ const updateViaNpm = async () => {
110
115
success("Updated to latest version via npm!");
111
116
hint("Run '{{ language .params .executableName | caseLower }} --version' to verify the new version.");
112
117
} catch (e) {
113
- error(`Failed to update via npm: ${e.message}`);
114
- hint("Try running: npm install -g {{ language .params .npmPackage | caseDash }}@latest");
118
+ // Check if error is due to file already existing (likely already latest version)
119
+ if (e.message.includes('EEXIST') || e.message.includes('file already exists')) {
120
+ success("Latest version is already installed via npm!");
121
+ hint("The CLI is up to date. Run '{{ language .params .executableName | caseLower }} --version' to verify.");
122
+ } else {
123
+ error(`Failed to update via npm: ${e.message}`);
124
+ hint("Try running: npm install -g {{ language .params .npmPackage | caseDash }}@latest --force");
125
+ }
115
126
}
116
127
};
117
128
@@ -124,8 +135,14 @@ const updateViaHomebrew = async () => {
124
135
success("Updated to latest version via Homebrew!");
125
136
hint("Run '{{ language .params .executableName | caseLower }} --version' to verify the new version.");
126
137
} catch (e) {
127
- error(`Failed to update via Homebrew: ${e.message}`);
128
- hint("Try running: brew upgrade {{ language .params .executableName | caseLower }}");
138
+ // Check if error is due to package already being up-to-date
139
+ if (e.message.includes('already installed') || e.message.includes('up-to-date')) {
140
+ success("Latest version is already installed via Homebrew!");
141
+ hint("The CLI is up to date. Run '{{ language .params .executableName | caseLower }} --version' to verify.");
142
+ } else {
143
+ error(`Failed to update via Homebrew: ${e.message}`);
144
+ hint("Try running: brew upgrade {{ language .params .executableName | caseLower }}");
145
+ }
129
146
}
130
147
};
131
148
@@ -146,11 +163,17 @@ const updateViaScript = async () => {
146
163
success("Updated to latest version via installation script!");
147
164
hint("Run '{{ language .params .executableName | caseLower }} --version' to verify the new version.");
148
165
} catch (e) {
149
- error(`Failed to update via installation script: ${e.message}`);
150
- if (platform === 'win32') {
151
- hint("Try running: iwr -useb https://appwrite.io/cli/install.ps1 | iex");
166
+ // Check if error indicates already up-to-date
167
+ if (e.message.includes('already exists') || e.message.includes('up-to-date')) {
168
+ success("Latest version is already installed!");
169
+ hint("The CLI is up to date. Run '{{ language .params .executableName | caseLower }} --version' to verify.");
152
170
} else {
153
- hint("Try running: wget -q https://appwrite.io/cli/install.sh -O - | /bin/bash");
171
+ error(`Failed to update via installation script: ${e.message}`);
172
+ if (platform === 'win32') {
173
+ hint("Try running: iwr -useb https://appwrite.io/cli/install.ps1 | iex");
174
+ } else {
175
+ hint("Try running: wget -q https://appwrite.io/cli/install.sh -O - | /bin/bash");
176
+ }
154
177
}
155
178
}
156
179
};
@@ -209,56 +232,22 @@ const updateCli = async ({ manual } = {}) => {
209
232
return;
210
233
}
211
234
212
- // Auto-detect installation method and suggest appropriate update
235
+ // Auto-detect installation method and update automatically
213
236
if (isInstalledViaNpm()) {
214
- const answer = await inquirer.prompt([{
215
- type: 'confirm',
216
- name: 'update',
217
- message: 'Update via npm?',
218
- default: true
219
- }]);
220
-
221
- if (answer.update) {
222
- await updateViaNpm();
223
- }
237
+ await updateViaNpm();
224
238
} else if (isInstalledViaHomebrew()) {
225
- const answer = await inquirer.prompt([{
226
- type: 'confirm',
227
- name: 'update',
228
- message: 'Update via Homebrew?',
229
- default: true
230
- }]);
231
-
232
- if (answer.update) {
233
- await updateViaHomebrew();
234
- }
239
+ await updateViaHomebrew();
235
240
} else {
236
- // Unknown installation method - show options
237
- const answer = await inquirer.prompt([{
238
- type: 'list',
239
- name: 'method',
240
- message: 'How would you like to update?',
241
- choices: [
242
- { name: 'NPM (npm install -g)', value: 'npm' },
243
- { name: 'Homebrew (macOS)', value: 'homebrew' },
244
- { name: 'Installation Script', value: 'script' },
245
- { name: 'Show manual instructions', value: 'manual' }
246
- ]
247
- }]);
248
-
249
- switch (answer.method) {
250
- case 'npm':
251
- await updateViaNpm();
252
- break;
253
- case 'homebrew':
254
- await updateViaHomebrew();
255
- break;
256
- case 'script':
257
- await updateViaScript();
258
- break;
259
- case 'manual':
241
+ // Unknown installation method - try npm first, then show manual instructions
242
+ try {
243
+ await updateViaNpm();
244
+ } catch (e) {
245
+ // If npm failed and it's not because the version is already installed
246
+ if (!e.message.includes('EEXIST') && !e.message.includes('file already exists')) {
247
+ error("Could not detect installation method or update failed.");
260
248
showManualInstructions(latestVersion);
261
- break;
249
+ }
250
+ // If it's EEXIST error, updateViaNpm already handled it with success message
262
251
}
263
252
}
264
253
0 commit comments