shine-code-submit 1.0.5 → 1.0.6
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/.claude-plugin/plugin.json +1 -1
- package/dist/install.cjs +1 -1
- package/package.json +1 -1
- package/src/cli/main.ts +15 -0
- package/src/daemon/server.ts +32 -0
- package/src/daemon/settings.ts +6 -0
- package/src/daemon/ui-assets.ts +1 -1
- package/src/shared/updater.ts +73 -0
- package/ui/.build/app.js +49 -49
- package/ui/components/SettingsModule.tsx +70 -6
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// 自动更新:查 npm registry 最新版本,有新版 spawn detached `npx shine-code-submit@latest install` 升级。
|
|
2
|
+
// daemon 启动时 + 定时调 autoUpdateIfNeeded。全程静默(try/catch),绝不影响 daemon。
|
|
3
|
+
//
|
|
4
|
+
// 升级链路:npx 拉 latest 包 → install CLI 部署新版到 cache + 注册 → startDaemonWithBun(1.0.5)
|
|
5
|
+
// 检测旧 daemon 版本不匹配 → stopDaemon 停旧 → 启新 daemon。daemon 退出不影响 npx install(detached)。
|
|
6
|
+
import { spawn } from "node:child_process";
|
|
7
|
+
import { SERVICE_NAME, SERVICE_VERSION } from "./config";
|
|
8
|
+
import { readSettings, writeSettings } from "../daemon/settings";
|
|
9
|
+
|
|
10
|
+
const REGISTRY_LATEST = `https://registry.npmjs.org/${SERVICE_NAME}/latest`;
|
|
11
|
+
const NPM_REGISTRY = "https://registry.npmjs.org/";
|
|
12
|
+
|
|
13
|
+
/** semver 大于:a > b 才 true(相等 false)。只升级不降级,避免本地比 npm 新(如发版前 build)时误降级。 */
|
|
14
|
+
function versionGt(a: string, b: string): boolean {
|
|
15
|
+
const pa = a.split(".").map((x) => parseInt(x, 10) || 0);
|
|
16
|
+
const pb = b.split(".").map((x) => parseInt(x, 10) || 0);
|
|
17
|
+
for (let i = 0; i < Math.max(pa.length, pb.length); i++) {
|
|
18
|
+
const x = pa[i] ?? 0;
|
|
19
|
+
const y = pb[i] ?? 0;
|
|
20
|
+
if (x > y) return true;
|
|
21
|
+
if (x < y) return false;
|
|
22
|
+
}
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface UpdateCheck {
|
|
27
|
+
latest?: string;
|
|
28
|
+
current: string;
|
|
29
|
+
hasUpdate: boolean;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** 查 npm registry 最新版本。失败返回 hasUpdate:false(不抛)。 */
|
|
33
|
+
export async function checkForUpdate(): Promise<UpdateCheck> {
|
|
34
|
+
try {
|
|
35
|
+
const res = await fetch(REGISTRY_LATEST, { signal: AbortSignal.timeout(5000) });
|
|
36
|
+
if (!res.ok) return { current: SERVICE_VERSION, hasUpdate: false };
|
|
37
|
+
const data = (await res.json()) as { version?: string };
|
|
38
|
+
const latest = data.version;
|
|
39
|
+
if (!latest) return { current: SERVICE_VERSION, hasUpdate: false };
|
|
40
|
+
return { latest, current: SERVICE_VERSION, hasUpdate: versionGt(latest, SERVICE_VERSION) };
|
|
41
|
+
} catch {
|
|
42
|
+
return { current: SERVICE_VERSION, hasUpdate: false };
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* 自动更新:读 settings(autoUpdate 开关),有新版 spawn detached npx install。
|
|
48
|
+
* 返回 {updated, latest}。全程 try/catch 静默——绝不影响 daemon。
|
|
49
|
+
* - autoUpdate===false → 跳过。
|
|
50
|
+
* - 有新版 → spawn `npx --yes --registry=官方 shine-code-submit@latest install`(detached,不阻塞)。
|
|
51
|
+
* - 无论是否升级,都缓存 latestVersion 到 settings(dashboard 显示用)。
|
|
52
|
+
*/
|
|
53
|
+
export async function autoUpdateIfNeeded(force = false): Promise<{ updated: boolean; latest?: string }> {
|
|
54
|
+
try {
|
|
55
|
+
const s = readSettings();
|
|
56
|
+
if (!force && s.autoUpdate === false) return { updated: false };
|
|
57
|
+
const check = await checkForUpdate();
|
|
58
|
+
// 缓存 latestVersion(dashboard 显示当前/最新版本)
|
|
59
|
+
if (check.latest && check.latest !== s.latestVersion) {
|
|
60
|
+
writeSettings({ ...s, latestVersion: check.latest });
|
|
61
|
+
}
|
|
62
|
+
if (!check.hasUpdate) return { updated: false, latest: check.latest };
|
|
63
|
+
// 有新版:spawn detached npx install(官方 registry 确保 latest,npmmirror 有同步延迟)
|
|
64
|
+
spawn(
|
|
65
|
+
"npx",
|
|
66
|
+
["--yes", `--registry=${NPM_REGISTRY}`, `${SERVICE_NAME}@latest`, "install"],
|
|
67
|
+
{ detached: true, stdio: "ignore", windowsHide: true, shell: true },
|
|
68
|
+
).unref();
|
|
69
|
+
return { updated: true, latest: check.latest };
|
|
70
|
+
} catch {
|
|
71
|
+
return { updated: false };
|
|
72
|
+
}
|
|
73
|
+
}
|