Compare commits

..

No commits in common. "8d89cebe12c7ce9454aac87f5566252e3c160307" and "67b2eef7ae889fada4908dad792679153fa33b09" have entirely different histories.

5 changed files with 127 additions and 119 deletions

22
cli.tsx
View File

@ -4,7 +4,7 @@ import { RootHost, HuntConfig, Install, Check } from "./checker.tsx";
let arg = await Arg.parse(Deno.args);
let env = await Env.load();
const collect =(inKey:string, inArg:Record<string, string>, inEnv:Record<string, string>):string|undefined=>
const collect =async(inKey:string, inArg:Record<string, string>, inEnv:Record<string, string>):Promise<string|undefined>=>
{
const scanArg = inArg[inKey];
const scanEnvFile = inEnv[inKey];
@ -93,6 +93,7 @@ if(arg._.length)
case "serve" :
{
const args = ["run", `-A`, `--no-lock`, `--config=${config.path}`, RootHost+"run.tsx", ...Deno.args];
console.log("args are", args);
await SubProcess(args);
break;
}
@ -101,12 +102,15 @@ if(arg._.length)
const useToken = await collect("DENO_DEPLOY_TOKEN", arg, env);
const useProject = await collect("DENO_DEPLOY_PROJECT", arg, env);
let scanProd = confirm(`Do you want to deploy to *production*?`);
let argProd:string[] = [];
let scanProd:string[]|string|null = prompt(`Do you want to deploy to *production*?`);
if(scanProd)
{
scanProd = confirm(`Are you sure? This will update the live project at "${useProject}"`);
argProd = scanProd ? ["--prod"] : [];
scanProd = prompt(`Are you sure? This will update the live project at "${useProject}"`);
scanProd = scanProd ? ["--prod"] : [];
}
else
{
scanProd = [];
}
const command = [
@ -120,19 +124,13 @@ if(arg._.length)
`--token=${useToken}`,
`--import-map=${imports.path}`,
`--exclude=.*,.*/,`,
...argProd,
...scanProd,
RootHost+"run.tsx"];
await SubProcess(command);
break;
}
case "baker" :
{
const args = ["run", `-A`, `--no-lock`, `--config=${config.path}`, RootHost+"run.tsx", ...Deno.args];
await SubProcess(args);
break;
}
case "upgrade" :
{
await SubProcess(["install", `-A`, `-r`, `-f`, `--no-lock`, `--config=${config.path}`, RootHost+"cli.tsx", ...Deno.args]);

View File

@ -1,103 +0,0 @@
import { walk, type WalkOptions, ensureFile } from "https://deno.land/std@0.204.0/fs/mod.ts";
import ts, { isAssertEntry } from "npm:typescript";
const tsopts:ts.CompilerOptions = { declaration: true, emitDeclarationOnly: true };
const tshost = ts.createCompilerHost(tsopts);
const tstypes =(fileName: string):string=> {
let output = "";
tshost.writeFile = (fileName: string, contents: string) => output = contents;
ts.createProgram([fileName], tsopts, tshost).emit();
return output;
}
const tstypes_all =(fileNames: string[]):string[]=> {
const output:string[] = [];
tshost.writeFile = (fileName: string, contents: string) => output[fileName.indexOf(fileName)] = contents;
ts.createProgram(fileNames, tsopts, tshost).emit();
return output;
}
import * as SWCW from "https://esm.sh/@swc/wasm-web@1.3.62";
await SWCW.default();
const options:SWCW.Options = {
sourceMaps: false,
minify: true,
jsc:
{
target:"es2022",
minify:
{
compress: { unused: true },
mangle: false
},
parser:
{
syntax: "typescript",
tsx: true,
},
transform:
{
react: { runtime: "automatic" }
}
}
}
const dir = Deno.cwd();
const folder = dir.substring(dir.lastIndexOf("\\")+1);
console.log("searching", dir);
const extensions = ["tsx", "ts", "jsx", "js"]
for await(const file of walk(dir, {includeDirs:false}))
{
const pathClean = file.path.replaceAll("\\", "/");
const pathRel = pathClean.substring(dir.length);
if(!pathRel.startsWith(".") && !pathRel.includes("/."))
{
const extension = file.name.substring(file.name.lastIndexOf(".")+1);
const pathBake = `.bake${pathRel}`;
if(extensions.includes(extension))
{
const pathDTS = pathBake.substring(0, pathBake.lastIndexOf("."))+".d.ts";
console.log("processing", pathRel);
const text = await Deno.readTextFile(pathClean);
const {code} = await SWCW.transform(text, { ...options, filename:file.name});
// check for types export directive
let tripleSlash = "";
const read = await Deno.open(file.path);
const buffer = new Uint8Array(256); // Set the buffer size to the maximum line length
try {
const bytesRead = await read.read(buffer);
if(bytesRead)
{
if(new TextDecoder().decode(buffer.subarray(0, bytesRead)).indexOf("@able-types") != -1)
{
tripleSlash =`/// <reference types=".${pathDTS.substring(pathDTS.lastIndexOf("/"))}" />\n`;
}
}
} finally {
read.close();
}
await ensureFile(pathBake);
await Deno.writeTextFile(pathBake, tripleSlash+code);
if(tripleSlash)
{
console.log("making types")
await ensureFile(pathDTS);
await Deno.writeTextFile(pathDTS, tstypes("."+pathRel));
}
}
else
{
await Deno.copyFile("."+pathRel, pathBake);
}
}
}

106
run-deploy.tsx Normal file
View File

@ -0,0 +1,106 @@
import * as Env from "https://deno.land/std@0.194.0/dotenv/mod.ts";
import { parse } from "https://deno.land/std@0.194.0/flags/mod.ts";
const collect =async(inKey:string, inArg:Record<string, string>, inEnv:Record<string, string>):Promise<string|undefined>=>
{
const scanArg = inArg[inKey];
const scanEnvFile = inEnv[inKey];
const scanEnvDeno = Deno.env.get(inKey);
if(scanArg)
{
console.log(`Using "${inKey}" from passed argument.`);
return scanArg;
}
if(scanEnvFile)
{
console.log(`Using "${inKey}" from .env file.`);
return scanEnvFile;
}
if(scanEnvDeno)
{
console.log(`Using "${inKey}" from environment variable.`);
return scanEnvDeno;
}
const scanUser = await prompt(`No "${inKey}" found. Enter one here:`);
if(!scanUser || scanUser?.length < 3)
{
console.log("Exiting...");
Deno.exit();
}
return scanUser;
};
const prompt =async(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");
};
try
{
console.log("Runing deploy!", Deno.mainModule);
let arg = parse(Deno.args);
let env = await Env.load();
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`,
{
args:[
"run",
"-A",
"--no-lock",
"https://deno.land/x/deploy/deployctl.ts",
"deploy",
`--project=${useProject}`,
`--import-map=./deno.json`,
`--token=${useToken}`,
...scanProd,
Deno.mainModule
],
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<void> {
Deno.stdout.write(chunk);
return Promise.resolve();
},
});
child.stdout.pipeTo(writableStream);
// manually close stdin
child.stdin.close();
const status = await child.status;
}
catch(e)
{
console.error(e);
}

View File

@ -92,7 +92,7 @@ let Configuration:Configuration =
minify:
{
compress: { unused: true },
mangle: false
mangle: true
},
parser:
{

13
run.tsx
View File

@ -20,8 +20,15 @@ export default function(config:Serve.ConfigurationArgs)
}
}
if(isDevelop)
if(isDeploy)
{
await import("./run-local.tsx");
import("./run-deploy.tsx");
}
else
{
if(isDevelop)
{
await import("./run-local.tsx");
}
Serve.default();
}
Serve.default();