Many improvements
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Fabian Stamm 2021-01-11 15:06:02 +01:00
parent 79bcef0698
commit 6fe3ddbd37
16 changed files with 79 additions and 56 deletions

View File

@ -8,4 +8,4 @@ ADD public /app/public
RUN /usr/bin/deno cache --unstable src/registry.ts RUN /usr/bin/deno cache --unstable src/registry.ts
VOLUME [ "/app/data" ] VOLUME [ "/app/data" ]
ENTRYPOINT [ "/usr/bin/deno", "run", "-A", "--unstable", "/app/src/registry.ts" ] ENTRYPOINT [ "/usr/bin/deno", "run", "-A", "--unstable", "--config", "tsconfig.json", "/app/src/registry.ts" ]

View File

@ -15,6 +15,7 @@ const config =
if (!config.user) config.user = {}; if (!config.user) config.user = {};
if (!config.web) config.web = {}; if (!config.web) config.web = {};
if (!config.general) config.general = {};
const env = Deno.env.toObject(); const env = Deno.env.toObject();
@ -47,11 +48,17 @@ for (const key in env) {
case "WEB_TRACKING": case "WEB_TRACKING":
config.web.tracking = env[key]; config.web.tracking = env[key];
break; break;
case "GENERAL_DEV":
config.general.dev = env[key] === "true";
} }
} }
} }
} }
if (config.general.dev) {
console.warn("Dev mode active!!!");
}
console.log("Known users:", Object.keys(config.user)); console.log("Known users:", Object.keys(config.user));
export default config; export default config;

View File

@ -1,40 +1,28 @@
export * as S3 from "https://deno.land/x/s3@0.2.0/mod.ts"; // @deno-types="./types/hotfix.d.ts"
export { S3Error } from "https://deno.land/x/s3@0.2.0/src/error.ts";
export * as Ini from "https://deno.hibas123.de/raw/ini@0.0.1/mod.ts"; export * as S3 from "https://deno.land/x/s3@0.3.0/mod.ts";
export { S3Error } from "https://deno.land/x/s3@0.3.0/src/error.ts";
export * as ABC from "https://deno.land/x/abc@v1/mod.ts"; export * as Ini from "https://deno.hibas123.de/raw/ini@0.0.3/mod.ts";
export * as CorsMW from "https://deno.land/x/abc@v1/middleware/cors.ts";
export * as LoggerMW from "https://deno.land/x/abc@v1/middleware/logger.ts";
export * as Path from "https://deno.land/std@0.74.0/path/mod.ts"; export * as ABC from "https://deno.land/x/abc@v1.2.4/mod.ts";
export * as FS from "https://deno.land/std@0.74.0/fs/mod.ts"; export * as CorsMW from "https://deno.land/x/abc@v1.2.4/middleware/cors.ts";
export * as Base64 from "https://deno.land/std@0.74.0/encoding/base64.ts"; export * as LoggerMW from "https://deno.land/x/abc@v1.2.4/middleware/logger.ts";
export * as Hash from "https://deno.land/std@0.74.0/hash/mod.ts";
export * as Colors from "https://deno.land/std@0.74.0/fmt/colors.ts"; export * as Path from "https://deno.land/std@0.83.0/path/mod.ts";
export * as FS from "https://deno.land/std@0.83.0/fs/mod.ts";
export * as Base64 from "https://deno.land/std@0.83.0/encoding/base64.ts";
export * as Hash from "https://deno.land/std@0.83.0/hash/mod.ts";
export * as Colors from "https://deno.land/std@0.83.0/fmt/colors.ts";
export * as Compress from "https://git.stamm.me/Deno/DenReg/raw/branch/master/tar/mod.ts"; export * as Compress from "https://git.stamm.me/Deno/DenReg/raw/branch/master/tar/mod.ts";
export { default as Prism } from "https://cdn.skypack.dev/prismjs"; export { default as Prism } from "https://cdn.skypack.dev/prismjs";
// export { Marked } from "https://deno.land/x/markdown/mod.ts";
// export { Marked } from "../../markdown/mod.ts";
export { Marked } from "https://deno.hibas123.de/raw/markdown/mod.ts"; export { Marked } from "https://deno.hibas123.de/raw/markdown/mod.ts";
import DS from "https://raw.githubusercontent.com/hibas123/dndb/master/mod.ts"; import DS from "https://raw.githubusercontent.com/hibas123/dndb/master/mod.ts";
/// <reference path="./types/jsx.d.ts" /> export * as Pico from "../../jsx/mod.ts";
export {
React,
jsx,
Fragment,
} from "https://deno.hibas123.de/raw/jsx-html/mod.ts";
// export {
// React,
// jsx,
// Fragment,
// } from "https://raw.githubusercontent.com/apiel/jsx-html/master/mod.ts";
export const Datastore = DS; export const Datastore = DS;

View File

@ -1,4 +1,4 @@
/// <reference path="./types/jsx.d.ts" /> // /// <reference path="./types/jsx.d.ts" />
import { ABC, CorsMW, LoggerMW, Path } from "./deps.ts"; import { ABC, CorsMW, LoggerMW, Path } from "./deps.ts";
import config from "./config.ts"; import config from "./config.ts";

View File

