Improve upgrade script
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
User user
2021-04-28 12:16:50 +02:00
parent e5829d9a4f
commit 3cda4ee8c8
8 changed files with 64 additions and 12 deletions

26
cli/helper/permission.ts Normal file
View File

@ -0,0 +1,26 @@
import { Colors } from "../deps.ts";
export const checkPermOrExit = (name: string, err: string) =>
Deno.permissions.query({ name: name as any }).then((res) => {
if (res.state !== "granted") {
console.log(Colors.bold(Colors.red(err)));
Deno.exit(1);
}
});
export const requestPermOrExit = (name: string, err: string) => {
Deno.permissions
.query({ name: name as any })
.then((res) => {
if (res.state === "prompt") {
return Deno.permissions.request({ name: name as any });
}
return res;
})
.then((res) => {
if (res.state !== "granted") {
console.log(Colors.bold(Colors.red(err)));
Deno.exit(1);
}
});
};

View File

@ -1,6 +1,11 @@
import { Colors } from "../deps.ts";
import { checkPermOrExit } from "../helper/permission.ts";
export async function runScript(script: string) {
await checkPermOrExit(
"run",
"Requires --allow-run to run scripts and hooks"
);
console.log(Colors.bold(Colors.blue("Running script:")), script);
const runPerm = await Deno.permissions.query({
name: "run",