fix: Only show update message if current < latest (#1499)
This commit is contained in:
@@ -17,6 +17,7 @@ export { walk, WalkError } from "https://deno.land/std@0.193.0/fs/walk.ts";
|
||||
export { parse } from "https://deno.land/std@0.193.0/flags/mod.ts";
|
||||
export { gte } from "https://deno.land/std@0.193.0/semver/mod.ts";
|
||||
export { existsSync } from "https://deno.land/std@0.193.0/fs/mod.ts";
|
||||
export * as semver from "https://deno.land/std@0.195.0/semver/mod.ts";
|
||||
|
||||
// ts-morph
|
||||
export { Node, Project } from "https://deno.land/x/ts_morph@17.0.1/mod.ts";
|
||||
|
||||
+19
-8
@@ -1,4 +1,4 @@
|
||||
import { colors, join } from "./deps.ts";
|
||||
import { colors, join, semver } from "./deps.ts";
|
||||
|
||||
export interface CheckFile {
|
||||
last_checked: string;
|
||||
@@ -45,10 +45,18 @@ async function fetchLatestVersion() {
|
||||
throw new Error(`Could not fetch latest version.`);
|
||||
}
|
||||
|
||||
async function readCurrentVersion() {
|
||||
const versions = (await import("../../versions.json", {
|
||||
"assert": { type: "json" },
|
||||
})).default as string[];
|
||||
return versions[0];
|
||||
}
|
||||
|
||||
export async function updateCheck(
|
||||
interval: number,
|
||||
getCacheDir = getFreshCacheDir,
|
||||
getLatestVersion = fetchLatestVersion,
|
||||
getCurrentVersion = readCurrentVersion,
|
||||
) {
|
||||
// Skip update checks on CI or Deno Deploy
|
||||
if (
|
||||
@@ -70,13 +78,11 @@ export async function updateCheck(
|
||||
}
|
||||
}
|
||||
|
||||
const versions = (await import("../../versions.json", {
|
||||
"assert": { type: "json" },
|
||||
})).default as string[];
|
||||
const version = await getCurrentVersion();
|
||||
|
||||
let checkFile: CheckFile = {
|
||||
current_version: versions[0],
|
||||
latest_version: versions[0],
|
||||
current_version: version,
|
||||
latest_version: version,
|
||||
last_checked: new Date(0).toISOString(),
|
||||
};
|
||||
try {
|
||||
@@ -89,7 +95,7 @@ export async function updateCheck(
|
||||
}
|
||||
|
||||
// Update current version
|
||||
checkFile.current_version = versions[0];
|
||||
checkFile.current_version = version;
|
||||
|
||||
// Only check in the specificed interval
|
||||
if (Date.now() >= new Date(checkFile.last_checked).getTime() + interval) {
|
||||
@@ -105,7 +111,12 @@ export async function updateCheck(
|
||||
}
|
||||
}
|
||||
|
||||
if (checkFile.current_version !== checkFile.latest_version) {
|
||||
// Only show update message if current version is smaller than latest
|
||||
const currentVersion = semver.parse(checkFile.current_version);
|
||||
const latestVersion = semver.parse(checkFile.latest_version);
|
||||
if (
|
||||
semver.lt(currentVersion, latestVersion)
|
||||
) {
|
||||
const current = colors.bold(colors.rgb8(checkFile.current_version, 208));
|
||||
const latest = colors.bold(colors.rgb8(checkFile.latest_version, 121));
|
||||
console.log(
|
||||
|
||||
Reference in New Issue
Block a user