Add script running abilities
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:
46
cli/helper/run_script.ts
Normal file
46
cli/helper/run_script.ts
Normal file
@ -0,0 +1,46 @@
|
||||
import { Colors } from "../deps.ts";
|
||||
|
||||
export async function runScript(script: string) {
|
||||
console.log(Colors.bold(Colors.blue("Running script:")), script);
|
||||
const runPerm = await Deno.permissions.query({
|
||||
name: "run",
|
||||
});
|
||||
|
||||
if (runPerm.state !== "granted") {
|
||||
console.log(
|
||||
Colors.red("Missing --allow-run permission. Cannot run hooks!")
|
||||
);
|
||||
throw new Error("Missing --allow-run permission. Cannot run hooks!");
|
||||
}
|
||||
|
||||
const process = Deno.run({
|
||||
cmd: ["deno", "run", "-A", "--unstable", script],
|
||||
});
|
||||
|
||||
const status = await process.status();
|
||||
|
||||
console.log(Colors.bold(Colors.blue("Finished script:")), script);
|
||||
|
||||
if (!status.success) {
|
||||
throw new Error(
|
||||
"A script did not complete sucessfully. This is not a issue of denreg!"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export async function runHooks(hooks: undefined | string | string[]) {
|
||||
if (!hooks) return;
|
||||
if (typeof hooks === "string") {
|
||||
hooks = [hooks];
|
||||
}
|
||||
|
||||
for (const hook of hooks) {
|
||||
try {
|
||||
await runScript(hook);
|
||||
} catch (err) {
|
||||
throw new Error(
|
||||
"A hook did not complete sucessfully. This is not a issue of denreg!"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user