From 6134b7be34a6296223740a69c282a2475b9c9df6 Mon Sep 17 00:00:00 2001 From: Seth Trowbridge Date: Sun, 30 Jul 2023 09:16:17 -0400 Subject: [PATCH 1/5] switch to code configuration --- deno.json | 10 +++++----- deno.lock | 28 ++++++++++++++++++++++++++++ example/.env | 1 - example/api.tsx | 4 ---- example/app.tsx | 2 +- example/deno.json | 11 ++++------- example/run__.tsx | 9 +++++++++ run-browser.tsx | 7 +++++++ run-local.tsx | 2 +- run-serve.tsx | 45 +++++++++++---------------------------------- run.tsx | 16 ++++++++++++++++ 11 files changed, 82 insertions(+), 53 deletions(-) create mode 100644 deno.lock delete mode 100644 example/.env delete mode 100644 example/api.tsx create mode 100644 example/run__.tsx create mode 100644 run.tsx diff --git a/deno.json b/deno.json index f8d9679..e1872f0 100644 --- a/deno.json +++ b/deno.json @@ -7,13 +7,13 @@ { "react":"https://esm.sh/preact@10.15.1/compat", "react-original":"https://esm.sh/preact@10.15.1/compat", - ">able/": "http://localhost:4507/" + "able/": "http://localhost:4507/" }, "tasks": { - "local": "deno run -A --reload=http://localhost --no-lock ./run-local.tsx --port=1234", - "serve": "deno run -A --reload=http://localhost --no-lock ./run-serve.tsx --port=1234", - "debug": "deno run -A --reload=http://localhost --inspect-wait --no-lock ./run-serve.tsx --port=1234", - "deploy":"deno run -A --no-lock --reload=http://localhost http://localhost:4507/run-deploy.tsx" + "local": "deno run -A --reload=http://localhost:4507 --no-lock ./run-local.tsx --port=1234", + "serve": "deno run -A --reload=http://localhost:4507 --no-lock ./run-serve.tsx --port=1234", + "debug": "deno run -A --reload=http://localhost:4507 --inspect-wait --no-lock ./run-serve.tsx --port=1234", + "deploy":"deno run -A --no-lock --reload=http://localhost:4507 http://localhost:4507/run-deploy.tsx" } } \ No newline at end of file diff --git a/deno.lock b/deno.lock new file mode 100644 index 0000000..f98e488 --- /dev/null +++ b/deno.lock @@ -0,0 +1,28 @@ +{ + "version": "2", + "remote": { + "http://localhost:4507/hmr-static.tsx": "b88a33a019b7a6090d05a43d15843b36fe294196c4423c753fe3654ab369f1b1", + "http://localhost:4507/run-local.tsx": "2c0bf9b994677f2c0bb6ef26616960f25f61e3f8b4767891a95896fb7752a74e", + "http://localhost:4507/run-serve.tsx": "400828ea6457485c3bfcfe3bfdd60b1844e6e66f56a3606d250ce9a7481c6ead", + "http://localhost:4507/run.tsx": "f7f2a90d2bda35e5de3b307e36666120439f516d88f44a4388a3251679a99e3e", + "https://deno.land/std@0.180.0/media_types/_db.ts": "7606d83e31f23ce1a7968cbaee852810c2cf477903a095696cdc62eaab7ce570", + "https://deno.land/std@0.180.0/media_types/_util.ts": "916efbd30b6148a716f110e67a4db29d6949bf4048997b754415dd7e42c52378", + "https://deno.land/std@0.180.0/media_types/content_type.ts": "c682589a0aeb016bfed355cc1ed6fbb3ead2ea48fc0000ac5de6a5730613ad1c", + "https://deno.land/std@0.180.0/media_types/extension.ts": "7a4ef2813d7182f724a941f38161525996e4a67abc3cf6a0f9bc2168d73a0f0e", + "https://deno.land/std@0.180.0/media_types/extensions_by_type.ts": "4358023feac696e6e9d49c0f1e76a859f03ca254df57812f31f8536890c3a443", + "https://deno.land/std@0.180.0/media_types/format_media_type.ts": "1e35e16562e5c417401ffc388a9f8f421f97f0ee06259cbe990c51bae4e6c7a8", + "https://deno.land/std@0.180.0/media_types/get_charset.ts": "8be15a1fd31a545736b91ace56d0e4c66ea0d7b3fdc5c90760e8202e7b4b1fad", + "https://deno.land/std@0.180.0/media_types/mod.ts": "d3f0b99f85053bc0b98ecc24eaa3546dfa09b856dc0bbaf60d8956d2cdd710c8", + "https://deno.land/std@0.180.0/media_types/parse_media_type.ts": "bed260d868ea271445ae41d748e7afed9b5a7f407d2777ead08cecf73e9278de", + "https://deno.land/std@0.180.0/media_types/type_by_extension.ts": "6076a7fc63181d70f92ec582fdea2c927eb2cfc7f9c9bee9d6add2aca86f2355", + "https://deno.land/std@0.180.0/media_types/vendor/mime-db.v1.52.0.ts": "6925bbcae81ca37241e3f55908d0505724358cda3384eaea707773b2c7e99586", + "https://esm.sh/@swc/wasm-web@1.3.62": "e077889c90bd43ad29e9cf086818efc334bdf31b933575e0c27972173053a3c6", + "https://esm.sh/preact@10.15.1/compat/jsx-runtime": "3f191e04473646ff8f5f76fb4378fc502a7cc892d9e147584d4f7531981bc86b", + "https://esm.sh/stable/preact@10.15.1/denonext/compat.js": "bad6b5b4d4fdfa5975b7a8d30410bd6877247f058e4952799fab39f66a94b8cf", + "https://esm.sh/stable/preact@10.15.1/denonext/compat/jsx-runtime.js": "e5c016fa258601ca873ba29188e56cede90372a0bdb52e58b0dfb801f2e2f219", + "https://esm.sh/stable/preact@10.15.1/denonext/hooks.js": "5c989ad368cf4f2cb3a5d7d1801843d9348c599fe3e7731d04728f7b845d724e", + "https://esm.sh/stable/preact@10.15.1/denonext/jsx-runtime.js": "52806054f5b3477005ab4bdc17de3d219ccc6c130d0cd803c45667b0cac2f6ed", + "https://esm.sh/stable/preact@10.15.1/denonext/preact.mjs": "30710ac1d5ff3711ae0c04eddbeb706f34f82d97489f61aaf09897bc75d2a628", + "https://esm.sh/v130/@swc/wasm-web@1.3.62/denonext/wasm-web.mjs": "57046d46c9ef1398a294ba7447034f5966e48866a05c309cccec4bb4d6e7c61b" + } +} diff --git a/example/.env b/example/.env deleted file mode 100644 index 6a7678a..0000000 --- a/example/.env +++ /dev/null @@ -1 +0,0 @@ -DENO_DEPLOY_TOKEN=1 \ No newline at end of file diff --git a/example/api.tsx b/example/api.tsx deleted file mode 100644 index 75d913f..0000000 --- a/example/api.tsx +++ /dev/null @@ -1,4 +0,0 @@ -export default (inReq:Request)=> -{ - return false; -} \ No newline at end of file diff --git a/example/app.tsx b/example/app.tsx index e2f7de8..88f14aa 100644 --- a/example/app.tsx +++ b/example/app.tsx @@ -39,7 +39,7 @@ export default ()=> return
-

