mpx-api 1.2.0 → 1.2.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.
- package/bin/mpx-api.js +73 -0
- package/package.json +1 -1
- package/src/schema.js +12 -0
- package/src/update.js +72 -0
package/bin/mpx-api.js
CHANGED
|
@@ -63,6 +63,79 @@ registerHistoryCommand(program);
|
|
|
63
63
|
registerLoadCommand(program);
|
|
64
64
|
registerDocsCommand(program);
|
|
65
65
|
|
|
66
|
+
// Update subcommand
|
|
67
|
+
program
|
|
68
|
+
.command('update')
|
|
69
|
+
.description('Check for updates and optionally install the latest version')
|
|
70
|
+
.option('--check', 'Only check for updates (do not install)')
|
|
71
|
+
.action(async (options, cmd) => {
|
|
72
|
+
const { checkForUpdate, performUpdate } = await import('../src/update.js');
|
|
73
|
+
const chalk = (await import('chalk')).default;
|
|
74
|
+
const jsonMode = cmd.parent?.opts()?.output === 'json';
|
|
75
|
+
|
|
76
|
+
try {
|
|
77
|
+
const info = checkForUpdate();
|
|
78
|
+
|
|
79
|
+
if (jsonMode) {
|
|
80
|
+
const output = {
|
|
81
|
+
current: info.current,
|
|
82
|
+
latest: info.latest,
|
|
83
|
+
updateAvailable: info.updateAvailable,
|
|
84
|
+
isGlobal: info.isGlobal
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
if (!options.check && info.updateAvailable) {
|
|
88
|
+
try {
|
|
89
|
+
const result = performUpdate(info.isGlobal);
|
|
90
|
+
output.updated = true;
|
|
91
|
+
output.newVersion = result.version;
|
|
92
|
+
} catch (err) {
|
|
93
|
+
output.updated = false;
|
|
94
|
+
output.error = err.message;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
console.log(JSON.stringify(output, null, 2));
|
|
99
|
+
process.exit(0);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Human-readable output
|
|
104
|
+
if (!info.updateAvailable) {
|
|
105
|
+
console.log('');
|
|
106
|
+
console.log(chalk.green.bold(`✓ mpx-api v${info.current} is up to date`));
|
|
107
|
+
console.log('');
|
|
108
|
+
process.exit(0);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
console.log('');
|
|
113
|
+
console.log(chalk.yellow.bold(`⬆ Update available: v${info.current} → v${info.latest}`));
|
|
114
|
+
|
|
115
|
+
if (options.check) {
|
|
116
|
+
console.log(chalk.gray(`Run ${chalk.cyan('mpx-api update')} to install`));
|
|
117
|
+
console.log('');
|
|
118
|
+
process.exit(0);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
console.log(chalk.gray(`Installing v${info.latest}${info.isGlobal ? ' (global)' : ''}...`));
|
|
123
|
+
|
|
124
|
+
const result = performUpdate(info.isGlobal);
|
|
125
|
+
console.log(chalk.green.bold(`✓ Updated to v${result.version}`));
|
|
126
|
+
console.log('');
|
|
127
|
+
process.exit(0);
|
|
128
|
+
} catch (err) {
|
|
129
|
+
if (jsonMode) {
|
|
130
|
+
console.log(JSON.stringify({ error: err.message, code: 'ERR_UPDATE' }, null, 2));
|
|
131
|
+
} else {
|
|
132
|
+
console.error(chalk.red.bold('\n❌ Update check failed:'), err.message);
|
|
133
|
+
console.error('');
|
|
134
|
+
}
|
|
135
|
+
process.exit(1);
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
|
|
66
139
|
// MCP subcommand
|
|
67
140
|
program
|
|
68
141
|
.command('mcp')
|
package/package.json
CHANGED
package/src/schema.js
CHANGED
|
@@ -253,6 +253,18 @@ export function getSchema() {
|
|
|
253
253
|
examples: [
|
|
254
254
|
{ command: 'mpx-api mcp', description: 'Start MCP stdio server' }
|
|
255
255
|
]
|
|
256
|
+
},
|
|
257
|
+
update: {
|
|
258
|
+
description: 'Check for updates and optionally install the latest version',
|
|
259
|
+
usage: 'mpx-api update [--check] [-o json]',
|
|
260
|
+
flags: {
|
|
261
|
+
'--check': { description: 'Only check for updates (do not install)', default: false }
|
|
262
|
+
},
|
|
263
|
+
examples: [
|
|
264
|
+
{ command: 'mpx-api update', description: 'Check and install updates' },
|
|
265
|
+
{ command: 'mpx-api update --check', description: 'Just check for updates' },
|
|
266
|
+
{ command: 'mpx-api update --check -o json', description: 'Check for updates (JSON output)' }
|
|
267
|
+
]
|
|
256
268
|
}
|
|
257
269
|
},
|
|
258
270
|
globalFlags: {
|
package/src/update.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Update Command
|
|
3
|
+
*
|
|
4
|
+
* Checks npm for the latest version of mpx-api and offers to update.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { execSync } from 'child_process';
|
|
8
|
+
import { readFileSync } from 'fs';
|
|
9
|
+
import { fileURLToPath } from 'url';
|
|
10
|
+
import { dirname, join } from 'path';
|
|
11
|
+
|
|
12
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
13
|
+
const __dirname = dirname(__filename);
|
|
14
|
+
const pkg = JSON.parse(readFileSync(join(__dirname, '../package.json'), 'utf8'));
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Check npm registry for latest version
|
|
18
|
+
* @returns {object} { current, latest, updateAvailable, isGlobal }
|
|
19
|
+
*/
|
|
20
|
+
export function checkForUpdate() {
|
|
21
|
+
const current = pkg.version;
|
|
22
|
+
|
|
23
|
+
let latest;
|
|
24
|
+
try {
|
|
25
|
+
latest = execSync('npm view mpx-api version', { encoding: 'utf8', timeout: 10000 }).trim();
|
|
26
|
+
} catch (err) {
|
|
27
|
+
throw new Error('Failed to check npm registry: ' + (err.message || 'unknown error'));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const updateAvailable = latest !== current && compareVersions(latest, current) > 0;
|
|
31
|
+
|
|
32
|
+
// Detect if installed globally
|
|
33
|
+
let isGlobal = false;
|
|
34
|
+
try {
|
|
35
|
+
const globalDir = execSync('npm root -g', { encoding: 'utf8', timeout: 5000 }).trim();
|
|
36
|
+
isGlobal = __dirname.startsWith(globalDir) || process.argv[1]?.includes('node_modules/.bin');
|
|
37
|
+
} catch {
|
|
38
|
+
// Can't determine, assume local
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return { current, latest, updateAvailable, isGlobal };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Perform the update
|
|
46
|
+
* @param {boolean} isGlobal - Install globally
|
|
47
|
+
* @returns {object} { success, version }
|
|
48
|
+
*/
|
|
49
|
+
export function performUpdate(isGlobal) {
|
|
50
|
+
const cmd = isGlobal ? 'npm install -g mpx-api@latest' : 'npm install mpx-api@latest';
|
|
51
|
+
try {
|
|
52
|
+
execSync(cmd, { encoding: 'utf8', timeout: 60000, stdio: 'pipe' });
|
|
53
|
+
// Verify
|
|
54
|
+
const newVersion = execSync('npm view mpx-api version', { encoding: 'utf8', timeout: 10000 }).trim();
|
|
55
|
+
return { success: true, version: newVersion };
|
|
56
|
+
} catch (err) {
|
|
57
|
+
throw new Error('Update failed: ' + (err.message || 'unknown error'));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Compare semver strings. Returns >0 if a > b, <0 if a < b, 0 if equal.
|
|
63
|
+
*/
|
|
64
|
+
export function compareVersions(a, b) {
|
|
65
|
+
const pa = a.split('.').map(Number);
|
|
66
|
+
const pb = b.split('.').map(Number);
|
|
67
|
+
for (let i = 0; i < 3; i++) {
|
|
68
|
+
if ((pa[i] || 0) > (pb[i] || 0)) return 1;
|
|
69
|
+
if ((pa[i] || 0) < (pb[i] || 0)) return -1;
|
|
70
|
+
}
|
|
71
|
+
return 0;
|
|
72
|
+
}
|