DenReg/cli/commands/upgrade.ts

65 lines
1.6 KiB
TypeScript
Raw Normal View History

2023-11-28 15:10:33 +00:00
import { CliffyPrompt, 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) {
2023-11-28 15:10:33 +00:00
const res = await CliffyPrompt.Confirm.prompt({
2020-10-14 20:04:18 +00:00
message: Colors.yellow("No update available!") + " Continue?",
default: false,
});
if (!res) return;
}
2023-11-28 15:10:33 +00:00
const res = await CliffyPrompt.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:20:30 +00:00
const cmd_base = ["deno", "install", "-A", "--unstable", "-f"];
const cmd1 = [
...cmd_base,
2021-04-28 10:16:50 +00:00
`https://deno.hibas123.de/raw/@denreg-cli@${meta.version}/denreg.ts`,
];
2021-04-28 10:20:30 +00:00
const cmd2 = [
...cmd_base,
`https://deno.hibas123.de/raw/@denreg-cli@${meta.version}/dpm.ts`,
];
2021-04-28 10:16:50 +00:00
await requestPermOrExit(
"run",
"Run permission required to install new version. Or run it manually: " +
2021-04-28 10:20:30 +00:00
cmd1.join(" ")
2021-04-28 10:16:50 +00:00
);
2021-04-28 10:20:30 +00:00
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,
2020-08-16 17:28:27 +00:00
});
2021-04-28 10:20:30 +00:00
const s2 = await process2.status();
if (!s2) {
2020-08-16 17:28:27 +00:00
console.log(Colors.red("Upgrade failed!"));
}
}
}