Skip to content

Commit

Permalink
fix(cli): add latest version check
Browse files Browse the repository at this point in the history
  • Loading branch information
Qu4k committed Sep 8, 2020
1 parent 6146dec commit 74caccf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion denon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ if (import.meta.main) {

// show all available scripts.
if (args.cmd.length === 0) {
printAvailableScripts(config);
await printAvailableScripts(config);
Deno.exit(0);
}

Expand Down
21 changes: 20 additions & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ export async function upgrade(version?: string): Promise<void> {

/** List all available scripts declared in the config file.
* // TODO(@qu4k): make it interactive */
export function printAvailableScripts(config: CompleteDenonConfig): void {
export async function printAvailableScripts(
config: CompleteDenonConfig,
): Promise<void> {
if (Object.keys(config.scripts).length) {
logger.info("available scripts:");
const runner = new Runner(config);
Expand Down Expand Up @@ -174,6 +176,23 @@ export function printAvailableScripts(config: CompleteDenonConfig): void {
);
}
}
const latest = await fetchLatestVersion();
if (latest && latest !== VERSION) {
logger.warning(`New version available (${latest}). Upgrade with \`${
blue(
"denon",
)
} ${yellow("--upgrade")}${reset("`.")}`);
}
}

export async function fetchLatestVersion(): Promise<string | undefined> {
const cdn = "https://cdn.deno.land/";
const url = `${cdn}denon/meta/versions.json`;
const res = await fetch(url);
if (res.status !== 200) return undefined;
const data = await res.json();
return data.latest;
}

/** Help message to be shown if `denon`
Expand Down

0 comments on commit 74caccf

Please sign in to comment.