Add ability to add root folder to meta.json (only affects upload)
This commit is contained in:
parent
13bc1b07cd
commit
f3f6f0d7bc
@ -42,23 +42,27 @@ async function runHooks(hooks: undefined | string | string[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default async function publish(options: { dry: boolean }) {
|
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.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.version) throw new Error("version is not set in meta.json");
|
||||||
if (!meta.files || !Array.isArray(meta.files) || meta.files.length <= 0)
|
if (!meta.files || !Array.isArray(meta.files) || meta.files.length <= 0)
|
||||||
throw new Error("files is not set or empty in meta.json");
|
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 tmpDir = await Deno.makeTempDir();
|
||||||
const packedFile = (await Deno.makeTempFile()) + ".tar";
|
const packedFile = (await Deno.makeTempFile()) + ".tar";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const walker = FS.walk(".", {
|
const walker = FS.walk(meta.root || ".", {
|
||||||
includeDirs: false,
|
includeDirs: false,
|
||||||
includeFiles: true,
|
includeFiles: true,
|
||||||
match: meta.files.map((file) => Path.globToRegExp(file)),
|
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);
|
log("Copying files to package to", tmpDir);
|
||||||
|
|
||||||
const copy = async (path: string) => {
|
const copy = async (path: string, abs?: boolean) => {
|
||||||
const dest = Path.join(tmpDir, path);
|
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.ensureDir(Path.dirname(dest));
|
||||||
await FS.copy(path, dest);
|
await FS.copy(path, dest);
|
||||||
};
|
};
|
||||||
|
|
||||||
await copy("meta.json");
|
await copy("meta.json", true);
|
||||||
|
|
||||||
for await (const file of walker) {
|
for await (const file of walker) {
|
||||||
await copy(file.path);
|
await copy(file.path);
|
||||||
log("Adding file:", file.path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
log("Compressing files into", packedFile);
|
log("Compressing files into", packedFile);
|
||||||
@ -88,9 +93,14 @@ export default async function publish(options: { dry: boolean }) {
|
|||||||
const url = new URL(getConfig("registry"));
|
const url = new URL(getConfig("registry"));
|
||||||
url.pathname = "/api/package/" + meta.name;
|
url.pathname = "/api/package/" + meta.name;
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
"Pushing version",
|
||||||
|
Colors.blue(meta.version),
|
||||||
|
"to repository"
|
||||||
|
);
|
||||||
|
|
||||||
if (!options.dry) {
|
if (!options.dry) {
|
||||||
log("Uploading new package version");
|
log("Uploading new package version");
|
||||||
|
|
||||||
await fetch(url, {
|
await fetch(url, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: await Deno.readFile(packedFile),
|
body: await Deno.readFile(packedFile),
|
||||||
|
@ -9,6 +9,7 @@ export interface IMeta {
|
|||||||
contributors?: string[];
|
contributors?: string[];
|
||||||
deprecated?: boolean;
|
deprecated?: boolean;
|
||||||
files: string[];
|
files: string[];
|
||||||
|
root?: string;
|
||||||
hooks?: {
|
hooks?: {
|
||||||
prepublish?: string | string[];
|
prepublish?: string | string[];
|
||||||
postpublish?: string | string[];
|
postpublish?: string | string[];
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@denreg-cli",
|
"name": "@denreg-cli",
|
||||||
"version": "0.2.6",
|
"version": "0.2.7",
|
||||||
"description": "CLI for the DenReg package registry",
|
"description": "CLI for the DenReg package registry",
|
||||||
"author": "Fabian Stamm <dev@fabianstamm.de>",
|
"author": "Fabian Stamm <dev@fabianstamm.de>",
|
||||||
"contributors": [],
|
"contributors": [],
|
||||||
|
@ -1 +1 @@
|
|||||||
export const version = "0.2.6"
|
export const version = "0.2.7"
|
Loading…
Reference in New Issue
Block a user