framework
Version:
The (AI) Framework: turnkey, zero-config AI orchestration that wraps a coding-agent CLI (Claude Code) as a black box and takes you from an idea to a running app. Vite for AI.
71 lines • 2.86 kB
JavaScript
/**
* CLI "up-to-date?" check (#312): after the bare-`framework` version footer,
* tell the user whether a newer version is published on npm. Display only;
* auto-update is a separate, deferred concern. Same seam + node-adapter +
* forgiving-on-error convention as `project.ts` (#380).
*/
/** The npm package this CLI ships as; the registry key for the version check. */
export const PACKAGE_NAME = 'framework';
/**
* A {@link VersionFetcher} backed by the npm registry. GETs the packument and
* reads `dist-tags.latest`. A 2.5s AbortSignal.timeout caps it; any error /
* non-ok / offline yields undefined (the check silently degrades to "unknown").
*/
export function nodeVersionFetcher() {
return async (pkg) => {
try {
const res = await fetch(`https://registry.npmjs.org/${pkg}`, { signal: AbortSignal.timeout(2500) });
if (!res.ok)
return undefined;
const data = (await res.json());
const latest = data?.['dist-tags']?.latest;
return typeof latest === 'string' ? latest : undefined;
}
catch {
return undefined;
}
};
}
/**
* Compare two `major.minor.patch` versions numerically (a prerelease/build
* suffix after `-` or `+` is stripped, missing parts read as 0). Returns
* -1 / 0 / 1. No semver dependency.
*/
export function compareVersions(a, b) {
const parse = (v) => (v.split(/[-+]/)[0] ?? '').split('.').map(n => parseInt(n, 10) || 0);
const pa = parse(a);
const pb = parse(b);
for (let i = 0; i < Math.max(pa.length, pb.length); i++) {
const na = pa[i] ?? 0;
const nb = pb[i] ?? 0;
if (na !== nb)
return na < nb ? -1 : 1;
}
return 0;
}
/**
* Check whether `current` is behind the latest published version. Uses the
* injected fetcher; a missing/failed fetch is 'unknown'. `current` >= latest is
* 'up-to-date' (so running a local build ahead of the registry never reads as
* "update available").
*/
export async function checkForUpdate(current, fetchLatest, pkg = PACKAGE_NAME) {
const latest = await fetchLatest(pkg);
if (!latest)
return { kind: 'unknown', current };
return compareVersions(latest, current) > 0
? { kind: 'update-available', current, latest }
: { kind: 'up-to-date', current };
}
/** The one-line message to print for a status, or undefined for 'unknown' (print nothing). */
export function formatUpdateStatus(status) {
switch (status.kind) {
case 'up-to-date':
return `✅ Up to date (v${status.current})`;
case 'update-available':
return `⬆️ Update available: v${status.latest} (you have v${status.current}). Run: npm i -g ${PACKAGE_NAME}`;
case 'unknown':
return undefined;
}
}
//# sourceMappingURL=update-check.js.map