Compare commits

...

4 Commits

Author SHA1 Message Date
21ec8a759e add h 2023-04-30 17:24:16 -04:00
ca892eed6a remove flash server 2023-04-30 16:45:35 -04:00
3feb8d3b6b remove app path inference 2023-04-30 16:24:43 -04:00
35592bb183 more logs 2023-04-30 15:57:12 -04:00
4 changed files with 36 additions and 26 deletions

View File

@ -1,13 +1,7 @@
{
"compilerOptions": {"lib": ["deno.window", "dom"]},
"imports":
{
"react": "https://esm.sh/stable/preact@10.13.2/compat",
"preact": "https://esm.sh/stable/preact@10.13.2/",
"@deep/": "./deep/",
"@eno/iso": "http://localhost:4507/lib/iso.tsx"
},
"importMap": "./deno.map.json",
"tasks": {
"dev": "deno run -A --unstable --reload=http://localhost:4507/ --no-lock app.tsx"
"dev": "deno run -A --unstable --reload=http://localhost:4507/ --no-lock app.tsx --dev"
}
}

10
example/deno.map.json Normal file
View File

@ -0,0 +1,10 @@
{
"imports":
{
"react": "https://esm.sh/stable/preact@10.13.2/compat",
"preact": "https://esm.sh/stable/preact@10.13.2/",
"@deep/": "./deep/",
"@eno/iso": "http://localhost:4507/lib/iso.tsx",
"@eno/app": "./app.tsx"
}
}

View File

@ -1,6 +1,6 @@
import TWPreTail from "https://esm.sh/v115/@twind/preset-tailwind@1.1.4/es2022/preset-tailwind.mjs";
import TWPreAuto from "https://esm.sh/v115/@twind/preset-autoprefix@1.0.7/es2022/preset-autoprefix.mjs";
import React from "react";
import React, {createElement as h} from "react";
import { Boot as _Boot } from "../server.tsx";
export const CSS = {

View File

@ -2,13 +2,23 @@ import * as ESBuild from 'https://deno.land/x/esbuild@v0.17.4/mod.js';
import * as MIME from "https://deno.land/std@0.180.0/media_types/mod.ts";
import { debounce } from "https://deno.land/std@0.151.0/async/debounce.ts";
import { parse as JSONC} from "https://deno.land/std@0.185.0/jsonc/mod.ts";
import { toFileUrl } from "https://deno.land/std@0.185.0/path/mod.ts";
import * as HTTP from "https://deno.land/std@0.185.0/http/server.ts"
import SSR from "https://esm.sh/v113/preact-render-to-string@6.0.2";
import Prepass from "https://esm.sh/preact-ssr-prepass@1.2.0";
import * as Twind from "https://esm.sh/@twind/core@1.1.3";
import React from "react";
import React, {createElement as h} from "react";
import * as Iso from "@eno/iso";
/**
* things you cant do on deno deploy:
* imports inside deno.json
* dynamic imports
* Deno.mainModule
* Deno.serve
* unspecified h
* ESBuild
*/
/**
* Setup a transpiler.
* @param inDevMode When true, starts a file-watcher
@ -65,7 +75,7 @@ function Transpiler(inDevMode:boolean)
const Sockets:Set<WebSocket> = new Set();
const SocketsBroadcast =(inData:string)=>{ for (const socket of Sockets){ socket.send(inData); } }
const SocketsHandler = inDevMode ? (_req:Request)=>
const SocketsHandler = inDevMode ? (_req:Request):false|Response=>
{
if(_req.headers.get("upgrade") == "websocket")
{
@ -86,7 +96,7 @@ function Transpiler(inDevMode:boolean)
return false;
}
:
()=>false;
():false=>false;
const watcher =async()=>
{
@ -244,7 +254,9 @@ const Path = {
};
console.log(Path);
console.log(`Dev Mode: ${DevMode}`);
console.log(`Args seen: `, Deno.env.toObject);
console.log(`import.meta.url:`, import.meta.url);
console.log(`Deno.cwd():`, Deno.cwd());
console.log(`Deno.mainModule:`, Deno.mainModule);
let Booted = false;
@ -254,19 +266,13 @@ export function Boot(inApp:React.FunctionComponent, inCSS?:object)
if(Booted){return;}
Booted = true;
const pathInit = Deno.mainModule;
const pathProj = toFileUrl(Deno.cwd());
//@ts-ignore
TwindInst = Twind.install({...Iso.CSS, ...inCSS||{}});
const App = inApp;
Path.AppDir = pathInit.split(pathProj.toString())[1];
Server(App, Path.AppDir, TwindInst);
Server(inApp, TwindInst);
}
async function Server(App:React.FunctionComponent, AppPath:string, TwindInst:Twind.Twind)
async function Server(App:React.FunctionComponent, TwindInst:Twind.Twind)
{
const {Transpileable, TranspileURL, SocketsHandler} = Transpiler(DevMode);
const {Imports, Error} = await Configure(DevMode, Path.LibDir);
@ -276,7 +282,7 @@ async function Server(App:React.FunctionComponent, AppPath:string, TwindInst:Twi
}
else if(App && TwindInst)
{
Deno.serve({ port: Deno.env.get("port")||3000 }, async(_req:Request) =>
HTTP.serve(async(_req:Request) =>
{
const url:URL = new URL(_req.url);
const pathParts = url.pathname.substring(1, url.pathname.endsWith("/") ? url.pathname.length-1 : url.pathname.length).split("/");
@ -284,7 +290,7 @@ async function Server(App:React.FunctionComponent, AppPath:string, TwindInst:Twi
const pathExt:string|undefined = pathLast?.split(".")[1];
const resp = SocketsHandler(_req);
if(resp){ return resp; }
if(resp){ return resp;}
console.log(url.pathname);
@ -384,7 +390,7 @@ async function Server(App:React.FunctionComponent, AppPath:string, TwindInst:Twi
import {Fetch} from "@eno/iso";
Fetch.Seed(${JSON.stringify(seed)});
import "${AppPath}";
import "@eno/app";
</script>
</body>
</html>`;
@ -397,6 +403,6 @@ async function Server(App:React.FunctionComponent, AppPath:string, TwindInst:Twi
console.log(error);
return new Response(error, {status:404});
}
});
}, { port: parseInt(Deno.env.get("port")||"3000" )});
}
}