cli #6
52
cli.tsx
52
cli.tsx
@ -1,12 +1,11 @@
|
|||||||
import { parse as JSONC } from "https://deno.land/x/jsonct@v0.1.0/mod.ts";
|
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()
|
export async function HuntConfig()
|
||||||
{
|
{
|
||||||
const Root = new URL(`file://${Deno.cwd().replaceAll("\\", "/")}`).toString();
|
|
||||||
let path:string, resp:Response, text="", json;
|
let path:string, resp:Response, text="", json;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
path = "./deno.json"
|
path = "deno.json"
|
||||||
resp = await fetch(Root + "/" + path);
|
resp = await fetch(Root + "/" + path);
|
||||||
text = await resp.text();
|
text = await resp.text();
|
||||||
}
|
}
|
||||||
@ -14,7 +13,7 @@ export async function HuntConfig()
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
path = "./deno.jsonc";
|
path = "deno.jsonc";
|
||||||
resp = await fetch(Root + "/" + path);
|
resp = await fetch(Root + "/" + path);
|
||||||
text = await resp.text();
|
text = await resp.text();
|
||||||
}
|
}
|
||||||
@ -26,6 +25,7 @@ export async function HuntConfig()
|
|||||||
resp = await fetch(path);
|
resp = await fetch(path);
|
||||||
json = await resp.json();
|
json = await resp.json();
|
||||||
path = json["deno.config"];
|
path = json["deno.config"];
|
||||||
|
json = undefined;
|
||||||
if(path)
|
if(path)
|
||||||
{
|
{
|
||||||
resp = await fetch(Root + "/" + 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<string>
|
||||||
|
{
|
||||||
|
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[])
|
export async function SubProcess(args:string[])
|
||||||
@ -81,5 +92,32 @@ export async function SubProcess(args:string[])
|
|||||||
const status = await child.status;
|
const status = await child.status;
|
||||||
}
|
}
|
||||||
|
|
||||||
const conf = await HuntConfig();
|
const config = await HuntConfig();
|
||||||
console.log(conf);
|
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);
|
@ -8,13 +8,13 @@
|
|||||||
"react":"https://esm.sh/preact@10.15.1/compat",
|
"react":"https://esm.sh/preact@10.15.1/compat",
|
||||||
"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",
|
"react-original":"https://esm.sh/preact@10.15.1/compat",
|
||||||
"able/": "http://localhost:4507/"
|
">able/": "http://localhost:4507/"
|
||||||
},
|
},
|
||||||
"tasks":
|
"tasks":
|
||||||
{
|
{
|
||||||
"local": "deno run -A --reload=http://localhost:4507 --no-lock ./run-local.tsx --port=1234",
|
"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",
|
"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",
|
"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"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
41
install__/deno.jsonc
Normal file
41
install__/deno.jsonc
Normal file
@ -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";
|
||||||
|
...
|
||||||
|
|
||||||
|
*/
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user