diff --git a/cli/commands/publish.ts b/cli/commands/publish.ts index fe822dd..e6f693a 100644 --- a/cli/commands/publish.ts +++ b/cli/commands/publish.ts @@ -42,23 +42,27 @@ async function runHooks(hooks: undefined | string | string[]) { } export default async function publish(options: { dry: boolean }) { - const meta: IMeta = await getMeta(); + const originalMeta = await getMeta(); + + if (originalMeta.hooks) { + log("Running prepublish hooks"); + await runHooks(originalMeta.hooks.prepublish); + } + + const meta = await getMeta(); + + //TODO: Output Diff between original and result meta if (!meta.name) throw new Error("name is not set in meta.json"); if (!meta.version) throw new Error("version is not set in meta.json"); 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"; try { - const walker = FS.walk(".", { + const walker = FS.walk(meta.root || ".", { includeDirs: false, includeFiles: true, match: meta.files.map((file) => Path.globToRegExp(file)), @@ -66,17 +70,18 @@ export default async function publish(options: { dry: boolean }) { log("Copying files to package to", tmpDir); - const copy = async (path: string) => { - const dest = Path.join(tmpDir, path); + const copy = async (path: string, abs?: boolean) => { + const relative = abs ? path : Path.relative(meta.root || ".", path); + log("Adding file:", path, "as", relative); + const dest = Path.join(tmpDir, relative); await FS.ensureDir(Path.dirname(dest)); await FS.copy(path, dest); }; - await copy("meta.json"); + await copy("meta.json", true); for await (const file of walker) { await copy(file.path); - log("Adding file:", file.path); } log("Compressing files into", packedFile); @@ -88,9 +93,14 @@ export default async function publish(options: { dry: boolean }) { const url = new URL(getConfig("registry")); url.pathname = "/api/package/" + meta.name; + console.log( + "Pushing version", + Colors.blue(meta.version), + "to repository" + ); + if (!options.dry) { log("Uploading new package version"); - await fetch(url, { method: "POST", body: await Deno.readFile(packedFile), diff --git a/cli/global.ts b/cli/global.ts index d5bad3f..8fcf6a9 100644 --- a/cli/global.ts +++ b/cli/global.ts @@ -9,6 +9,7 @@ export interface IMeta { contributors?: string[]; deprecated?: boolean; files: string[]; + root?: string; hooks?: { prepublish?: string | string[]; postpublish?: string | string[]; diff --git a/cli/meta.json b/cli/meta.json index f4f51e4..e78eb27 100644 --- a/cli/meta.json +++ b/cli/meta.json @@ -1,6 +1,6 @@ { "name": "@denreg-cli", - "version": "0.2.6", + "version": "0.2.7", "description": "CLI for the DenReg package registry", "author": "Fabian Stamm ", "contributors": [], diff --git a/cli/version.ts b/cli/version.ts index 1318cd8..67ec2d3 100644 --- a/cli/version.ts +++ b/cli/version.ts @@ -1 +1 @@ -export const version = "0.2.6" \ No newline at end of file +export const version = "0.2.7" \ No newline at end of file