Improve upgrade script
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
26
cli/helper/permission.ts
Normal file
26
cli/helper/permission.ts
Normal 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);
|
||||
}
|
||||
});
|
||||
};
|
@ -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",
|
||||
|
Reference in New Issue
Block a user