This commit is contained in:
parent
775eca793b
commit
7abe63429f
@ -1,6 +1,45 @@
|
||||
import { Colors, Path, FS, Compress, Base64 } from "../deps.ts";
|
||||
import { getMeta, IMeta, log, getConfig } from "../global.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 meta: IMeta = await getMeta();
|
||||
|
||||
@ -9,6 +48,11 @@ export default async function publish(options: { dry: boolean }) {
|
||||
if (!meta.files || !Array.isArray(meta.files) || meta.files.length <= 0)
|
||||
throw new Error("files is not set or empty in meta.json");
|
||||
|
||||
if (meta.hooks) {
|
||||
log("Running prepublish hooks");
|
||||
await runHooks(meta.hooks.prepublish);
|
||||
}
|
||||
|
||||
const tmpDir = await Deno.makeTempDir();
|
||||
const packedFile = (await Deno.makeTempFile()) + ".tar";
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Cliffy, Path } from "./deps.ts";
|
||||
import { Cliffy, Path, Colors } from "./deps.ts";
|
||||
import { init } from "./global.ts";
|
||||
|
||||
import setupCMD from "./commands/setup.ts";
|
||||
@ -80,5 +80,9 @@ const flags = await new Cliffy.Command()
|
||||
await init(flags.options);
|
||||
|
||||
if (command) {
|
||||
await Promise.resolve((command as CommandHandler)(...opts));
|
||||
try {
|
||||
await Promise.resolve((command as CommandHandler)(...opts));
|
||||
} catch (err) {
|
||||
console.log(Colors.bold(Colors.red("An error occured:")), err.message);
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,10 @@ export interface IMeta {
|
||||
contributors?: string[];
|
||||
deprecated?: boolean;
|
||||
files: string[];
|
||||
hooks?: {
|
||||
prepublish?: string | string[];
|
||||
postpublish?: string | string[];
|
||||
};
|
||||
}
|
||||
|
||||
let verbose = false;
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@denreg-cli",
|
||||
"version": "0.1.11",
|
||||
"version": "0.2.0",
|
||||
"description": "CLI for the DenReg package registry",
|
||||
"author": "Fabian Stamm <dev@fabianstamm.de>",
|
||||
"contributors": [],
|
||||
|
Loading…
Reference in New Issue
Block a user