DenReg/cli/commands/upgrade.ts

40 lines
989 B
TypeScript
Raw Normal View History

2020-08-16 17:28:27 +00:00
import { Cliffy, Colors } from "../deps.ts";
2020-10-14 20:04:18 +00:00
import { version } from "../version.ts";
2020-08-16 17:28:27 +00:00
export default async function upgrade() {
2020-10-14 20:04:18 +00:00
const meta = await fetch(
"https://deno.hibas123.de/raw/@denreg-cli/meta.json"
).then((e) => e.json());
if (meta.version === version) {
const res = await Cliffy.Confirm.prompt({
message: Colors.yellow("No update available!") + " Continue?",
default: false,
});
if (!res) return;
}
2020-08-16 17:28:27 +00:00
const res = await Cliffy.Confirm.prompt({
2020-10-14 20:04:18 +00:00
message: "Are you sure you want to upgrade?",
2020-08-16 17:28:27 +00:00
default: true,
});
if (res) {
const process = Deno.run({
cmd: [
"deno",
"install",
"-A",
"--unstable",
"-f",
2020-10-14 20:04:18 +00:00
`https://deno.hibas123.de/raw/@denreg-cli@${meta.version}/denreg.ts`,
2020-08-16 17:28:27 +00:00
],
});
const s = await process.status();
if (!s) {
console.log(Colors.red("Upgrade failed!"));
}
}
}