DenReg/cli/commands/upgrade.ts
Fabian Stamm ed1ce0cc0f
All checks were successful
continuous-integration/drone/push Build is passing
Improving update support
2020-10-14 22:04:18 +02:00

40 lines
989 B
TypeScript

import { Cliffy, Colors } from "../deps.ts";
import { version } from "../version.ts";
export default async function upgrade() {
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;
}
const res = await Cliffy.Confirm.prompt({
message: "Are you sure you want to upgrade?",
default: true,
});
if (res) {
const process = Deno.run({
cmd: [
"deno",
"install",
"-A",
"--unstable",
"-f",
`https://deno.hibas123.de/raw/@denreg-cli@${meta.version}/denreg.ts`,
],
});
const s = await process.status();
if (!s) {
console.log(Colors.red("Upgrade failed!"));
}
}
}