DenReg/cli/commands/upgrade.ts

53 lines
1.3 KiB
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";
2021-04-28 10:16:50 +00:00
import { requestPermOrExit } from "../helper/permission.ts";
2020-08-16 17:28:27 +00:00
export default async function upgrade() {
2021-04-28 10:16:50 +00:00
await requestPermOrExit(
"net",
"Net permission required to fetch new version"
);
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) {
2021-04-28 10:16:50 +00:00
const cmd = [
"deno",
"install",
"-A",
"--unstable",
"-f",
`https://deno.hibas123.de/raw/@denreg-cli@${meta.version}/denreg.ts`,
];
await requestPermOrExit(
"run",
"Run permission required to install new version. Or run it manually: " +
cmd.join(" ")
);
2020-08-16 17:28:27 +00:00
const process = Deno.run({
2021-04-28 10:16:50 +00:00
cmd,
2020-08-16 17:28:27 +00:00
});
const s = await process.status();
if (!s) {
console.log(Colors.red("Upgrade failed!"));
}
}
}