allow for code or config setup

This commit is contained in:
Seth Trowbridge 2023-07-30 13:04:26 -04:00
parent 6134b7be34
commit 78230a5672
10 changed files with 194 additions and 98 deletions

View File

View File

19
example-config/deno.json Normal file
View File

@ -0,0 +1,19 @@
{
"imports":
{
"react": "https://esm.sh/preact@10.15.1/compat",
">able/": "http://localhost:4507/",
">able/app.tsx": "./app.tsx"
},
"tasks":
{
"serve": "deno run -A --no-lock --config=deno.json --reload=http://localhost:4507 http://localhost:4507/run.tsx",
"local": "deno run -A --no-lock --config=deno.json --reload=http://localhost:4507 http://localhost:4507/run.tsx --dev",
"debug": "deno run -A --no-lock --config=deno.json --reload=http://localhost:4507 --inspect-wait http://localhost:4507/run.tsx",
"cloud": "deno run -A --no-lock --config=deno.json --reload=http://localhost:4507 http://localhost:4507/run.tsx --dep"
},
"compilerOptions":
{
"lib": ["deno.window", "dom"]
}
}

56
example-script/app.tsx Normal file
View File

@ -0,0 +1,56 @@
import { Router, Switch, Case } from ">able/iso-elements.tsx";
import React from "react";
const CTXString = React.createContext("lol");
type StateBinding<T> = [get:T, set:React.StateUpdater<T>];
const CTXState = React.createContext(null) as React.Context<StateBinding<number>|null>;
const Outer =(props:{children:React.JSX.Element})=>
{
const binding = React.useState(11);
return <CTXState.Provider value={binding}>
{props.children}
</CTXState.Provider>
};
const Inner =()=>
{
const [stateGet, stateSet] = React.useContext(CTXState) || ["default", ()=>{}];
return <button onClick={e=>stateSet((old)=>old+1)}>count: {stateGet} :)</button>
};
type Store = {name:string, age:number}
const reducer =(inState:Store, inAction:number)=>
{
return {...inState, age:inState.age+inAction};
}
const builder =(inState:Store):Store=>
{
inState.age = 100;
return inState;
}
export default ()=>
{
const [Store, Dispatch] = React.useReducer(reducer, {name:"seth", age:24} as Store, builder)
return <CTXString.Provider value="intradestink">
<Router.Provider>
<div class="my-4 font-sans">
<h1 class="font-black text-xl text-red-500">Title</h1>
<h2 class="font-black text-blue-500 p-4">subtitle</h2>
<p>
<button onClick={e=>Dispatch(1)}>{Store.name}|{Store.age}?</button>
</p>
</div>
<Outer>
<Inner/>
</Outer>
<Outer>
<Inner/>
</Outer>
</Router.Provider>
</CTXString.Provider>;
}

View File

@ -9,6 +9,7 @@
{ {
"local": "deno run -A --no-lock --reload=http://localhost:4507 run__.tsx --dev", "local": "deno run -A --no-lock --reload=http://localhost:4507 run__.tsx --dev",
"serve": "deno run -A --no-lock --reload=http://localhost:4507 run__.tsx", "serve": "deno run -A --no-lock --reload=http://localhost:4507 run__.tsx",
"debug": "deno run -A --no-lock --reload=http://localhost:4507 --inspect-wait run__.tsx" "debug": "deno run -A --no-lock --reload=http://localhost:4507 --inspect-wait run__.tsx",
"cloud": "deno run -A --no-lock --reload=http://localhost:4507 run__.tsx --dep"
} }
} }

View File

@ -30,6 +30,7 @@ const collect =async(inKey:string, inArg:Record<string, string>, inEnv:Record<st
console.log("Exiting..."); console.log("Exiting...");
Deno.exit(); Deno.exit();
} }
return scanUser;
}; };
const prompt =async(question: string):Promise<string>=> const prompt =async(question: string):Promise<string>=>
@ -45,8 +46,7 @@ const prompt =async(question: string):Promise<string>=>
try try
{ {
console.log("Runing deploy!"); console.log("Runing deploy!", Deno.mainModule);
const serveScript = import.meta.resolve("./run-serve.tsx");
let arg = parse(Deno.args); let arg = parse(Deno.args);
let env = await Env.load(); let env = await Env.load();
@ -66,7 +66,7 @@ try
`--project=${useProject}`, `--project=${useProject}`,
`--import-map=./deno.json`, `--import-map=./deno.json`,
`--token=${useToken}`, `--token=${useToken}`,
serveScript Deno.mainModule
], ],
stdin: "piped", stdin: "piped",
stdout: "piped" stdout: "piped"

View File

@ -1,6 +1,7 @@
import * as MIME from "https://deno.land/std@0.180.0/media_types/mod.ts"; import * as MIME from "https://deno.land/std@0.180.0/media_types/mod.ts";
import * as SWCW from "https://esm.sh/@swc/wasm-web@1.3.62"; import * as SWCW from "https://esm.sh/@swc/wasm-web@1.3.62";
import CustomServe from ">able/api.tsx";
export const Root = new URL(`file://${Deno.cwd().replaceAll("\\", "/")}`).toString(); export const Root = new URL(`file://${Deno.cwd().replaceAll("\\", "/")}`).toString();
@ -72,11 +73,11 @@ export type Configuration = {Start:string, Allow:string, Reset:string, SWCOp
export type ConfigurationArgs = Partial<Configuration>; export type ConfigurationArgs = Partial<Configuration>;
let Configuration:Configuration = let Configuration:Configuration =
{ {
Start: "", Start: ">able/app.tsx",
Allow: "*", Allow: "*",
Reset: "/clear-cache", Reset: "/clear-cache",
async Extra(inReq, inURL, inExt, inMap, inConfig){}, async Extra(inReq, inURL, inExt, inMap, inConfig){},
async Serve(inReq, inURL, inExt, inMap, inConfig){}, Serve: CustomServe,
Remap: (inImports, inConfig)=> Remap: (inImports, inConfig)=>
{ {
return inImports; return inImports;
@ -258,6 +259,8 @@ export const Configure =(config:ConfigurationArgs)=>
ImportMapReload(); ImportMapReload();
} }
export default async()=>
{
await ImportMapReload(); await ImportMapReload();
try try
{ {
@ -358,4 +361,4 @@ const server = Deno.serve({port:parseInt(Deno.env.get("port")||"8000")}, async(r
return new Response(`{"error":"unmatched route", "path":"${url.pathname}"}`, {status:404, headers}); return new Response(`{"error":"unmatched route", "path":"${url.pathname}"}`, {status:404, headers});
}); });
}

21
run.tsx
View File

@ -1,5 +1,14 @@
import * as Serve from "./run-serve.tsx"; import * as Serve from "./run-serve.tsx";
export default Serve.Configure;
export default function(config:Serve.ConfigurationArgs)
{
if(Deno.env.get("deploy"))
{
return;
}
Serve.Configure(config)
Serve.default();
}
Deno.args.forEach(arg=> Deno.args.forEach(arg=>
{ {
@ -10,7 +19,15 @@ Deno.args.forEach(arg=>
} }
}); });
if(Deno.env.get("dep"))
{
import("./run-deploy.tsx");
}
else
{
if(Deno.env.get("dev")) if(Deno.env.get("dev"))
{ {
import("./run-local.tsx"); await import("./run-local.tsx");
}
Serve.default();
} }