From 27579986754fe8d2b2a171dd2c16360a964fe325 Mon Sep 17 00:00:00 2001 From: Seth Trowbridge Date: Mon, 28 Aug 2023 22:16:56 -0400 Subject: [PATCH] config checking --- .gitingore | 1 + checker.tsx | 139 ++++++++++++++++++++++++++++++-------------------- cli.tsx | 25 +++++++-- deno.jsonc | 9 +++- run-serve.tsx | 10 ---- sub.tsx | 7 --- sup.tsx | 37 -------------- 7 files changed, 112 insertions(+), 116 deletions(-) create mode 100644 .gitingore delete mode 100644 sub.tsx delete mode 100644 sup.tsx diff --git a/.gitingore b/.gitingore new file mode 100644 index 0000000..941fcf1 --- /dev/null +++ b/.gitingore @@ -0,0 +1 @@ +deno.lock \ No newline at end of file diff --git a/checker.tsx b/checker.tsx index 80ec776..01a117b 100644 --- a/checker.tsx +++ b/checker.tsx @@ -115,9 +115,12 @@ export async function Install(file:string, overrideName?:string, handler?:(conte export async function Check() { + let [config, imports] = await HuntConfig(); + console.log(`Checking directory "${Root}"`); + console.log("Found", config, imports); try { - let [config, imports] = await HuntConfig(); + //console.log(config, imports); if(!config.path) { @@ -181,63 +184,25 @@ export async function Check() await bake(imports); } - if(!importMap[">able/app.tsx"]) - { - if(confirm(`🤔 OPTIONAL: Your import map does not override the default/empty FRONT-END app with the specifier ">able/app.tsx". Create this file and add the specifier?`)) - { - importMap[">able/app.tsx"] = `./app.tsx`; - await bake(imports); - await Install("app.tsx"); - } - } - else - { - try - { - const app = await import(importMap[">able/app.tsx"]); - // @ts-ignore - const result = app.default().$$typeof; - } - catch(e) - { - console.log(e); - if(confirm(`🚧 Your FRONT-END app ("${importMap[">able/app.tsx"]}") does not export a default function that returns VDOM nodes. Replace it?`)) - { - await Install("app.tsx", importMap[">able/app.tsx"]); - } - else - { - throw("⛔ Your FRONT-END app has incorrect export types."); - } - } - } + const tasks:Record = { + "check": `deno run -A --no-lock ${RootHost}cli.tsx check`, + "local": `deno run -A --no-lock ${RootHost}cli.tsx local`, + "debug": `deno run -A --no-lock ${RootHost}cli.tsx debug`, + "serve": `deno run -A --no-lock ${RootHost}cli.tsx serve`, + "cloud": `deno run -A --no-lock ${RootHost}cli.tsx cloud` + }; - if(!importMap[">able/api.tsx"]) + const confTasks = (config.json.tasks || {}) as Record; + for(const key in tasks) { - if(confirm(`🤔 OPTIONAL: Your import map does not override the default/empty BACK-END api with the specifier ">able/api.tsx". Create this file and add the specifier?`)) + if(tasks[key] !== confTasks[key]) { - importMap[">able/api.tsx"] = "./api.tsx"; - await bake(imports); - await Install("api.tsx"); - } - } - else - { - try - { - const api = await import(importMap[">able/api.tsx"]); - const result = api.default(new Request(new URL("https://fake-deno-testing-domain.com/"))); - } - catch(e) - { - if(confirm(`🚧 Your starter backend app ("${importMap[">able/api.tsx"]}") does not export a default function that accepts a Request. Replace it?`)) + if(confirm(`🤔 OPTIONAL: The tasks defined in your config contain missing or modified values. Update tasks?`)) { - await Install("api.tsx", importMap[">able/api.tsx"]); - } - else - { - throw("⛔ Starter backend app has incorrect export types."); + config.json.tasks = {...confTasks, ...tasks}; + await bake(config); } + break; } } @@ -267,6 +232,70 @@ export async function Check() } + if(!importMap[">able/app.tsx"]) + { + if(confirm(`🤔 OPTIONAL: Your import map does not override the default/empty FRONT-END app with the specifier ">able/app.tsx". Create this file and add the specifier?`)) + { + importMap[">able/app.tsx"] = `./app.tsx`; + await bake(imports); + await Install("app.tsx"); + } + } + else + { + /* + try + { + const app = await import(importMap[">able/app.tsx"]); + // @ts-ignore + const result = app.default().$$typeof; + } + catch(e) + { + console.log(e); + if(confirm(`🚧 Your FRONT-END app ("${importMap[">able/app.tsx"]}") does not export a default function that returns VDOM nodes. Replace it?`)) + { + await Install("app.tsx", importMap[">able/app.tsx"]); + } + else + { + throw("⛔ Your FRONT-END app has incorrect export types."); + } + } + */ + } + + if(!importMap[">able/api.tsx"]) + { + if(confirm(`🤔 OPTIONAL: Your import map does not override the default/empty BACK-END api with the specifier ">able/api.tsx". Create this file and add the specifier?`)) + { + importMap[">able/api.tsx"] = "./api.tsx"; + await bake(imports); + await Install("api.tsx"); + } + } + else + { + /* + try + { + const api = await import(importMap[">able/api.tsx"]); + const result = api.default(new Request(new URL("https://fake-deno-testing-domain.com/"))); + } + catch(e) + { + if(confirm(`🚧 Your starter backend app ("${importMap[">able/api.tsx"]}") does not export a default function that accepts a Request. Replace it?`)) + { + await Install("api.tsx", importMap[">able/api.tsx"]); + } + else + { + throw("⛔ Starter backend app has incorrect export types."); + } + } + */ + } + } } catch(e) @@ -276,6 +305,4 @@ export async function Check() } console.log(`🚗 Good to go!`); -} - -Check(); \ No newline at end of file +} \ No newline at end of file diff --git a/cli.tsx b/cli.tsx index 25159c1..8264873 100644 --- a/cli.tsx +++ b/cli.tsx @@ -35,7 +35,6 @@ const collect =async(inKey:string, inArg:Record, inEnv:Recordable/": "file:///C:/Web%20Projects/able-baker/", + ">able/": "http://localhost:4507/", ">able/app.tsx": "./app.tsx" }, + "tasks": { + "check": "deno run -A --no-lock http://localhost:4507/cli.tsx check", + "local": "deno run -A --no-lock http://localhost:4507/cli.tsx local", + "debug": "deno run -A --no-lock http://localhost:4507/cli.tsx debug", + "serve": "deno run -A --no-lock http://localhost:4507/cli.tsx serve", + "cloud": "deno run -A --no-lock http://localhost:4507/cli.tsx cloud" + }, "compilerOptions": { "jsx": "react-jsx", "jsxImportSource": "react", diff --git a/run-serve.tsx b/run-serve.tsx index 84d9b38..78bbb24 100644 --- a/run-serve.tsx +++ b/run-serve.tsx @@ -17,16 +17,6 @@ const ImportMapReload =async()=> if(imports) { - if(imports["react"]) - { - console.log(`"react" specifier not defined in import map`); - - } - else if(!imports["react/"]) - { - imports["react/"] = imports["react"]+"/"; - } - ImportMapProxies = {}; Object.entries(imports).forEach(([key, value])=> { diff --git a/sub.tsx b/sub.tsx deleted file mode 100644 index b11c13a..0000000 --- a/sub.tsx +++ /dev/null @@ -1,7 +0,0 @@ -import { parse } from "https://deno.land/std@0.194.0/flags/mod.ts"; - -let arg = parse(Deno.args); - -console.log(arg); - -console.log(Deno.env.get("super")) diff --git a/sup.tsx b/sup.tsx deleted file mode 100644 index beef02b..0000000 --- a/sup.tsx +++ /dev/null @@ -1,37 +0,0 @@ -import * as Env from "https://deno.land/std@0.194.0/dotenv/mod.ts"; -import * as Arg from "https://deno.land/std@0.194.0/flags/mod.ts"; - -let arg = Arg.parse(Deno.args); -let env = await Env.load(); - -Deno.env.set("super", "its super"); - -export async function SubProcess(args:string[]) -{ - const command = new Deno.Command( - `deno`, - { - args, - stdin: "piped", - stdout: "piped" - } - ); - - const child = command.spawn(); - - // open a file and pipe the subprocess output to it. - const writableStream = new WritableStream({ - write(chunk: Uint8Array): Promise { - Deno.stdout.write(chunk); - return Promise.resolve(); - }, - }); - child.stdout.pipeTo(writableStream); - - // manually close stdin - child.stdin.close(); - const status = await child.status; -} - - -SubProcess(["run", "-A", "sub.tsx", "keyword!", "--passed=yep"]); \ No newline at end of file