@magentrix-corp/magentrix-cli 1.3.16 ā 1.3.17
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/LICENSE +25 -25
- package/README.md +1166 -1166
- package/actions/autopublish.old.js +293 -293
- package/actions/config.js +182 -182
- package/actions/create.js +466 -466
- package/actions/help.js +164 -164
- package/actions/iris/buildStage.js +874 -874
- package/actions/iris/delete.js +256 -256
- package/actions/iris/dev.js +391 -391
- package/actions/iris/index.js +6 -6
- package/actions/iris/link.js +375 -375
- package/actions/iris/recover.js +268 -268
- package/actions/main.js +80 -80
- package/actions/publish.js +1420 -1420
- package/actions/pull.js +684 -684
- package/actions/setup.js +148 -148
- package/actions/status.js +17 -17
- package/actions/update.js +248 -248
- package/bin/magentrix.js +393 -393
- package/package.json +55 -55
- package/utils/assetPaths.js +158 -158
- package/utils/autopublishLock.js +77 -77
- package/utils/cacher.js +206 -206
- package/utils/cli/checkInstanceUrl.js +76 -74
- package/utils/cli/helpers/compare.js +282 -282
- package/utils/cli/helpers/ensureApiKey.js +63 -63
- package/utils/cli/helpers/ensureCredentials.js +68 -68
- package/utils/cli/helpers/ensureInstanceUrl.js +75 -75
- package/utils/cli/writeRecords.js +262 -262
- package/utils/compare.js +135 -135
- package/utils/compress.js +17 -17
- package/utils/config.js +527 -527
- package/utils/debug.js +144 -144
- package/utils/diagnostics/testPublishLogic.js +96 -96
- package/utils/diff.js +49 -49
- package/utils/downloadAssets.js +291 -291
- package/utils/filetag.js +115 -115
- package/utils/hash.js +14 -14
- package/utils/iris/backup.js +411 -411
- package/utils/iris/builder.js +541 -541
- package/utils/iris/config-reader.js +664 -664
- package/utils/iris/deleteHelper.js +150 -150
- package/utils/iris/errors.js +537 -537
- package/utils/iris/linker.js +601 -601
- package/utils/iris/lock.js +360 -360
- package/utils/iris/validation.js +360 -360
- package/utils/iris/validator.js +281 -281
- package/utils/iris/zipper.js +248 -248
- package/utils/logger.js +291 -291
- package/utils/magentrix/api/assets.js +220 -220
- package/utils/magentrix/api/auth.js +107 -107
- package/utils/magentrix/api/createEntity.js +61 -61
- package/utils/magentrix/api/deleteEntity.js +55 -55
- package/utils/magentrix/api/iris.js +251 -251
- package/utils/magentrix/api/meqlQuery.js +36 -36
- package/utils/magentrix/api/retrieveEntity.js +86 -86
- package/utils/magentrix/api/updateEntity.js +66 -66
- package/utils/magentrix/fetch.js +168 -168
- package/utils/merge.js +22 -22
- package/utils/permissionError.js +70 -70
- package/utils/preferences.js +40 -40
- package/utils/progress.js +469 -469
- package/utils/spinner.js +43 -43
- package/utils/template.js +52 -52
- package/utils/updateFileBase.js +121 -121
- package/utils/workspaces.js +108 -108
- package/vars/config.js +11 -11
- package/vars/global.js +50 -50
package/actions/update.js
CHANGED
|
@@ -1,248 +1,248 @@
|
|
|
1
|
-
import { execSync } from 'child_process';
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
import { fileURLToPath } from 'url';
|
|
5
|
-
import chalk from 'chalk';
|
|
6
|
-
import { withSpinner } from '../utils/spinner.js';
|
|
7
|
-
|
|
8
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
9
|
-
const __dirname = path.dirname(__filename);
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Detects how the CLI was installed (global npm, local npm, or development).
|
|
13
|
-
* @returns {Object} { method: 'global'|'local'|'dev', packagePath: string }
|
|
14
|
-
*/
|
|
15
|
-
const detectInstallationMethod = () => {
|
|
16
|
-
try {
|
|
17
|
-
// Get the real path of the binary (resolves symlinks)
|
|
18
|
-
const binaryPath = path.resolve(__dirname, '../bin/magentrix.js');
|
|
19
|
-
const realBinaryPath = fs.realpathSync(binaryPath);
|
|
20
|
-
|
|
21
|
-
// Check if running from node_modules
|
|
22
|
-
const isInNodeModules = realBinaryPath.includes('node_modules');
|
|
23
|
-
|
|
24
|
-
if (!isInNodeModules) {
|
|
25
|
-
// Running from source (development)
|
|
26
|
-
return { method: 'dev', packagePath: path.resolve(__dirname, '..') };
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// Check if it's a global installation by looking at the path structure
|
|
30
|
-
// Global npm packages on Unix: /usr/local/lib/node_modules or ~/.npm-global/lib/node_modules
|
|
31
|
-
// Global npm packages on Windows: %APPDATA%\npm\node_modules
|
|
32
|
-
const isGlobal = realBinaryPath.includes('/lib/node_modules/') ||
|
|
33
|
-
realBinaryPath.includes('\\npm\\node_modules\\') ||
|
|
34
|
-
realBinaryPath.includes('/.npm-global/') ||
|
|
35
|
-
realBinaryPath.includes('\\.npm-global\\');
|
|
36
|
-
|
|
37
|
-
if (isGlobal) {
|
|
38
|
-
return { method: 'global', packagePath: null };
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// Local installation - find the nearest package.json in node_modules
|
|
42
|
-
let currentPath = realBinaryPath;
|
|
43
|
-
while (currentPath !== path.dirname(currentPath)) {
|
|
44
|
-
if (path.basename(currentPath) === 'node_modules') {
|
|
45
|
-
return { method: 'local', packagePath: path.dirname(currentPath) };
|
|
46
|
-
}
|
|
47
|
-
currentPath = path.dirname(currentPath);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return { method: 'local', packagePath: process.cwd() };
|
|
51
|
-
} catch (error) {
|
|
52
|
-
console.warn(chalk.yellow(`Warning: Could not detect installation method: ${error.message}`));
|
|
53
|
-
return { method: 'unknown', packagePath: null };
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Gets the current installed version from package.json.
|
|
59
|
-
* @returns {string} Version string
|
|
60
|
-
*/
|
|
61
|
-
const getCurrentVersion = () => {
|
|
62
|
-
try {
|
|
63
|
-
const packageJsonPath = path.resolve(__dirname, '../package.json');
|
|
64
|
-
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
|
|
65
|
-
return packageJson.version;
|
|
66
|
-
} catch (error) {
|
|
67
|
-
return 'unknown';
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Gets the latest available version from npm registry.
|
|
73
|
-
* @param {string} packageName - NPM package name
|
|
74
|
-
* @returns {Promise<string>} Latest version string
|
|
75
|
-
*/
|
|
76
|
-
const getLatestVersion = async (packageName) => {
|
|
77
|
-
try {
|
|
78
|
-
const result = execSync(`npm view ${packageName} version`, { encoding: 'utf-8' });
|
|
79
|
-
return result.trim();
|
|
80
|
-
} catch (error) {
|
|
81
|
-
throw new Error(`Failed to check latest version: ${error.message}`);
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Attempts to update the package based on installation method.
|
|
87
|
-
* @param {string} method - Installation method ('global', 'local', or 'dev')
|
|
88
|
-
* @param {string} packagePath - Path to package directory (for local installs)
|
|
89
|
-
* @returns {Promise<Object>} { success: boolean, message: string }
|
|
90
|
-
*/
|
|
91
|
-
const performUpdate = async (method, packagePath) => {
|
|
92
|
-
const packageName = '@magentrix-corp/magentrix-cli';
|
|
93
|
-
|
|
94
|
-
try {
|
|
95
|
-
let command;
|
|
96
|
-
let cwd = process.cwd();
|
|
97
|
-
|
|
98
|
-
switch (method) {
|
|
99
|
-
case 'global':
|
|
100
|
-
command = `npm install -g ${packageName}@latest`;
|
|
101
|
-
break;
|
|
102
|
-
|
|
103
|
-
case 'local':
|
|
104
|
-
command = `npm install ${packageName}@latest`;
|
|
105
|
-
cwd = packagePath || process.cwd();
|
|
106
|
-
break;
|
|
107
|
-
|
|
108
|
-
case 'dev':
|
|
109
|
-
return {
|
|
110
|
-
success: false,
|
|
111
|
-
isDev: true,
|
|
112
|
-
message: 'Cannot auto-update: Running from source code (development mode)'
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
default:
|
|
116
|
-
return {
|
|
117
|
-
success: false,
|
|
118
|
-
message: 'Cannot auto-update: Unable to detect installation method'
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// Execute the update command
|
|
123
|
-
execSync(command, {
|
|
124
|
-
cwd,
|
|
125
|
-
stdio: 'inherit', // Show npm output to user
|
|
126
|
-
encoding: 'utf-8'
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
return { success: true, message: 'Update completed successfully!' };
|
|
130
|
-
} catch (error) {
|
|
131
|
-
// Parse the error to provide helpful messages
|
|
132
|
-
const errorMessage = error.message || String(error);
|
|
133
|
-
|
|
134
|
-
// Check for common error patterns
|
|
135
|
-
if (errorMessage.includes('EACCES') || errorMessage.includes('permission denied')) {
|
|
136
|
-
return {
|
|
137
|
-
success: false,
|
|
138
|
-
needsSudo: true,
|
|
139
|
-
message: 'Update failed: Permission denied'
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
if (errorMessage.includes('ENOTFOUND') || errorMessage.includes('network')) {
|
|
144
|
-
return {
|
|
145
|
-
success: false,
|
|
146
|
-
message: 'Update failed: Network error (check your internet connection)'
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
return {
|
|
151
|
-
success: false,
|
|
152
|
-
message: `Update failed: ${errorMessage}`
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Main update command handler.
|
|
159
|
-
*/
|
|
160
|
-
export const update = async () => {
|
|
161
|
-
console.log(chalk.bold.cyan('\nš MagentrixCLI Updater\n'));
|
|
162
|
-
|
|
163
|
-
// Step 1: Detect installation method
|
|
164
|
-
const { method, packagePath } = detectInstallationMethod();
|
|
165
|
-
const currentVersion = getCurrentVersion();
|
|
166
|
-
|
|
167
|
-
console.log(chalk.gray('Current version:'), chalk.white(currentVersion));
|
|
168
|
-
console.log(chalk.gray('Installation method:'), chalk.white(method));
|
|
169
|
-
|
|
170
|
-
if (method === 'dev') {
|
|
171
|
-
console.log();
|
|
172
|
-
console.log(chalk.yellow('ā ļø Development Mode Detected'));
|
|
173
|
-
console.log(chalk.gray('You are running from source code.'));
|
|
174
|
-
console.log(chalk.gray('To update, use:'), chalk.cyan('git pull'));
|
|
175
|
-
return;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
// Step 2: Check for latest version
|
|
179
|
-
console.log();
|
|
180
|
-
const latestVersion = await withSpinner('Checking for updates...', async () => {
|
|
181
|
-
return await getLatestVersion('@magentrix-corp/magentrix-cli');
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
console.log(chalk.gray('Latest version:'), chalk.white(latestVersion));
|
|
185
|
-
|
|
186
|
-
// Step 3: Compare versions
|
|
187
|
-
if (currentVersion === latestVersion) {
|
|
188
|
-
console.log();
|
|
189
|
-
console.log(chalk.green('ā You are already on the latest version!'));
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
console.log();
|
|
194
|
-
console.log(chalk.yellow(`š¦ Update available: ${currentVersion} ā ${latestVersion}`));
|
|
195
|
-
console.log();
|
|
196
|
-
|
|
197
|
-
// Step 4: Attempt update
|
|
198
|
-
console.log(chalk.blue('Starting update...\n'));
|
|
199
|
-
|
|
200
|
-
const result = await performUpdate(method, packagePath);
|
|
201
|
-
|
|
202
|
-
console.log();
|
|
203
|
-
|
|
204
|
-
if (result.success) {
|
|
205
|
-
console.log(chalk.green('ā
' + result.message));
|
|
206
|
-
console.log(chalk.gray('\nRun'), chalk.cyan('magentrix --version'), chalk.gray('to verify the update.'));
|
|
207
|
-
} else {
|
|
208
|
-
console.log(chalk.bgRed.bold.white(' ā Update Failed '));
|
|
209
|
-
console.log(chalk.redBright('ā'.repeat(60)));
|
|
210
|
-
console.log(chalk.red(result.message));
|
|
211
|
-
console.log();
|
|
212
|
-
|
|
213
|
-
// Show helpful troubleshooting tips
|
|
214
|
-
console.log(chalk.yellow('Common solutions:'));
|
|
215
|
-
console.log();
|
|
216
|
-
|
|
217
|
-
if (result.needsSudo || result.message.includes('Permission')) {
|
|
218
|
-
console.log(chalk.white('1. ') + chalk.gray('Try running with elevated permissions:'));
|
|
219
|
-
if (method === 'global') {
|
|
220
|
-
console.log(chalk.cyan(' sudo npm install -g @magentrix-corp/magentrix-cli@latest'));
|
|
221
|
-
} else {
|
|
222
|
-
console.log(chalk.cyan(' sudo npm install @magentrix-corp/magentrix-cli@latest'));
|
|
223
|
-
}
|
|
224
|
-
console.log();
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
console.log(chalk.white('2. ') + chalk.gray('Manually update using npm:'));
|
|
228
|
-
if (method === 'global') {
|
|
229
|
-
console.log(chalk.cyan(' npm install -g @magentrix-corp/magentrix-cli@latest'));
|
|
230
|
-
} else {
|
|
231
|
-
console.log(chalk.cyan(' npm install @magentrix-corp/magentrix-cli@latest'));
|
|
232
|
-
}
|
|
233
|
-
console.log();
|
|
234
|
-
|
|
235
|
-
console.log(chalk.white('3. ') + chalk.gray('Check npm configuration:'));
|
|
236
|
-
console.log(chalk.cyan(' npm config list'));
|
|
237
|
-
console.log();
|
|
238
|
-
|
|
239
|
-
console.log(chalk.white('4. ') + chalk.gray('Verify you have write access to npm directories'));
|
|
240
|
-
console.log();
|
|
241
|
-
|
|
242
|
-
console.log(chalk.white('5. ') + chalk.gray('If using a proxy, ensure npm is configured correctly:'));
|
|
243
|
-
console.log(chalk.cyan(' npm config set proxy http://your-proxy:port'));
|
|
244
|
-
console.log();
|
|
245
|
-
|
|
246
|
-
console.log(chalk.redBright('ā'.repeat(60)));
|
|
247
|
-
}
|
|
248
|
-
};
|
|
1
|
+
import { execSync } from 'child_process';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { fileURLToPath } from 'url';
|
|
5
|
+
import chalk from 'chalk';
|
|
6
|
+
import { withSpinner } from '../utils/spinner.js';
|
|
7
|
+
|
|
8
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
9
|
+
const __dirname = path.dirname(__filename);
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Detects how the CLI was installed (global npm, local npm, or development).
|
|
13
|
+
* @returns {Object} { method: 'global'|'local'|'dev', packagePath: string }
|
|
14
|
+
*/
|
|
15
|
+
const detectInstallationMethod = () => {
|
|
16
|
+
try {
|
|
17
|
+
// Get the real path of the binary (resolves symlinks)
|
|
18
|
+
const binaryPath = path.resolve(__dirname, '../bin/magentrix.js');
|
|
19
|
+
const realBinaryPath = fs.realpathSync(binaryPath);
|
|
20
|
+
|
|
21
|
+
// Check if running from node_modules
|
|
22
|
+
const isInNodeModules = realBinaryPath.includes('node_modules');
|
|
23
|
+
|
|
24
|
+
if (!isInNodeModules) {
|
|
25
|
+
// Running from source (development)
|
|
26
|
+
return { method: 'dev', packagePath: path.resolve(__dirname, '..') };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Check if it's a global installation by looking at the path structure
|
|
30
|
+
// Global npm packages on Unix: /usr/local/lib/node_modules or ~/.npm-global/lib/node_modules
|
|
31
|
+
// Global npm packages on Windows: %APPDATA%\npm\node_modules
|
|
32
|
+
const isGlobal = realBinaryPath.includes('/lib/node_modules/') ||
|
|
33
|
+
realBinaryPath.includes('\\npm\\node_modules\\') ||
|
|
34
|
+
realBinaryPath.includes('/.npm-global/') ||
|
|
35
|
+
realBinaryPath.includes('\\.npm-global\\');
|
|
36
|
+
|
|
37
|
+
if (isGlobal) {
|
|
38
|
+
return { method: 'global', packagePath: null };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Local installation - find the nearest package.json in node_modules
|
|
42
|
+
let currentPath = realBinaryPath;
|
|
43
|
+
while (currentPath !== path.dirname(currentPath)) {
|
|
44
|
+
if (path.basename(currentPath) === 'node_modules') {
|
|
45
|
+
return { method: 'local', packagePath: path.dirname(currentPath) };
|
|
46
|
+
}
|
|
47
|
+
currentPath = path.dirname(currentPath);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return { method: 'local', packagePath: process.cwd() };
|
|
51
|
+
} catch (error) {
|
|
52
|
+
console.warn(chalk.yellow(`Warning: Could not detect installation method: ${error.message}`));
|
|
53
|
+
return { method: 'unknown', packagePath: null };
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Gets the current installed version from package.json.
|
|
59
|
+
* @returns {string} Version string
|
|
60
|
+
*/
|
|
61
|
+
const getCurrentVersion = () => {
|
|
62
|
+
try {
|
|
63
|
+
const packageJsonPath = path.resolve(__dirname, '../package.json');
|
|
64
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
|
|
65
|
+
return packageJson.version;
|
|
66
|
+
} catch (error) {
|
|
67
|
+
return 'unknown';
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Gets the latest available version from npm registry.
|
|
73
|
+
* @param {string} packageName - NPM package name
|
|
74
|
+
* @returns {Promise<string>} Latest version string
|
|
75
|
+
*/
|
|
76
|
+
const getLatestVersion = async (packageName) => {
|
|
77
|
+
try {
|
|
78
|
+
const result = execSync(`npm view ${packageName} version`, { encoding: 'utf-8' });
|
|
79
|
+
return result.trim();
|
|
80
|
+
} catch (error) {
|
|
81
|
+
throw new Error(`Failed to check latest version: ${error.message}`);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Attempts to update the package based on installation method.
|
|
87
|
+
* @param {string} method - Installation method ('global', 'local', or 'dev')
|
|
88
|
+
* @param {string} packagePath - Path to package directory (for local installs)
|
|
89
|
+
* @returns {Promise<Object>} { success: boolean, message: string }
|
|
90
|
+
*/
|
|
91
|
+
const performUpdate = async (method, packagePath) => {
|
|
92
|
+
const packageName = '@magentrix-corp/magentrix-cli';
|
|
93
|
+
|
|
94
|
+
try {
|
|
95
|
+
let command;
|
|
96
|
+
let cwd = process.cwd();
|
|
97
|
+
|
|
98
|
+
switch (method) {
|
|
99
|
+
case 'global':
|
|
100
|
+
command = `npm install -g ${packageName}@latest`;
|
|
101
|
+
break;
|
|
102
|
+
|
|
103
|
+
case 'local':
|
|
104
|
+
command = `npm install ${packageName}@latest`;
|
|
105
|
+
cwd = packagePath || process.cwd();
|
|
106
|
+
break;
|
|
107
|
+
|
|
108
|
+
case 'dev':
|
|
109
|
+
return {
|
|
110
|
+
success: false,
|
|
111
|
+
isDev: true,
|
|
112
|
+
message: 'Cannot auto-update: Running from source code (development mode)'
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
default:
|
|
116
|
+
return {
|
|
117
|
+
success: false,
|
|
118
|
+
message: 'Cannot auto-update: Unable to detect installation method'
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Execute the update command
|
|
123
|
+
execSync(command, {
|
|
124
|
+
cwd,
|
|
125
|
+
stdio: 'inherit', // Show npm output to user
|
|
126
|
+
encoding: 'utf-8'
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
return { success: true, message: 'Update completed successfully!' };
|
|
130
|
+
} catch (error) {
|
|
131
|
+
// Parse the error to provide helpful messages
|
|
132
|
+
const errorMessage = error.message || String(error);
|
|
133
|
+
|
|
134
|
+
// Check for common error patterns
|
|
135
|
+
if (errorMessage.includes('EACCES') || errorMessage.includes('permission denied')) {
|
|
136
|
+
return {
|
|
137
|
+
success: false,
|
|
138
|
+
needsSudo: true,
|
|
139
|
+
message: 'Update failed: Permission denied'
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (errorMessage.includes('ENOTFOUND') || errorMessage.includes('network')) {
|
|
144
|
+
return {
|
|
145
|
+
success: false,
|
|
146
|
+
message: 'Update failed: Network error (check your internet connection)'
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return {
|
|
151
|
+
success: false,
|
|
152
|
+
message: `Update failed: ${errorMessage}`
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Main update command handler.
|
|
159
|
+
*/
|
|
160
|
+
export const update = async () => {
|
|
161
|
+
console.log(chalk.bold.cyan('\nš MagentrixCLI Updater\n'));
|
|
162
|
+
|
|
163
|
+
// Step 1: Detect installation method
|
|
164
|
+
const { method, packagePath } = detectInstallationMethod();
|
|
165
|
+
const currentVersion = getCurrentVersion();
|
|
166
|
+
|
|
167
|
+
console.log(chalk.gray('Current version:'), chalk.white(currentVersion));
|
|
168
|
+
console.log(chalk.gray('Installation method:'), chalk.white(method));
|
|
169
|
+
|
|
170
|
+
if (method === 'dev') {
|
|
171
|
+
console.log();
|
|
172
|
+
console.log(chalk.yellow('ā ļø Development Mode Detected'));
|
|
173
|
+
console.log(chalk.gray('You are running from source code.'));
|
|
174
|
+
console.log(chalk.gray('To update, use:'), chalk.cyan('git pull'));
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// Step 2: Check for latest version
|
|
179
|
+
console.log();
|
|
180
|
+
const latestVersion = await withSpinner('Checking for updates...', async () => {
|
|
181
|
+
return await getLatestVersion('@magentrix-corp/magentrix-cli');
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
console.log(chalk.gray('Latest version:'), chalk.white(latestVersion));
|
|
185
|
+
|
|
186
|
+
// Step 3: Compare versions
|
|
187
|
+
if (currentVersion === latestVersion) {
|
|
188
|
+
console.log();
|
|
189
|
+
console.log(chalk.green('ā You are already on the latest version!'));
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
console.log();
|
|
194
|
+
console.log(chalk.yellow(`š¦ Update available: ${currentVersion} ā ${latestVersion}`));
|
|
195
|
+
console.log();
|
|
196
|
+
|
|
197
|
+
// Step 4: Attempt update
|
|
198
|
+
console.log(chalk.blue('Starting update...\n'));
|
|
199
|
+
|
|
200
|
+
const result = await performUpdate(method, packagePath);
|
|
201
|
+
|
|
202
|
+
console.log();
|
|
203
|
+
|
|
204
|
+
if (result.success) {
|
|
205
|
+
console.log(chalk.green('ā
' + result.message));
|
|
206
|
+
console.log(chalk.gray('\nRun'), chalk.cyan('magentrix --version'), chalk.gray('to verify the update.'));
|
|
207
|
+
} else {
|
|
208
|
+
console.log(chalk.bgRed.bold.white(' ā Update Failed '));
|
|
209
|
+
console.log(chalk.redBright('ā'.repeat(60)));
|
|
210
|
+
console.log(chalk.red(result.message));
|
|
211
|
+
console.log();
|
|
212
|
+
|
|
213
|
+
// Show helpful troubleshooting tips
|
|
214
|
+
console.log(chalk.yellow('Common solutions:'));
|
|
215
|
+
console.log();
|
|
216
|
+
|
|
217
|
+
if (result.needsSudo || result.message.includes('Permission')) {
|
|
218
|
+
console.log(chalk.white('1. ') + chalk.gray('Try running with elevated permissions:'));
|
|
219
|
+
if (method === 'global') {
|
|
220
|
+
console.log(chalk.cyan(' sudo npm install -g @magentrix-corp/magentrix-cli@latest'));
|
|
221
|
+
} else {
|
|
222
|
+
console.log(chalk.cyan(' sudo npm install @magentrix-corp/magentrix-cli@latest'));
|
|
223
|
+
}
|
|
224
|
+
console.log();
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
console.log(chalk.white('2. ') + chalk.gray('Manually update using npm:'));
|
|
228
|
+
if (method === 'global') {
|
|
229
|
+
console.log(chalk.cyan(' npm install -g @magentrix-corp/magentrix-cli@latest'));
|
|
230
|
+
} else {
|
|
231
|
+
console.log(chalk.cyan(' npm install @magentrix-corp/magentrix-cli@latest'));
|
|
232
|
+
}
|
|
233
|
+
console.log();
|
|
234
|
+
|
|
235
|
+
console.log(chalk.white('3. ') + chalk.gray('Check npm configuration:'));
|
|
236
|
+
console.log(chalk.cyan(' npm config list'));
|
|
237
|
+
console.log();
|
|
238
|
+
|
|
239
|
+
console.log(chalk.white('4. ') + chalk.gray('Verify you have write access to npm directories'));
|
|
240
|
+
console.log();
|
|
241
|
+
|
|
242
|
+
console.log(chalk.white('5. ') + chalk.gray('If using a proxy, ensure npm is configured correctly:'));
|
|
243
|
+
console.log(chalk.cyan(' npm config set proxy http://your-proxy:port'));
|
|
244
|
+
console.log();
|
|
245
|
+
|
|
246
|
+
console.log(chalk.redBright('ā'.repeat(60)));
|
|
247
|
+
}
|
|
248
|
+
};
|