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!" ); } } }