Add dry run upload and adding additional verbose output
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Fabian Stamm 2020-08-16 11:39:56 +02:00
parent a436a4ecb0
commit ccc48b0480
3 changed files with 40 additions and 36 deletions

View File

@ -1,7 +1,7 @@
import { Colors, Path, FS, Compress, Base64 } from "../deps.ts";
import { getMeta, IMeta, log, getConfig } from "../global.ts";
export default async function publish() {
export default async function publish(options: { dry: boolean }) {
const meta: IMeta = await getMeta();
if (!meta.name) throw new Error("name is not set in meta.json");
@ -10,7 +10,7 @@ export default async function publish() {
throw new Error("files is not set or empty in meta.json");
const tmpDir = await Deno.makeTempDir();
const packedFile = await Deno.makeTempFile();
const packedFile = (await Deno.makeTempFile()) + ".tar";
try {
const walker = FS.walk(".", {
@ -31,9 +31,10 @@ export default async function publish() {
for await (const file of walker) {
await copy(file.path);
log("Adding file:", file.path);
}
log("Compressing file");
log("Compressing files into", packedFile);
await Compress.Tar.compress(tmpDir, packedFile, {
excludeSrc: true,
@ -42,34 +43,38 @@ export default async function publish() {
const url = new URL(getConfig("registry"));
url.pathname = "/api/package/" + meta.name;
log("Uploading new package version");
if (!options.dry) {
log("Uploading new package version");
await fetch(url, {
method: "POST",
body: await Deno.readFile(packedFile),
headers: {
Authorization:
"Basic " +
Base64.encode(
getConfig("username") + ":" + getConfig("password")
),
},
})
.then((res) =>
res.status === 200
? res.json()
: Promise.reject(new Error(res.statusText))
)
.then((res) => {
if (!res.success) {
throw new Error(res.message);
} else {
console.log(Colors.green("Upload successfull"));
}
await fetch(url, {
method: "POST",
body: await Deno.readFile(packedFile),
headers: {
Authorization:
"Basic " +
Base64.encode(
getConfig("username") + ":" + getConfig("password")
),
},
})
.catch((err) => {
console.log(Colors.red("Error: " + err.message));
});
.then((res) =>
res.status === 200
? res.json()
: Promise.reject(new Error(res.statusText))
)
.then((res) => {
if (!res.success) {
throw new Error(res.message);
} else {
console.log(Colors.green("Upload successfull"));
}
})
.catch((err) => {
console.log(Colors.red("Error: " + err.message));
});
} else {
console.log(Colors.yellow("Dry run. Skipping upload"));
}
} finally {
await Deno.remove(tmpDir, { recursive: true });
await Deno.remove(packedFile);

View File

@ -50,6 +50,9 @@ const flags = await new Cliffy.Command()
new Cliffy.Command()
.description("Upload package")
.action(commandWrapper(publishCMD))
.option("-d, --dry [dry:boolean]", "Dry run", {
default: false,
})
)
.command(
"init",

View File

@ -1,12 +1,8 @@
{
"name": "@denreg-cli",
"version": "0.1.9",
"version": "0.1.10",
"description": "CLI for the DenReg package registry",
"author": "Fabian Stamm <dev@fabianstamm.de>",
"contributors": [],
"files": [
"**/*.ts",
"**/*.js",
"README.md"
]
}
"files": ["**/*.ts", "**/*.js", "README.md"]
}