@ -1,8 +1,12 @@
/// <reference path="./types/jsx.d.ts" /> // / <reference path="./types/jsx.d.ts" />
import { React, jsx } from "./deps.ts"; import { Pico } from "./deps.ts";
import config from "./config.ts"; import config from "./config.ts";
const React = {
createElement: Pico.h.bind(Pico),
};
class StringReader implements Deno.Reader { class StringReader implements Deno.Reader {
private data: Uint8Array; private data: Uint8Array;
private offset = 0; private offset = 0;
@ -25,15 +29,37 @@ class StringReader implements Deno.Reader {
} }
} }
type ELM = any;
type Component = () => ELM;
const componentCache = new Map<string, Component>();
async function loadComponent(name: string) {
let mod = componentCache.get(name);
if (!mod || config.general.dev) {
mod = (await import(`./views/${name}.tsx`)).default;
if (!mod) throw new Error("Invalid component " + name);
componentCache.set(name, mod);
}
return mod;
}
const preLoad = ["index", "package", "browse_folder", "browse_file"];
preLoad.forEach((page) =>
loadComponent(page).catch((err) => console.error("Error preloading", page))
);
export default async function render( export default async function render(
name: string, name: string,
data: any data: any
): Promise<Deno.Reader> { ): Promise<Deno.Reader> {
const component: { const Component = await loadComponent(name);
default: () => JSX.IntrinsicElements | Promise<JSX.IntrinsicElements>;
} = await import(`./views/${name}.tsx`);
const res = await (<component.default {...data} />).render(); //@ts-ignore
const res = await Pico.renderSSR(<Component {...data} />);
return new StringReader("<!DOCTYPE html>\n" + (res as string)); return new StringReader("<!DOCTYPE html>\n" + res);
} }

4
registry/src/types/hotfix.d.ts vendored Normal file
View File

@ -0,0 +1,4 @@
// fixes an issue in std@0.80.0
interface ReadableStream<R> {
getIterator(): any;
}

View File

@ -1,5 +0,0 @@
declare namespace JSX {
interface IntrinsicElements {
[elemName: string]: any;
}
}

View File

@ -1,5 +1,4 @@
/// <reference path="../types/jsx.d.ts" /> import { Pico } from "../deps.ts";
import { React } from "../deps.ts";
import config from "../config.ts"; import config from "../config.ts";
const styles = new TextDecoder().decode( const styles = new TextDecoder().decode(

View File

@ -1,5 +1,4 @@
/// <reference path="../types/jsx.d.ts" /> import { Pico, Marked } from "../deps.ts";
import { React, Marked } from "../deps.ts";
import type { IPackage } from "../db.ts"; import type { IPackage } from "../db.ts";
import { sortVersions } from "../utils.ts"; import { sortVersions } from "../utils.ts";

View File

@ -1,5 +1,4 @@
/// <reference path="../types/jsx.d.ts" /> import { Pico } from "../deps.ts";
import { React, Fragment } from "../deps.ts";
export function Main(a: any, children: any) { export function Main(a: any, children: any) {
return ( return (

View File

@ -1,5 +1,5 @@
/// <reference path="../types/jsx.d.ts" /> // /// <reference path="../types/jsx.d.ts" />
import { React, Fragment, Marked } from "../deps.ts"; import { Pico, Marked } from "../deps.ts";
import type { IPackage } from "../db.ts"; import type { IPackage } from "../db.ts";
export default async function index({ export default async function index({

View File

@ -1,5 +1,4 @@
/// <reference path="../types/jsx.d.ts" /> import { Pico } from "../deps.ts";
import { React } from "../deps.ts";
import Base from "./_base.tsx"; import Base from "./_base.tsx";
import type { IPackage } from "../db.ts"; import type { IPackage } from "../db.ts";

View File

@ -1,5 +1,4 @@
/// <reference path="../types/jsx.d.ts" /> import { Pico } from "../deps.ts";
import { React } from "../deps.ts";
import Base from "./_base.tsx"; import Base from "./_base.tsx";
import type { IPackage } from "../db.ts"; import type { IPackage } from "../db.ts";

View File

@ -1,5 +1,4 @@
/// <reference path="../types/jsx.d.ts" /> import { Pico } from "../deps.ts";
import { React, Fragment } from "../deps.ts";
import Base from "./_base.tsx"; import Base from "./_base.tsx";
import type { IPackage } from "../db.ts"; import type { IPackage } from "../db.ts";
import { sortVersions } from "../utils.ts"; import { sortVersions } from "../utils.ts";

View File

@ -1,5 +1,4 @@
/// <reference path="../types/jsx.d.ts" /> import { Pico, Marked } from "../deps.ts";
import { React, Fragment, Marked } from "../deps.ts";
import Base from "./_base.tsx"; import Base from "./_base.tsx";
import type { IPackage } from "../db.ts"; import type { IPackage } from "../db.ts";
import { sortVersions, getFile, getAbsolutePackageVersion } from "../utils.ts"; import { sortVersions, getFile, getAbsolutePackageVersion } from "../utils.ts";

10
registry/tsconfig.json Normal file
View File

@ -0,0 +1,10 @@
{
"compilerOptions": {
"lib": ["dom", "dom.iterable", "esnext", "deno.ns", "deno.unstable"],
"jsx": "react",
"jsxFactory": "Pico.h",
"jsxFragmentFactory": "Pico.Fragment",
"noImplicitAny": true,
"strictPropertyInitialization": false
}
}