atm-droid 1.0.6 → 1.0.7
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/package.json +1 -1
- package/src/menu.js +55 -1
package/package.json
CHANGED
package/src/menu.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
const chalk = require('chalk');
|
|
2
2
|
const inquirer = require('inquirer');
|
|
3
|
+
const fetch = require('node-fetch');
|
|
3
4
|
const { config, writeFactoryAuth, getFactoryAuthPath } = require('./config');
|
|
4
5
|
const api = require('./api');
|
|
5
6
|
const daemon = require('./daemon');
|
|
7
|
+
const pkg = require('../package.json');
|
|
8
|
+
|
|
9
|
+
let latestVersion = null;
|
|
10
|
+
let hasNewVersion = false;
|
|
6
11
|
|
|
7
12
|
// 格式化数字
|
|
8
13
|
function formatNumber(num) {
|
|
@@ -11,6 +16,20 @@ function formatNumber(num) {
|
|
|
11
16
|
return num.toString();
|
|
12
17
|
}
|
|
13
18
|
|
|
19
|
+
// 检查新版本
|
|
20
|
+
async function checkNewVersion() {
|
|
21
|
+
try {
|
|
22
|
+
const res = await fetch('https://registry.npmjs.org/atm-droid/latest', { timeout: 3000 });
|
|
23
|
+
if (res.ok) {
|
|
24
|
+
const data = await res.json();
|
|
25
|
+
latestVersion = data.version;
|
|
26
|
+
hasNewVersion = latestVersion !== pkg.version;
|
|
27
|
+
}
|
|
28
|
+
} catch (e) {
|
|
29
|
+
// 忽略网络错误
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
14
33
|
// 清屏
|
|
15
34
|
function clearScreen() {
|
|
16
35
|
console.clear();
|
|
@@ -19,8 +38,13 @@ function clearScreen() {
|
|
|
19
38
|
// 显示标题
|
|
20
39
|
function showHeader() {
|
|
21
40
|
console.log(chalk.cyan('╔════════════════════════════════════╗'));
|
|
22
|
-
|
|
41
|
+
const versionStr = ` ATM Token Manager v${pkg.version} `;
|
|
42
|
+
console.log(chalk.cyan('║') + chalk.white.bold(versionStr.padEnd(36).slice(0, 36)) + chalk.cyan('║'));
|
|
23
43
|
console.log(chalk.cyan('╚════════════════════════════════════╝'));
|
|
44
|
+
|
|
45
|
+
if (hasNewVersion && latestVersion) {
|
|
46
|
+
console.log(chalk.yellow(` ⚠ 发现新版本 v${latestVersion},运行 npm update -g atm-droid 更新`));
|
|
47
|
+
}
|
|
24
48
|
console.log();
|
|
25
49
|
}
|
|
26
50
|
|
|
@@ -96,6 +120,12 @@ async function mainMenu() {
|
|
|
96
120
|
}
|
|
97
121
|
|
|
98
122
|
choices.push(new inquirer.Separator());
|
|
123
|
+
|
|
124
|
+
// 有新版本时显示更新选项
|
|
125
|
+
if (hasNewVersion && latestVersion) {
|
|
126
|
+
choices.push({ name: chalk.yellow(`⬆️ 更新到 v${latestVersion}`), value: 'update' });
|
|
127
|
+
}
|
|
128
|
+
|
|
99
129
|
choices.push({ name: '❌ 退出程序', value: 'exit' });
|
|
100
130
|
|
|
101
131
|
const { action } = await inquirer.prompt([{
|
|
@@ -404,8 +434,29 @@ async function pause() {
|
|
|
404
434
|
}]);
|
|
405
435
|
}
|
|
406
436
|
|
|
437
|
+
// 自动更新
|
|
438
|
+
async function doUpdate() {
|
|
439
|
+
const { execSync } = require('child_process');
|
|
440
|
+
|
|
441
|
+
console.log(chalk.cyan(`\n 正在更新到 v${latestVersion}...\n`));
|
|
442
|
+
|
|
443
|
+
try {
|
|
444
|
+
execSync('npm update -g atm-droid', { stdio: 'inherit' });
|
|
445
|
+
console.log(chalk.green('\n ✓ 更新完成!请重新运行 atm 命令\n'));
|
|
446
|
+
await pause();
|
|
447
|
+
process.exit(0);
|
|
448
|
+
} catch (e) {
|
|
449
|
+
console.log(chalk.red(`\n ✗ 更新失败: ${e.message}`));
|
|
450
|
+
console.log(chalk.yellow(' 请手动运行: npm update -g atm-droid\n'));
|
|
451
|
+
await pause();
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
|
|
407
455
|
// 主循环
|
|
408
456
|
async function menu() {
|
|
457
|
+
// 启动时检查新版本(后台执行,不阻塞)
|
|
458
|
+
checkNewVersion();
|
|
459
|
+
|
|
409
460
|
while (true) {
|
|
410
461
|
const action = await mainMenu();
|
|
411
462
|
|
|
@@ -431,6 +482,9 @@ async function menu() {
|
|
|
431
482
|
case 'logout':
|
|
432
483
|
await doLogout();
|
|
433
484
|
break;
|
|
485
|
+
case 'update':
|
|
486
|
+
await doUpdate();
|
|
487
|
+
break;
|
|
434
488
|
case 'exit':
|
|
435
489
|
clearScreen();
|
|
436
490
|
console.log(chalk.cyan('\n 再见!\n'));
|