easy-codex 0.2.2 → 0.2.3
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/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
显示当前本机 Codex 登录账号的剩余额度百分比和重置时间。第三方辅助工具,与 OpenAI 无官方隶属关系。
|
|
4
4
|
|
|
5
|
+
## v0.2.3 修复说明
|
|
6
|
+
|
|
7
|
+
- update先在线检查正式版本,再按明确版本号安装,避免npm旧缓存导致降级;已是最新或本地版本更高时不重复安装。
|
|
8
|
+
- 包含上一版update、show自动重开、09:00–18:00绿色时段,以及完整版本说明。
|
|
9
|
+
|
|
5
10
|
## v0.2.2 新增与调整
|
|
6
11
|
|
|
7
12
|
- **命令更新**:新增 `easy-codex update`,从官方 npm 更新当前全局安装。
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<key>CFBundleIdentifier</key><string>com.unionschool.easy-codex.overlay</string>
|
|
6
6
|
<key>CFBundleName</key><string>Easy Codex Overlay</string>
|
|
7
7
|
<key>CFBundlePackageType</key><string>APPL</string>
|
|
8
|
-
<key>CFBundleShortVersionString</key><string>0.2.
|
|
8
|
+
<key>CFBundleShortVersionString</key><string>0.2.3</string>
|
|
9
9
|
<key>LSMinimumSystemVersion</key><string>14.0</string>
|
|
10
10
|
<key>LSUIElement</key><true/>
|
|
11
11
|
<key>NSHighResolutionCapable</key><true/>
|
|
Binary file
|
package/package.json
CHANGED
package/src/update.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { access, realpath } from 'node:fs/promises';
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
2
3
|
import { dirname, basename, join, delimiter } from 'node:path';
|
|
3
4
|
import { fileURLToPath } from 'node:url';
|
|
4
|
-
import { spawn } from 'node:child_process';
|
|
5
|
+
import { spawn, execFile } from 'node:child_process';
|
|
6
|
+
import { promisify } from 'node:util';
|
|
7
|
+
const { version } = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
|
|
5
8
|
|
|
6
9
|
export function installedPrefix(root, platform = process.platform) {
|
|
7
10
|
const modules = dirname(root.replace(/[\\/]$/, ''));
|
|
@@ -10,6 +13,15 @@ export function installedPrefix(root, platform = process.platform) {
|
|
|
10
13
|
return basename(parent) === 'lib' ? dirname(parent) : platform === 'win32' ? parent : null;
|
|
11
14
|
}
|
|
12
15
|
|
|
16
|
+
export function isNewer(latest, current) {
|
|
17
|
+
if (!/^\d+\.\d+\.\d+$/.test(latest) || !/^\d+\.\d+\.\d+(?:-[\w.-]+)?$/.test(current)) {
|
|
18
|
+
throw new Error('无法识别正式版本号,未执行更新。');
|
|
19
|
+
}
|
|
20
|
+
const a = latest.split('.').map(Number), b = current.split('-')[0].split('.').map(Number);
|
|
21
|
+
for (let i = 0; i < 3; i++) { if (a[i] !== b[i]) return a[i] > b[i]; }
|
|
22
|
+
return current.includes('-');
|
|
23
|
+
}
|
|
24
|
+
|
|
13
25
|
async function findNpmCli() {
|
|
14
26
|
const directories = [dirname(process.execPath), ...(process.env.PATH ?? '').split(delimiter)];
|
|
15
27
|
for (const directory of directories.filter(Boolean)) {
|
|
@@ -22,6 +34,14 @@ async function findNpmCli() {
|
|
|
22
34
|
throw new Error('未找到 npm,请先安装 Node.js/npm,再使用 npm i -g 更新。');
|
|
23
35
|
}
|
|
24
36
|
|
|
37
|
+
async function readLatest(npmCli, name) {
|
|
38
|
+
try {
|
|
39
|
+
const { stdout } = await promisify(execFile)(process.execPath, [npmCli, 'view', name, 'dist-tags.latest',
|
|
40
|
+
'--json', '--prefer-online', '--registry=https://registry.npmjs.org'], { timeout: 30000, maxBuffer: 4096 });
|
|
41
|
+
return JSON.parse(stdout);
|
|
42
|
+
} catch { throw new Error('无法在线检查 npm 最新版本,请检查网络后重试。'); }
|
|
43
|
+
}
|
|
44
|
+
|
|
25
45
|
function runNpm(command, args) {
|
|
26
46
|
return new Promise((resolve, reject) => {
|
|
27
47
|
const child = spawn(command, args, { stdio: 'inherit', shell: false });
|
|
@@ -34,12 +54,19 @@ function runNpm(command, args) {
|
|
|
34
54
|
}
|
|
35
55
|
|
|
36
56
|
export async function updatePackage(name, { root = fileURLToPath(new URL('../', import.meta.url)),
|
|
37
|
-
getNpmCli = findNpmCli,
|
|
57
|
+
getNpmCli = findNpmCli, getLatest = readLatest, currentVersion = version,
|
|
58
|
+
run = runNpm, platform = process.platform } = {}) {
|
|
38
59
|
if (!['easy-codex', 'easy-claude'].includes(name)) throw new Error('不支持的更新包名。');
|
|
39
60
|
const npmCli = await getNpmCli();
|
|
61
|
+
const latest = await getLatest(npmCli, name);
|
|
62
|
+
if (!isNewer(latest, currentVersion)) {
|
|
63
|
+
console.log(`${name} 当前 ${currentVersion},npm 最新 ${latest},无需更新。`);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
40
66
|
const prefix = installedPrefix(root, platform);
|
|
67
|
+
// 先在线检查再锁定版本,避免安装阶段复用旧 latest 缓存而降级。
|
|
41
68
|
const args = [npmCli, 'install', '--global', ...(prefix ? ['--prefix', prefix] : []),
|
|
42
|
-
'--registry=https://registry.npmjs.org', `${name}
|
|
69
|
+
'--prefer-online', '--registry=https://registry.npmjs.org', `${name}@${latest}`];
|
|
43
70
|
await run(process.execPath, args);
|
|
44
|
-
console.log(`${name}
|
|
71
|
+
console.log(`${name} 已更新到 ${latest};运行 ${name} show 自动重启浮窗。`);
|
|
45
72
|
}
|