From 35f8e64a26b210b54a96aa02d771bc6c2c29b716 Mon Sep 17 00:00:00 2001 From: Seth Trowbridge Date: Tue, 1 Aug 2023 15:30:31 -0400 Subject: [PATCH] installer started --- cli.tsx | 52 ++++++++++++++++++++++++++++++++++------ deno.json => deno__.json | 4 ++-- install__/deno.jsonc | 41 +++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+), 9 deletions(-) rename deno.json => deno__.json (91%) create mode 100644 install__/deno.jsonc diff --git a/cli.tsx b/cli.tsx index b0ffa78..7740e3f 100644 --- a/cli.tsx +++ b/cli.tsx @@ -1,12 +1,11 @@ import { parse as JSONC } from "https://deno.land/x/jsonct@v0.1.0/mod.ts"; - +const Root = new URL(`file://${Deno.cwd().replaceAll("\\", "/")}`).toString(); export async function HuntConfig() { - const Root = new URL(`file://${Deno.cwd().replaceAll("\\", "/")}`).toString(); let path:string, resp:Response, text="", json; try { - path = "./deno.json" + path = "deno.json" resp = await fetch(Root + "/" + path); text = await resp.text(); } @@ -14,7 +13,7 @@ export async function HuntConfig() { try { - path = "./deno.jsonc"; + path = "deno.jsonc"; resp = await fetch(Root + "/" + path); text = await resp.text(); } @@ -26,6 +25,7 @@ export async function HuntConfig() resp = await fetch(path); json = await resp.json(); path = json["deno.config"]; + json = undefined; if(path) { resp = await fetch(Root + "/" + path); @@ -51,7 +51,18 @@ export async function HuntConfig() } } - return {text, path, json}; + return {path, text, json}; +} + +async function Prompt(question: string):Promise +{ + const buf = new Uint8Array(1024); + await Deno.stdout.write(new TextEncoder().encode(question)); + const bytes = await Deno.stdin.read(buf); + if (bytes) { + return new TextDecoder().decode(buf.subarray(0, bytes)).trim(); + } + throw new Error("Unexpected end of input"); } export async function SubProcess(args:string[]) @@ -81,5 +92,32 @@ export async function SubProcess(args:string[]) const status = await child.status; } -const conf = await HuntConfig(); -console.log(conf); \ No newline at end of file +const config = await HuntConfig(); +if(!config.path) +{ + try + { + const resp = await Prompt("No Deno configuration found. Create one? [y/n]"); + if(resp == "y") + { + const pathServer = import.meta.resolve("./"); + const pathConfig = pathServer + "install__/deno.jsonc"; + + console.log(pathServer, pathConfig); + + const resp = await fetch(pathConfig); + const text = await resp.text(); + Deno.writeTextFileSync(Deno.cwd()+"/deno.jsonc", text.replaceAll("{{server}}", pathServer)); + } + else + { + throw(""); + } + } + catch(e) + { + console.log(e, "(Exiting...)"); + Deno.exit(); + } +} +console.log(config); \ No newline at end of file diff --git a/deno.json b/deno__.json similarity index 91% rename from deno.json rename to deno__.json index 2cbba0c..1e16461 100644 --- a/deno.json +++ b/deno__.json @@ -8,13 +8,13 @@ "react":"https://esm.sh/preact@10.15.1/compat", "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:4507 --no-lock ./run-local.tsx --port=1234", "serve": "deno run -A --reload=http://localhost:4507 --no-lock ./run-serve.tsx --port=1234", + "cloud": "deno run -A --reload=http://localhost:4507 --no-lock ./run-deploy.tsx", "debug": "deno run -A --reload=http://localhost:4507 --no-lock --inspect-wait ./run-serve.tsx --port=1234", - "cloud": "deno run -A --reload=http://localhost:4507 --no-lock ./run-deploy.tsx" } } \ No newline at end of file diff --git a/install__/deno.jsonc b/install__/deno.jsonc new file mode 100644 index 0000000..8dce7ac --- /dev/null +++ b/install__/deno.jsonc @@ -0,0 +1,41 @@ +{ + "imports": + { + "react":"https://esm.sh/preact@10.15.1/compat", // (required) Specifier for 'react' + "react/":"https://esm.sh/preact@10.15.1/compat/", // (conditional) This allows the use of JSX without explicitly importing React into a module. If you choose to remove this (and make importing react required), also remove "jsx" and "jsxImportSource" from "compilerOptions" (below) + ">able/": "{{server}}" // (required) Specifier 'able'. (See note below about "isomorphic proxies") + }, + + "tasks": + { + "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", + "cloud": "deno run -A --reload=http://localhost:4507 --no-lock ./run-deploy.tsx", + "debug": "deno run -A --reload=http://localhost:4507 --no-lock --inspect-wait ./run-serve.tsx --port=1234" + }, + + "compilerOptions": + { + "lib": ["deno.window", "dom"], // makes the Deno Language Server OK with browser-specific code + "jsx": "react-jsx", // see "react/" import above + "jsxImportSource": "react" // ^ + } + +/* + + Imports prefixed with ">" are "isomorphic proxies." + In addition to functioning normally as bare module specifiers for Deno, **these imports are added as routes when the server starts**. + Assuming the specifier points to remotely a hosted directory containing typescript files, requests to your running Able server on these proxy routes are actually fetched from the remote, then transpiled (and cached), then send back as a response. + For example, after the Able server starts, if it sees a web request to '/>able/iso-elements.tsx' it would actually return a browser-friendly transpiled copy of what was on the remote. + Conversely, if the Deno Language Server were to see: `import * as Iso from ">able/iso-elements.tsx";` in one of your modules, + that will be resolved normally with the import map and Deno will just receive the tsx file as-is from the remote, typings and all, so intellisense will work in your IDE. + + While ">able/" is a required "import proxy" to pull in Able source code, you are free to use this convention to also add your own proxies as you see fit. + E.g. adding this record to imports: + ">your-import/": "https://raw.githubusercontent.com/your-name/your-lib/master/" + will give both Deno and browsers running your Able project everything they need + import CoolComponent from ">your-import/cc.tsx"; + ... + +*/ +} \ No newline at end of file