Refine version command with async update cache and background check
This commit is contained in:
1 parent
68a858b4b9
commit
6ad01893b3
6 files changed
+410
-5
No files matched your search
@@ -3,6 +3,7 @@ import { basename, dirname, join } from "node:path";
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { isCompiledBinary } from "../../core/runtime.js";
|
||||
import { readInstalledSkillVersion } from "../../core/embedded-skill.js";
|
||||
import { saveUpdateCache } from "../../core/update-cache.js";
|
||||
import { VERSION, IS_RELEASE } from "../../version.js";
|
||||
import { runServiceCommand, serviceStatus } from "../service.js";
|
||||
import { printJson } from "../printer.js";
|
||||
@@ -23,6 +24,7 @@ export type UpdateOptions = {
|
||||
force?: boolean;
|
||||
targetVersion?: string;
|
||||
repo?: string;
|
||||
bgSave?: boolean;
|
||||
};
|
||||
|
||||
export async function handleUpdateCommand(runtime: CliRuntime, options: UpdateOptions = {}) {
|
||||
@@ -103,6 +105,18 @@ export async function handleUpdateCommand(runtime: CliRuntime, options: UpdateOp
|
||||
const isUpgrade = isNewerVersion(latestVersion, VERSION);
|
||||
const pendingReleases = releases.filter((r) => isNewerVersion(r.version, VERSION));
|
||||
|
||||
if (latestRelease?.version) {
|
||||
saveUpdateCache({
|
||||
latestVersion: latestRelease.version,
|
||||
publishedAt: latestRelease.publishedAt,
|
||||
releaseUrl: latestRelease.htmlUrl
|
||||
});
|
||||
}
|
||||
|
||||
if (options.bgSave) {
|
||||
return;
|
||||
}
|
||||
|
||||
printJson({
|
||||
updated: false,
|
||||
updateAvailable: isUpgrade,
|
||||
@@ -174,6 +188,18 @@ export async function handleUpdateCommand(runtime: CliRuntime, options: UpdateOp
|
||||
const shouldUpdate = isUpgrade || Boolean(options.force);
|
||||
const pendingReleases = releases.filter((r) => isNewerVersion(r.version, VERSION));
|
||||
|
||||
if (release?.version) {
|
||||
saveUpdateCache({
|
||||
latestVersion: release.version,
|
||||
publishedAt: release.publishedAt,
|
||||
releaseUrl: release.htmlUrl
|
||||
});
|
||||
}
|
||||
|
||||
if (options.bgSave) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (options.checkOnly) {
|
||||
printJson({
|
||||
updated: false,
|
||||
@@ -277,6 +303,12 @@ export async function handleUpdateCommand(runtime: CliRuntime, options: UpdateOp
|
||||
// function returns, and nothing is left running.
|
||||
const skillSync = installSkillFromInstalledBinary(execPath, latestVersion);
|
||||
|
||||
saveUpdateCache({
|
||||
latestVersion,
|
||||
publishedAt: release.publishedAt,
|
||||
releaseUrl: release.htmlUrl
|
||||
});
|
||||
|
||||
printJson({
|
||||
updated: true,
|
||||
fromVersion: VERSION,
|
||||
|
||||
Reference in new issue
Block a user