Title?????

+

Title

subtitle

diff --git a/example/deno.json b/example/deno.json index 9155bc1..a27803a 100644 --- a/example/deno.json +++ b/example/deno.json @@ -3,15 +3,12 @@ "imports": { "react": "https://esm.sh/preact@10.15.1/compat", - ">able/": "http://localhost:4507/", - ">able/app": "./app.tsx", - ">able/api": "./api.tsx" + ">able/": "http://localhost:4507/" }, "tasks": { - "local": "deno run --config=deno.json -A --no-lock --reload=http://localhost:4507 http://localhost:4507/run-local.tsx", - "serve": "deno run --config=deno.json -A --no-lock --reload=http://localhost:4507 http://localhost:4507/run-serve.tsx", - "deploy":"deno run -A --no-lock --reload=http://localhost:4507 http://localhost:4507/run-deploy.tsx", - "debug": "deno run --config=deno.json -A --inspect-wait --no-lock --reload=http://localhost:4507 http://localhost:4507/run-serve.tsx" + "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" } } \ No newline at end of file diff --git a/example/run__.tsx b/example/run__.tsx new file mode 100644 index 0000000..8bc8091 --- /dev/null +++ b/example/run__.tsx @@ -0,0 +1,9 @@ +import Configure from ">able/run.tsx"; + +Configure({ + Start:"/app.tsx", + Serve() + { + return false; + } +}) \ No newline at end of file diff --git a/run-browser.tsx b/run-browser.tsx index 4c13939..018f55d 100644 --- a/run-browser.tsx +++ b/run-browser.tsx @@ -26,6 +26,13 @@ export const Shadow =(inElement:HTMLElement, inConfig?:TW.TwindUserConfig)=> export default async(inSelector:string, inModulePath:string, inMemberApp="default", inMemberCSS="CSS"):Promise<(()=>void)|false>=> { + + if(!inModulePath) + { + return false; + } + + let dom = document.querySelector(inSelector); if(!dom) { diff --git a/run-local.tsx b/run-local.tsx index 6cf1af7..bef5370 100644 --- a/run-local.tsx +++ b/run-local.tsx @@ -25,7 +25,7 @@ Configure({ inImports["react"] = `/>able/hmr-react.tsx`; return inImports; }, - async Serve(inReq, inURL, inExt, inMap, inConfig) + async Extra(inReq, inURL, inExt, inMap, inConfig) { if(!inURL.pathname.startsWith(encodeURI("/>"))) { diff --git a/run-serve.tsx b/run-serve.tsx index 73a748f..a31b014 100644 --- a/run-serve.tsx +++ b/run-serve.tsx @@ -1,20 +1,9 @@ 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 Api from ">able/api"; - export const Root = new URL(`file://${Deno.cwd().replaceAll("\\", "/")}`).toString(); -Deno.args.forEach(arg=> -{ - if(arg.startsWith("--")) - { - const kvp = arg.substring(2).split("="); - Deno.env.set(kvp[0], kvp[1] || "true"); - } -}); - type DenoConfig = {imports:Record}; const ImportMap:DenoConfig = {imports:{}}; let ImportMapOriginal = {}; @@ -77,14 +66,16 @@ const ImportMapReload =async()=> ImportMap.imports = Configuration.Remap(json.imports, Configuration); }; -type CustomHTTPHandler = (inReq:Request, inURL:URL, inExt:string|false, inMap:{imports:Record}, inConfig:Configuration)=>void|false|Response|Promise; -type CustomRemapper = (inImports:Record, inConfig:Configuration)=>Record; -type Configuration = {Allow:string, Reset:string, SWCOp:SWCW.Options, Serve:CustomHTTPHandler, Shell:CustomHTTPHandler, Remap:CustomRemapper}; -type ConfigurationArgs = {Allow?:string, Reset?:string, SWCOp?:SWCW.Options, Serve?:CustomHTTPHandler, Shell?:CustomHTTPHandler, Remap?:CustomRemapper}; +export type CustomHTTPHandler = (inReq:Request, inURL:URL, inExt:string|false, inMap:{imports:Record}, inConfig:Configuration)=>void|false|Response|Promise; +export type CustomRemapper = (inImports:Record, inConfig:Configuration)=>Record; +export type Configuration = {Start:string, Allow:string, Reset:string, SWCOp:SWCW.Options, Serve:CustomHTTPHandler, Extra:CustomHTTPHandler, Shell:CustomHTTPHandler, Remap:CustomRemapper}; +export type ConfigurationArgs = Partial; let Configuration:Configuration = { + Start: "", Allow: "*", Reset: "/clear-cache", + async Extra(inReq, inURL, inExt, inMap, inConfig){}, async Serve(inReq, inURL, inExt, inMap, inConfig){}, Remap: (inImports, inConfig)=> { @@ -104,7 +95,7 @@ let Configuration:Configuration = `, {status:200, headers:{"content-type":"text/html"}}); @@ -254,19 +245,6 @@ export const Transpile = } }; - -export const ExtensionPrefix =(string:string, suffix:string)=> -{ - const lastDotIndex = string.lastIndexOf("."); - if (lastDotIndex === -1) { - return string; - } - - const prefix = string.substring(0, lastDotIndex); - const suffixString = string.substring(lastDotIndex + 1); - return prefix + "." + suffix + "." + suffixString; -}; - export const Extension =(inPath:string)=> { const posSlash = inPath.lastIndexOf("/"); @@ -298,7 +276,7 @@ const server = Deno.serve({port:parseInt(Deno.env.get("port")||"8000")}, async(r const headers = {"content-type":"application/json", "Access-Control-Allow-Origin": Configuration.Allow, "charset":"UTF-8"}; let proxy = Root + url.pathname; - if(url.pathname.includes("/__")) + if(url.pathname.includes("__/") || url.pathname.lastIndexOf("__.") > -1) { return new Response(`{"error":"unmatched route", "path":"${url.pathname}"}`, {status:404, headers}); } @@ -323,14 +301,13 @@ const server = Deno.serve({port:parseInt(Deno.env.get("port")||"8000")}, async(r } } - // allow for custom handler - const custom = await Configuration.Serve(req, url, ext, ImportMap, Configuration); + // allow for custom handlers + const custom = await Configuration.Extra(req, url, ext, ImportMap, Configuration); if(custom) { return custom; } - - const api = Api(req); + const api = await Configuration.Serve(req, url, ext, ImportMap, Configuration); if(api) { return api; diff --git a/run.tsx b/run.tsx new file mode 100644 index 0000000..047650f --- /dev/null +++ b/run.tsx @@ -0,0 +1,16 @@ +import * as Serve from "./run-serve.tsx"; +export default Serve.Configure; + +Deno.args.forEach(arg=> +{ + if(arg.startsWith("--")) + { + const kvp = arg.substring(2).split("="); + Deno.env.set(kvp[0], kvp[1] || "true"); + } +}); + +if(Deno.env.get("dev")) +{ + import("./run-local.tsx"); +} \ No newline at end of file -- 2.34.1 From 78230a5672544e3083e7f5a1e11b47aec5c67861 Mon Sep 17 00:00:00 2001 From: Seth Trowbridge Date: Sun, 30 Jul 2023 13:04:26 -0400 Subject: [PATCH 2/5] allow for code or config setup --- api => api.tsx | 0 app => app.tsx | 0 {example => example-config}/app.tsx | 0 example-config/deno.json | 19 +++ example-script/app.tsx | 56 ++++++++ {example => example-script}/deno.json | 3 +- {example => example-script}/run__.tsx | 0 run-deploy.tsx | 6 +- run-serve.tsx | 185 +++++++++++++------------- run.tsx | 23 +++- 10 files changed, 194 insertions(+), 98 deletions(-) rename api => api.tsx (100%) rename app => app.tsx (100%) rename {example => example-config}/app.tsx (100%) create mode 100644 example-config/deno.json create mode 100644 example-script/app.tsx rename {example => example-script}/deno.json (78%) rename {example => example-script}/run__.tsx (100%) diff --git a/api b/api.tsx similarity index 100% rename from api rename to api.tsx diff --git a/app b/app.tsx similarity index 100% rename from app rename to app.tsx diff --git a/example/app.tsx b/example-config/app.tsx similarity index 100% rename from example/app.tsx rename to example-config/app.tsx diff --git a/example-config/deno.json b/example-config/deno.json new file mode 100644 index 0000000..ae6483b --- /dev/null +++ b/example-config/deno.json @@ -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"] + } +} \ No newline at end of file diff --git a/example-script/app.tsx b/example-script/app.tsx new file mode 100644 index 0000000..88f14aa --- /dev/null +++ b/example-script/app.tsx @@ -0,0 +1,56 @@ +import { Router, Switch, Case } from ">able/iso-elements.tsx"; + +import React from "react"; + +const CTXString = React.createContext("lol"); + +type StateBinding = [get:T, set:React.StateUpdater]; +const CTXState = React.createContext(null) as React.Context|null>; +const Outer =(props:{children:React.JSX.Element})=> +{ + const binding = React.useState(11); + return + {props.children} + +}; +const Inner =()=> +{ + const [stateGet, stateSet] = React.useContext(CTXState) || ["default", ()=>{}]; + return +}; + + +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 + +

+

Title

+

subtitle

+

+ +

+
+ + + + + + + + ; +} diff --git a/example/deno.json b/example-script/deno.json similarity index 78% rename from example/deno.json rename to example-script/deno.json index a27803a..c8e26a5 100644 --- a/example/deno.json +++ b/example-script/deno.json @@ -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" } } \ No newline at end of file diff --git a/example/run__.tsx b/example-script/run__.tsx similarity index 100% rename from example/run__.tsx rename to example-script/run__.tsx diff --git a/run-deploy.tsx b/run-deploy.tsx index 4d20a1c..d2ab39a 100644 --- a/run-deploy.tsx +++ b/run-deploy.tsx @@ -30,6 +30,7 @@ const collect =async(inKey:string, inArg:Record, inEnv:Record=> @@ -45,8 +46,7 @@ const prompt =async(question: string):Promise=> 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" diff --git a/run-serve.tsx b/run-serve.tsx index a31b014..2c45b08 100644 --- a/run-serve.tsx +++ b/run-serve.tsx @@ -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; 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,104 +259,106 @@ export const Configure =(config:ConfigurationArgs)=> ImportMapReload(); } -await ImportMapReload(); -try +export default async()=> { - await SWCW.default(); -} -catch(e) -{ - console.log("swc init error:", e); -} - - -const server = Deno.serve({port:parseInt(Deno.env.get("port")||"8000")}, async(req: Request)=> -{ - const url:URL = new URL(req.url); - const ext = Extension(url.pathname); - const headers = {"content-type":"application/json", "Access-Control-Allow-Origin": Configuration.Allow, "charset":"UTF-8"}; - let proxy = Root + url.pathname; - - if(url.pathname.includes("__/") || url.pathname.lastIndexOf("__.") > -1) + await ImportMapReload(); + try { - return new Response(`{"error":"unmatched route", "path":"${url.pathname}"}`, {status:404, headers}); + await SWCW.default(); } - - // proxy imports - if(url.pathname.startsWith(encodeURI("/>"))) + catch(e) { - let bestMatch=""; - for(let key in ImportMapProxies) + console.log("swc init error:", e); + } + + + const server = Deno.serve({port:parseInt(Deno.env.get("port")||"8000")}, async(req: Request)=> + { + const url:URL = new URL(req.url); + const ext = Extension(url.pathname); + const headers = {"content-type":"application/json", "Access-Control-Allow-Origin": Configuration.Allow, "charset":"UTF-8"}; + let proxy = Root + url.pathname; + + if(url.pathname.includes("__/") || url.pathname.lastIndexOf("__.") > -1) { - if(url.pathname.startsWith(key) && key.length > bestMatch.length) + return new Response(`{"error":"unmatched route", "path":"${url.pathname}"}`, {status:404, headers}); + } + + // proxy imports + if(url.pathname.startsWith(encodeURI("/>"))) + { + let bestMatch=""; + for(let key in ImportMapProxies) { - bestMatch = key; + if(url.pathname.startsWith(key) && key.length > bestMatch.length) + { + bestMatch = key; + } + } + if(bestMatch.length) + { + const match = ImportMapProxies[bestMatch]; + const path = url.pathname.substring(bestMatch.length); + proxy = path ? match + path : Root + match; + + } + } + + // allow for custom handlers + const custom = await Configuration.Extra(req, url, ext, ImportMap, Configuration); + if(custom) + { + return custom; + } + const api = await Configuration.Serve(req, url, ext, ImportMap, Configuration); + if(api) + { + return api; + } + + // transpileable files + if(Transpile.Check(ext)) + { + console.log("transpiling:", proxy); + const code = await Transpile.Fetch(proxy, url.pathname); + if(code) + { + return new Response(code, {headers:{...headers, "content-type":"application/javascript"}} ); + } + } + + // custom page html + if(!ext) + { + const shell = await Configuration.Shell(req, url, ext, ImportMap, Configuration); + if(shell) + { + return shell; } } - if(bestMatch.length) + + // cache-reset route + if(url.pathname === Configuration.Reset) { - const match = ImportMapProxies[bestMatch]; - const path = url.pathname.substring(bestMatch.length); - proxy = path ? match + path : Root + match; - - } - } - - // allow for custom handlers - const custom = await Configuration.Extra(req, url, ext, ImportMap, Configuration); - if(custom) - { - return custom; - } - const api = await Configuration.Serve(req, url, ext, ImportMap, Configuration); - if(api) - { - return api; - } - - // transpileable files - if(Transpile.Check(ext)) - { - console.log("transpiling:", proxy); - const code = await Transpile.Fetch(proxy, url.pathname); - if(code) - { - return new Response(code, {headers:{...headers, "content-type":"application/javascript"}} ); - } - } - - // custom page html - if(!ext) - { - const shell = await Configuration.Shell(req, url, ext, ImportMap, Configuration); - if(shell) - { - return shell; + return new Response(`{"cleared":${Transpile.Clear()}}`, {headers}); } - } - - // cache-reset route - if(url.pathname === Configuration.Reset) - { - return new Response(`{"cleared":${Transpile.Clear()}}`, {headers}); - } - - // all other static files - if(ext) - { - try + + // all other static files + if(ext) { - const type = MIME.typeByExtension(ext); - const file = await fetch(proxy); - return new Response(file.body, {headers:{...headers, "content-type":type||""}}); + try + { + const type = MIME.typeByExtension(ext); + const file = await fetch(proxy); + return new Response(file.body, {headers:{...headers, "content-type":type||""}}); + } + catch(e) + { + return new Response(`{"error":"${e}", "path":"${url.pathname}"}`, {status:404, headers}); + } } - catch(e) - { - return new Response(`{"error":"${e}", "path":"${url.pathname}"}`, {status:404, headers}); - } - } - - return new Response(`{"error":"unmatched route", "path":"${url.pathname}"}`, {status:404, headers}); - -}); - + + return new Response(`{"error":"unmatched route", "path":"${url.pathname}"}`, {status:404, headers}); + + }); +} diff --git a/run.tsx b/run.tsx index 047650f..1fa0c64 100644 --- a/run.tsx +++ b/run.tsx @@ -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("dev")) +if(Deno.env.get("dep")) { - import("./run-local.tsx"); + import("./run-deploy.tsx"); +} +else +{ + if(Deno.env.get("dev")) + { + await import("./run-local.tsx"); + } + Serve.default(); } \ No newline at end of file -- 2.34.1 From 1f6ab7cf47aec659420da3d4f8c2c5a1795da5d3 Mon Sep 17 00:00:00 2001 From: Seth Trowbridge Date: Sun, 30 Jul 2023 13:29:15 -0400 Subject: [PATCH 3/5] only run once --- run-serve.tsx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/run-serve.tsx b/run-serve.tsx index 2c45b08..90bd739 100644 --- a/run-serve.tsx +++ b/run-serve.tsx @@ -259,8 +259,13 @@ export const Configure =(config:ConfigurationArgs)=> ImportMapReload(); } + +let running = false; export default async()=> { + if(running){return}; + running = true; + await ImportMapReload(); try { -- 2.34.1 From 79c5a0aff00d28e5bd3f7966389d454eb54b4919 Mon Sep 17 00:00:00 2001 From: Seth Trowbridge Date: Sun, 30 Jul 2023 14:01:14 -0400 Subject: [PATCH 4/5] fix flag names --- run.tsx | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/run.tsx b/run.tsx index 1fa0c64..55c37b3 100644 --- a/run.tsx +++ b/run.tsx @@ -1,15 +1,5 @@ import * as Serve from "./run-serve.tsx"; -export default function(config:Serve.ConfigurationArgs) -{ - if(Deno.env.get("deploy")) - { - return; - } - Serve.Configure(config) - Serve.default(); -} - Deno.args.forEach(arg=> { if(arg.startsWith("--")) @@ -18,14 +8,25 @@ Deno.args.forEach(arg=> Deno.env.set(kvp[0], kvp[1] || "true"); } }); +const isDeploy = Deno.env.get("dep"); +const isDevelop = Deno.env.get("dev"); -if(Deno.env.get("dep")) +export default function(config:Serve.ConfigurationArgs) +{ + if(!isDeploy) + { + Serve.Configure(config) + Serve.default(); + } +} + +if(isDeploy) { import("./run-deploy.tsx"); } else { - if(Deno.env.get("dev")) + if(isDevelop) { await import("./run-local.tsx"); } -- 2.34.1 From bd7af1241ee4369cffe87dc36812c9bcb70605fd Mon Sep 17 00:00:00 2001 From: Seth Trowbridge Date: Sun, 30 Jul 2023 14:21:35 -0400 Subject: [PATCH 5/5] allow for production deployment --- run-deploy.tsx | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/run-deploy.tsx b/run-deploy.tsx index d2ab39a..5f9ef7c 100644 --- a/run-deploy.tsx +++ b/run-deploy.tsx @@ -53,6 +53,17 @@ try let useToken = await collect("DENO_DEPLOY_TOKEN", arg, env); let useProject = await collect("DENO_DEPLOY_PROJECT", arg, env); + + let scanProd:string|string[] = await prompt(`Do you want to deploy to *production*? [y/n]`); + if(scanProd == "y") + { + scanProd = await prompt(`This will update the live project at ${useProject} are you sure you want to continue? [y/n]`); + scanProd = scanProd=="y" ? ["--prod"] : []; + } + else + { + scanProd = []; + } const command = new Deno.Command( `deno`, @@ -66,6 +77,7 @@ try `--project=${useProject}`, `--import-map=./deno.json`, `--token=${useToken}`, + ...scanProd, Deno.mainModule ], stdin: "piped", -- 2.34.1