Compare commits

...

2 Commits

Author SHA1 Message Date
Fabian Stamm
6fe3ddbd37 Many improvements
Some checks failed
continuous-integration/drone/push Build is failing
2021-01-11 15:06:02 +01:00
Fabian Stamm
79bcef0698 Remove unused console output 2021-01-11 15:05:03 +01:00
18 changed files with 91 additions and 66 deletions

View File

@ -1,9 +1,14 @@
{
"name": "@denreg-jsx",
"version": "0.1.0",
"description": "Denreg JSX renderer",
"author": "Fabian Stamm <dev@fabianstamm.de>",
"contributors": [],
"deprecated": false,
"files": ["**/*.ts", "**/*.js", "tsconfig.json", "README.md"]
"name": "@denreg-jsx",
"version": "0.1.1",
"description": "Denreg JSX renderer",
"author": "Fabian Stamm <dev@fabianstamm.de>",
"contributors": [],
"deprecated": false,
"files": [
"**/*.ts",
"**/*.js",
"tsconfig.json",
"README.md"
]
}

View File

@ -83,7 +83,6 @@ async function renderHTML(element: Element) {
if (typeof element.component !== "string")
throw new Error("Internal consistency error");
console.log("Element:", element.component);
let props = "";
for (const key in element.props) {
@ -101,7 +100,6 @@ async function renderHTML(element: Element) {
inner = element.props["innerHTML"];
} else {
const children = cleanChildren(element.children);
if (tag == "body") console.log(element.children, children);
inner = (
await Promise.all(children.map((child) => renderSSR(child)))
).join("");
@ -114,7 +112,6 @@ async function renderCustom(element: Element) {
if (typeof element.component === "string")
throw new Error("Internal consistency error");
console.log("Component:", element.component);
const res = await Promise.resolve(
element.component(
{

View File

@ -8,4 +8,4 @@ ADD public /app/public
RUN /usr/bin/deno cache --unstable src/registry.ts
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.web) config.web = {};
if (!config.general) config.general = {};
const env = Deno.env.toObject();
@ -47,11 +48,17 @@ for (const key in env) {
case "WEB_TRACKING":
config.web.tracking = env[key];
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));
export default config;

View File

@ -1,40 +1,28 @@
export * as S3 from "https://deno.land/x/s3@0.2.0/mod.ts";
export { S3Error } from "https://deno.land/x/s3@0.2.0/src/error.ts";
// @deno-types="./types/hotfix.d.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 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 Ini from "https://deno.hibas123.de/raw/ini@0.0.3/mod.ts";
export * as Path from "https://deno.land/std@0.74.0/path/mod.ts";
export * as FS from "https://deno.land/std@0.74.0/fs/mod.ts";
export * as Base64 from "https://deno.land/std@0.74.0/encoding/base64.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 ABC from "https://deno.land/x/abc@v1.2.4/mod.ts";
export * as CorsMW from "https://deno.land/x/abc@v1.2.4/middleware/cors.ts";
export * as LoggerMW from "https://deno.land/x/abc@v1.2.4/middleware/logger.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 { 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";
import DS from "https://raw.githubusercontent.com/hibas123/dndb/master/mod.ts";
/// <reference path="./types/jsx.d.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 * as Pico from "../../jsx/mod.ts";
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 config from "./config.ts";

View File

@ -1,8 +1,12 @@
/// <reference path="./types/jsx.d.ts" />
import { React, jsx } from "./deps.ts";
// / <reference path="./types/jsx.d.ts" />
import { Pico } from "./deps.ts";
import config from "./config.ts";
const React = {
createElement: Pico.h.bind(Pico),
};
class StringReader implements Deno.Reader {
private data: Uint8Array;
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(
name: string,
data: any
): Promise<Deno.Reader> {
const component: {
default: () => JSX.IntrinsicElements | Promise<JSX.IntrinsicElements>;
} = await import(`./views/${name}.tsx`);
const Component = await loadComponent(name);
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 { React } from "../deps.ts";
import { Pico } from "../deps.ts";
import config from "../config.ts";
const styles = new TextDecoder().decode(

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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