@itd2902/auggw 1.0.5 → 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/SETUP.md +17 -1
- package/package.json +1 -1
- package/src/commands/status.js +12 -3
- package/src/index.js +7 -2
- package/src/utils/update.js +24 -0
package/SETUP.md
CHANGED
|
@@ -7,7 +7,23 @@
|
|
|
7
7
|
## Cài đặt
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
|
-
npm install -g auggw
|
|
10
|
+
npm install -g @itd2902/auggw
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Chạy từ source (local dev)
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
cd cli
|
|
17
|
+
npm link
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Sau đó dùng `auggw` như bình thường. Mọi thay đổi trong source sẽ có hiệu lực ngay.
|
|
21
|
+
|
|
22
|
+
Gỡ link khi không cần:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
cd cli
|
|
26
|
+
npm unlink -g
|
|
11
27
|
```
|
|
12
28
|
|
|
13
29
|
## Đăng nhập
|
package/package.json
CHANGED
package/src/commands/status.js
CHANGED
|
@@ -13,17 +13,26 @@ async function statusCommand() {
|
|
|
13
13
|
} else {
|
|
14
14
|
console.log("📋 Current Account");
|
|
15
15
|
console.log(` Name: ${data.current.name}`);
|
|
16
|
-
console.log(` Tenant: ${data.current.tenantURL}`);
|
|
17
16
|
console.log(` Token: ...${data.current.accessToken}`);
|
|
18
17
|
console.log(
|
|
19
18
|
` Status: ${data.current.isLimited ? "🔴 Limited" : "🟢 Active"}`,
|
|
20
19
|
);
|
|
21
20
|
if (data.current.creditTotal) {
|
|
22
|
-
const
|
|
21
|
+
const remaining = data.current.creditRemaining || 0;
|
|
23
22
|
const total = data.current.creditTotal;
|
|
23
|
+
const used = total - remaining;
|
|
24
24
|
const pct = Math.round((used / total) * 100);
|
|
25
|
+
const barWidth = 30;
|
|
26
|
+
const filled = Math.round((pct / 100) * barWidth);
|
|
27
|
+
const empty = barWidth - filled;
|
|
28
|
+
const color = pct > 90 ? "\x1b[31m" : pct > 70 ? "\x1b[33m" : "\x1b[32m";
|
|
29
|
+
const reset = "\x1b[0m";
|
|
30
|
+
const bar = `${color}${"█".repeat(filled)}${"\x1b[90m"}${"░".repeat(empty)}${reset}`;
|
|
25
31
|
console.log(
|
|
26
|
-
` Credit: ${
|
|
32
|
+
` Credit: ${remaining.toLocaleString()} / ${total.toLocaleString()} remaining`,
|
|
33
|
+
);
|
|
34
|
+
console.log(
|
|
35
|
+
` ${bar} ${color}${pct}% used${reset}`,
|
|
27
36
|
);
|
|
28
37
|
}
|
|
29
38
|
console.log();
|
package/src/index.js
CHANGED
|
@@ -2,13 +2,15 @@ const { Command } = require('commander');
|
|
|
2
2
|
const loginCommand = require('./commands/login');
|
|
3
3
|
const switchCommand = require('./commands/switch');
|
|
4
4
|
const statusCommand = require('./commands/status');
|
|
5
|
+
const { checkUpdate } = require('./utils/update');
|
|
6
|
+
const pkg = require('../package.json');
|
|
5
7
|
|
|
6
8
|
const program = new Command();
|
|
7
9
|
|
|
8
10
|
program
|
|
9
|
-
.name('auggw')
|
|
11
|
+
.name(Object.keys(pkg.bin)[0] || 'auggw')
|
|
10
12
|
.description('CLI tool for rotating Augment session accounts')
|
|
11
|
-
.version(
|
|
13
|
+
.version(pkg.version);
|
|
12
14
|
|
|
13
15
|
program
|
|
14
16
|
.command('login')
|
|
@@ -27,3 +29,6 @@ program
|
|
|
27
29
|
|
|
28
30
|
program.parse();
|
|
29
31
|
|
|
32
|
+
// Non-blocking update check — runs after command finishes
|
|
33
|
+
checkUpdate();
|
|
34
|
+
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const pkg = require("../../package.json");
|
|
2
|
+
|
|
3
|
+
async function checkUpdate() {
|
|
4
|
+
try {
|
|
5
|
+
const resp = await fetch(`https://registry.npmjs.org/${pkg.name}/latest`, {
|
|
6
|
+
signal: AbortSignal.timeout(3000),
|
|
7
|
+
});
|
|
8
|
+
if (!resp.ok) return;
|
|
9
|
+
const data = await resp.json();
|
|
10
|
+
if (data.version && data.version !== pkg.version) {
|
|
11
|
+
const cmd = pkg.name.startsWith("@")
|
|
12
|
+
? `npm i -g ${pkg.name}`
|
|
13
|
+
: `npm i -g ${pkg.name}`;
|
|
14
|
+
console.log(
|
|
15
|
+
`\n\x1b[33m⬆ Update available: ${pkg.version} → ${data.version}\x1b[0m`,
|
|
16
|
+
);
|
|
17
|
+
console.log(` Run: \x1b[36m${cmd}\x1b[0m\n`);
|
|
18
|
+
}
|
|
19
|
+
} catch {
|
|
20
|
+
// Silently ignore — no network, timeout, etc.
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
module.exports = { checkUpdate };
|