Skip to content

Commit

Permalink
Updated to handle versioning
Browse files Browse the repository at this point in the history
  • Loading branch information
ccalamos committed May 7, 2021
1 parent 7ec4beb commit bbe27fe
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
18 changes: 11 additions & 7 deletions commands/update/upgrade.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import { dirname, join } from "https://deno.land/std@0.95.0/path/mod.ts";
import { existsSync } from "https://deno.land/std@0.95.0/fs/exists.ts";
import { getVersion } from "../../utils/version.ts";

export default async function () {
export default async function (isInstall = false) {
console.log("Looking up latest version...");

const versionMetaUrl = "https://cdn.deno.land/barrel/meta/versions.json";
const { latest } = await (await fetch(versionMetaUrl)).json();

const denoExecPath = Deno.execPath();
console.log(denoExecPath);
const cmdExists = existsSync(join(dirname(denoExecPath), "barrel"));
console.log(cmdExists);

if (!isInstall && cmdExists && latest === getVersion()) {
console.log('Already up-to-date!')
Deno.exit(0);
}

try {
const p = Deno.run({
Expand All @@ -31,11 +35,11 @@ export default async function () {
});
const status = await p.status();
if (status.success) {
if (cmdExists) {
console.log(`Barrel-CLI is up to ${latest}`);
if (!isInstall) {
console.log(`Barrel-CLI is updated to ${latest}!`);
} else {
console.log("Barrel-CLI was installed successfully");
console.log(`Run 'barrel -h' to get started`);
console.log("Barrel-CLI was installed successfully!");
console.log(`Run 'barrel -h' to get started.`);
}
}
Deno.exit(status.code);
Expand Down
8 changes: 2 additions & 6 deletions utils/version.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import { IVersion, ValidVersion } from "../types.ts";

const CURRENT_DATE = new Date();
const VERSION_INFO: IVersion = {
year: CURRENT_DATE.getFullYear().toString().slice(2) as IVersion["year"],
month: (CURRENT_DATE.getMonth() + 1).toString().padStart(
2,
"0",
) as IVersion["month"],
year: "21",
month: "05",
minor: "0",
patch: "4",
separator: ".",
Expand Down

0 comments on commit bbe27fe

Please sign in to comment.