good font

tag create workflow
This commit is contained in:
2024-10-19 21:18:35 -06:00
parent f6ce166b11
commit 3d9b877661
13 changed files with 307 additions and 23 deletions

View File

@@ -2,6 +2,8 @@ import { BearMetalStore } from "@bearmetal/store";
import { getPackVersion } from "../util/packVersion.ts";
import type { Router } from "../router.ts";
import { getTagDir } from "./getTagDir.ts";
import { ensureDir } from "@std/fs/ensure-dir";
import { ensureFile } from "@std/fs/ensure-file";
export const createTagRoutes = (router: Router) => {
router.route("/api/pack/:namespace/tags")
@@ -25,7 +27,108 @@ export const createTagRoutes = (router: Router) => {
);
return new Response(JSON.stringify(tags), { status: 200 });
} catch {
return new Response("no tags found", { status: 404 });
return new Response("[]", { status: 200 });
}
})
.post(async (req, ctx) => {
if (!ctx.params.namespace) {
return new Response("somehow hit the tags endpoint without namespace", {
status: 500,
});
}
using store = new BearMetalStore();
const version = getPackVersion(store);
const tagDir = await getTagDir(store, ctx.params.namespace, version);
await ensureDir(tagDir);
const { tag, type } = await req.json();
if (!tag || !type) {
return new Response("no tag name provided", { status: 400 });
}
const tagPath = `${tagDir}/${type}/${tag}.json`;
await ensureFile(tagPath);
return new Response(tag, { status: 200 });
});
router.route("/api/pack/:namespace/tags/:type-:tag")
.get(async (_, ctx) => {
if (!ctx.params.namespace) {
return new Response("somehow hit the tags endpoint without namespace", {
status: 500,
});
}
using store = new BearMetalStore();
const version = getPackVersion(store);
const tagDir = await getTagDir(store, ctx.params.namespace, version);
const tag = ctx.params.tag;
if (!tag) {
return new Response("no tag name provided", { status: 400 });
}
try {
const tagFile = Deno.readTextFileSync(tagDir + "/" + tag + ".json");
return new Response(tagFile, { status: 200 });
} catch {
return new Response("no tag found", { status: 404 });
}
})
.put(async (req, ctx) => {
if (!ctx.params.namespace) {
return new Response("somehow hit the tags endpoint without namespace", {
status: 500,
});
}
using store = new BearMetalStore();
const version = getPackVersion(store);
const tagDir = await getTagDir(store, ctx.params.namespace, version);
const tag = ctx.params.tag;
const type = ctx.params.type;
if (!tag || !type) {
return new Response("no tag name provided", { status: 400 });
}
const tagPath = `${tagDir}/${type}/${tag}.json`;
await ensureFile(tagPath);
await Deno.writeTextFile(tagPath, await req.text());
return new Response(tag, { status: 200 });
})
.delete(async (_, ctx) => {
if (!ctx.params.namespace) {
return new Response("somehow hit the tags endpoint without namespace", {
status: 500,
});
}
using store = new BearMetalStore();
const version = getPackVersion(store);
const tagDir = await getTagDir(store, ctx.params.namespace, version);
const tag = ctx.params.tag;
if (!tag) {
return new Response("no tag name provided", { status: 400 });
}
try {
await Deno.remove(tagDir + "/" + tag + ".json");
return new Response(tag, { status: 200 });
} catch {
return new Response("no tag found", { status: 404 });
}
});
};

View File

@@ -19,8 +19,6 @@ export async function getDirName(version: number, path: string) {
const singular = makeSingular(path);
const plural = makePlural(path);
console.log("versionData", versionData);
return versionData && versionData.schema.data["<namespace>"][singular] ||
versionData.schema.data["<namespace>"][plural];
}