diff --git a/registry/Dockerfile b/registry/Dockerfile index b17c172..da4ff70 100644 --- a/registry/Dockerfile +++ b/registry/Dockerfile @@ -29,5 +29,5 @@ ADD src /app/src RUN /usr/bin/deno cache --unstable src/registry.ts -VOLUME [ "/data" ] +VOLUME [ "/app/data" ] ENTRYPOINT [ "/usr/bin/deno", "run", "-A", "--unstable", "/app/src/registry.ts" ] diff --git a/registry/src/deps.ts b/registry/src/deps.ts index f630d34..972a98d 100644 --- a/registry/src/deps.ts +++ b/registry/src/deps.ts @@ -15,4 +15,11 @@ export * as Compress from "https://git.stamm.me/Deno/DenReg/raw/branch/master/ta import DS from "https://raw.githubusercontent.com/hibas123/dndb/master/mod.ts"; +/// +export { + React, + jsx, + Fragment, +} from "https://deno.hibas123.de/raw/@denreg-jsx/mod.ts"; + export const Datastore = DS; diff --git a/registry/src/http.ts b/registry/src/http.ts index e6b9023..5caa4e4 100644 --- a/registry/src/http.ts +++ b/registry/src/http.ts @@ -1,3 +1,4 @@ +/// import { ABC, CorsMW, LoggerMW } from "./deps.ts"; import config from "./config.ts"; @@ -13,6 +14,14 @@ api(app.group("api")); import raw from "./http/raw.ts"; raw(app.group("raw")); +import view from "./http/views.ts"; +view(app.group("/")); + +import render from "./renderer.tsx"; +app.renderer = { + render: render, +}; + app.start({ port }); console.log("Running server at http://0.0.0.0:" + port); console.log("Open at http://127.0.0.1:" + port); diff --git a/registry/src/http/views.ts b/registry/src/http/views.ts new file mode 100644 index 0000000..45a2860 --- /dev/null +++ b/registry/src/http/views.ts @@ -0,0 +1,16 @@ +import { ABC } from "../deps.ts"; +import { basicauth } from "../utils.ts"; + +export default function views(g: ABC.Group) { + g.get( + "/", + async (ctx) => { + return ctx.render("index"); + // const render = await IndexView(); + // console.log(render); + // ctx.response.body = render; + // ctx.response.status = 200; + }, + basicauth("views") + ); +} diff --git a/registry/src/renderer.tsx b/registry/src/renderer.tsx new file mode 100644 index 0000000..190a714 --- /dev/null +++ b/registry/src/renderer.tsx @@ -0,0 +1,37 @@ +/// +import { React, jsx } from "./deps.ts"; + +class StringReader implements Deno.Reader { + private data: Uint8Array; + private offset = 0; + constructor(text: string) { + this.data = new TextEncoder().encode(text); + } + + async read(p: Uint8Array): Promise { + if (this.offset >= this.data.byteLength) return null; + + const forLength = Math.min(p.length, this.data.length - this.offset); + + for (let i = 0; i < forLength; i++) { + p[i] = this.data[i + this.offset]; + } + + this.offset += forLength; + + return forLength; + } +} + +export default async function render( + name: string, + data: any +): Promise { + const component: { + default: () => JSX.IntrinsicElements | Promise; + } = await import(`./views/${name}.tsx`); + + const res = await ().render(); + console.log(res); + return new StringReader(res as string); +} diff --git a/registry/src/types/jsx.d.ts b/registry/src/types/jsx.d.ts new file mode 100644 index 0000000..abc0e8b --- /dev/null +++ b/registry/src/types/jsx.d.ts @@ -0,0 +1,5 @@ +declare namespace JSX { + interface IntrinsicElements { + [elemName: string]: any; + } +} \ No newline at end of file diff --git a/registry/src/views/_base.tsx b/registry/src/views/_base.tsx new file mode 100644 index 0000000..508c68c --- /dev/null +++ b/registry/src/views/_base.tsx @@ -0,0 +1,16 @@ +/// +import { React } from "../deps.ts"; + +export default function Base(d: any, children: any[]) { + return ( + + + + + {children} + + ); +} diff --git a/registry/src/views/index.tsx b/registry/src/views/index.tsx new file mode 100644 index 0000000..3f632ac --- /dev/null +++ b/registry/src/views/index.tsx @@ -0,0 +1,33 @@ +/// +import { React, Fragment } from "../deps.ts"; +import Base from "./_base.tsx"; +import DB, { IPackage } from "../db.ts"; + +function Package({ pkg }: { pkg: IPackage }) { + const { name, versions } = pkg; + + return ( +
+
{name}
+
    + {versions.map((version) => ( +
  • {version}
  • + ))} +
+
+ ); +} + +export default async function index() { + const packages = await DB.find({}); + + return ( + +
+ {packages.map((pkg) => ( + + ))} +
+ + ); +}