start-file #5

Merged
SethTrowbridge merged 5 commits from start-file into master 2023-07-30 14:29:34 -04:00
10 changed files with 194 additions and 98 deletions
Showing only changes of commit 78230a5672 - Show all commits

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",
"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...");
Deno.exit();
}
return scanUser;
};
const prompt =async(question: string):Promise<string>=>
@ -45,8 +46,7 @@ const prompt =async(question: string):Promise<string>=>
try
{
console.log("Runing deploy!");
const serveScript = import.meta.resolve("./run-serve.tsx");
console.log("Runing deploy!", Deno.mainModule);
let arg = parse(Deno.args);
let env = await Env.load();
@ -66,7 +66,7 @@ try
`--project=${useProject}`,
`--import-map=./deno.json`,
`--token=${useToken}`,
serveScript
Deno.mainModule
],
stdin: "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 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();
@ -72,11 +73,11 @@ export type Configuration = {Start:string, Allow:string, Reset:string, SWCOp
export type ConfigurationArgs = Partial<Configuration>;
let Configuration:Configuration =
{
Start: "",
Start: ">able/app.tsx",
Allow: "*",
Reset: "/clear-cache",
async Extra(inReq, inURL, inExt, inMap, inConfig){},
async Serve(inReq, inURL, inExt, inMap, inConfig){},
Serve: CustomServe,
Remap: (inImports, inConfig)=>
{
return inImports;
@ -258,6 +259,8 @@ export const Configure =(config:ConfigurationArgs)=>
ImportMapReload();
}
export default async()=>
{
await ImportMapReload();
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});
});
}

21
run.tsx
View File

@ -1,5 +1,14 @@
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=>
{
@ -10,7 +19,15 @@ Deno.args.forEach(arg=>
}
});
if(Deno.env.get("dep"))
{
import("./run-deploy.tsx");
}
else
{
if(Deno.env.get("dev"))
{
import("./run-local.tsx");
await import("./run-local.tsx");
}
Serve.default();
}