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:
@ -1,46 +1,8 @@
|
||||
import { Colors, Path, FS, Compress, Base64 } from "../deps.ts";
|
||||
import { getMeta, IMeta, log, getConfig } from "../global.ts";
|
||||
import { runHooks } from "../helper/run_script.ts";
|
||||
import { ServerError } from "../helper/server_error.ts";
|
||||
|
||||
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 hook did not complete sucessfully. This is not a issue of denreg!"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async function runHooks(hooks: undefined | string | string[]) {
|
||||
if (!hooks) return;
|
||||
if (typeof hooks === "string") {
|
||||
hooks = [hooks];
|
||||
}
|
||||
|
||||
for (const hook of hooks) {
|
||||
await runScript(hook);
|
||||
}
|
||||
}
|
||||
|
||||
export default async function publish(options: { dry: boolean }) {
|
||||
const originalMeta = await getMeta();
|
||||
|
||||
|
18
cli/commands/run.ts
Normal file
18
cli/commands/run.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import { Colors, Path, FS, Compress, Base64 } from "../deps.ts";
|
||||
import { getMeta, IMeta, log, getConfig } from "../global.ts";
|
||||
import { ServerError } from "../helper/server_error.ts";
|
||||
|
||||
import { runScript } from "../helper/run_script.ts";
|
||||
|
||||
export default async function run(options: {}, name: string) {
|
||||
const { scripts } = await getMeta();
|
||||
if (!scripts || !scripts[name]) {
|
||||
console.log(Colors.bold(Colors.red("Script not found:")), name);
|
||||
} else {
|
||||
let script = scripts[name];
|
||||
if (!Array.isArray(script)) script = [script];
|
||||
for (const s of script) {
|
||||
await runScript(s);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user