cofluxd 0.1.0 → 0.1.2

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.
Files changed (2) hide show
  1. package/cofluxd.mjs +23 -2
  2. package/package.json +1 -1
package/cofluxd.mjs CHANGED
@@ -45,6 +45,20 @@ async function download(url, dest) {
45
45
  if (!res.ok) die(`下载失败 HTTP ${res.status}: ${url}\n(该版本/平台的 release 资产是否已发布?)`);
46
46
  fs.writeFileSync(dest, Buffer.from(await res.arrayBuffer()), { mode: 0o755 });
47
47
  }
48
+ // 取最新 release tag(含 prerelease;GitHub 的 /releases/latest 跳转不含 prerelease,故走 API)。
49
+ async function resolveLatestTag() {
50
+ try {
51
+ const r = await fetch(`https://api.github.com/repos/${REPO}/releases?per_page=1`, {
52
+ headers: { "user-agent": "cofluxd", accept: "application/vnd.github+json" },
53
+ });
54
+ if (!r.ok) return null;
55
+ const arr = await r.json();
56
+ return Array.isArray(arr) && arr[0]?.tag_name ? arr[0].tag_name : null;
57
+ } catch {
58
+ return null;
59
+ }
60
+ }
61
+
48
62
  async function ensureBinaries({ version, binDir }) {
49
63
  fs.mkdirSync(BIN_DIR, { recursive: true });
50
64
  if (binDir) {
@@ -58,7 +72,14 @@ async function ensureBinaries({ version, binDir }) {
58
72
  return;
59
73
  }
60
74
  const t = rustTarget();
61
- const base = version === "latest" ? `https://github.com/${REPO}/releases/latest/download` : `https://github.com/${REPO}/releases/download/${version}`;
75
+ let base;
76
+ if (version === "latest") {
77
+ const tag = await resolveLatestTag();
78
+ if (tag) console.log(`最新版本: ${tag}`);
79
+ base = tag ? `https://github.com/${REPO}/releases/download/${tag}` : `https://github.com/${REPO}/releases/latest/download`;
80
+ } else {
81
+ base = `https://github.com/${REPO}/releases/download/${version}`;
82
+ }
62
83
  for (const b of ["coflux-supervisor", "coflux-worker"]) {
63
84
  process.stdout.write(`下载 ${b}-${t} … `);
64
85
  await download(`${base}/${b}-${t}`, join(BIN_DIR, b));
@@ -184,7 +205,7 @@ function cmdReload() {
184
205
  function cmdDown() { stopService(); console.log("✓ 已停止"); }
185
206
 
186
207
  async function cmdUpdate(v) {
187
- if (!fs.existsSync(ENV_FILE)) die("尚未安装,先 cofluxd up / onboard");
208
+ if (!fs.existsSync(SETTINGS)) die("尚未安装,先 cofluxd up / onboard");
188
209
  await ensureBinaries({ version: v.version, binDir: v["bin-dir"] });
189
210
  restartService();
190
211
  console.log(`✓ 已更新到 ${v["bin-dir"] ? "本地产物" : v.version} 并重启(supervisor)`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cofluxd",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "coflux daemon 管理 CLI:装/起/停/升级 Rust daemon(supervisor + worker)",
5
5
  "type": "module",
6
6
  "bin": {