DenReg/cli/commands/upgrade.ts

65 lines
1.6 KiB
TypeScript

import { Cliffy, Colors } from "../deps.ts";
import { version } from "../version.ts";
import { requestPermOrExit } from "../helper/permission.ts";
export default async function upgrade() {
await requestPermOrExit(
"net",
"Net permission required to fetch new version"
);
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 cmd_base = ["deno", "install", "-A", "--unstable", "-f"];
const cmd1 = [
...cmd_base,
`https://deno.hibas123.de/raw/@denreg-cli@${meta.version}/denreg.ts`,
];
const cmd2 = [
...cmd_base,
`https://deno.hibas123.de/raw/@denreg-cli@${meta.version}/dpm.ts`,
];
await requestPermOrExit(
"run",
"Run permission required to install new version. Or run it manually: " +
cmd1.join(" ")
);
const process1 = Deno.run({
cmd: cmd1,
});
const s1 = await process1.status();
if (!s1) {
console.log(Colors.red("Upgrade failed!"));
}
const process2 = Deno.run({
cmd: cmd2,
});
const s2 = await process2.status();
if (!s2) {
console.log(Colors.red("Upgrade failed!"));
}
}
}