2023-08-10 22:37:53 -04:00
|
|
|
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";
|
2023-08-12 20:30:44 -04:00
|
|
|
import { RootHost, HuntConfig, Install, Check } from "./checker.tsx";
|
|
|
|
|
2023-08-10 22:37:53 -04:00
|
|
|
let arg = await Arg.parse(Deno.args);
|
|
|
|
let env = await Env.load();
|
2023-11-06 15:45:47 -05:00
|
|
|
const collect =(inKey:string, inArg:Record<string, string>, inEnv:Record<string, string>):string|undefined=>
|
2023-08-10 22:37:53 -04:00
|
|
|
{
|
|
|
|
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 = prompt(`No "${inKey}" found. Enter one here:`);
|
|
|
|
if(!scanUser || scanUser?.length < 3)
|
|
|
|
{
|
|
|
|
console.log("Exiting...");
|
|
|
|
Deno.exit();
|
|
|
|
}
|
|
|
|
return scanUser;
|
|
|
|
};
|
|
|
|
|
2023-08-01 10:19:39 -04:00
|
|
|
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<void> {
|
|
|
|
Deno.stdout.write(chunk);
|
|
|
|
return Promise.resolve();
|
|
|
|
},
|
|
|
|
});
|
|
|
|
child.stdout.pipeTo(writableStream);
|
|
|
|
|
|
|
|
// manually close stdin
|
|
|
|
child.stdin.close();
|
|
|
|
const status = await child.status;
|
2023-08-28 22:16:56 -04:00
|
|
|
|
|
|
|
return status;
|
2023-08-01 10:19:39 -04:00
|
|
|
}
|
|
|
|
|
2023-08-10 22:37:53 -04:00
|
|
|
if(arg._.length)
|
2023-08-01 17:23:19 -04:00
|
|
|
{
|
2023-08-10 22:37:53 -04:00
|
|
|
|
|
|
|
const [config, imports] = await HuntConfig();
|
2023-09-24 09:19:50 -04:00
|
|
|
|
|
|
|
console.log("able subprocesses running with ", config.path);
|
|
|
|
|
2023-08-10 22:37:53 -04:00
|
|
|
switch(arg._[0])
|
|
|
|
{
|
2023-08-28 22:16:56 -04:00
|
|
|
case "check" :
|
|
|
|
case "setup" :
|
|
|
|
{
|
|
|
|
await Check();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "local" :
|
2023-08-10 22:37:53 -04:00
|
|
|
{
|
2023-09-24 09:19:50 -04:00
|
|
|
await SubProcess(["run", `-A`, `--no-lock`, `--config=${config.path}`, RootHost+"run.tsx", "--dev", ...Deno.args]);
|
2023-08-28 22:16:56 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "debug" :
|
|
|
|
{
|
2024-04-23 12:44:22 -04:00
|
|
|
await SubProcess(["run", `-A`, `--no-lock`, `--config=${config.path}`, `--inspect-wait=127.0.0.1:9230`, RootHost+"run.tsx", "--dev", ...Deno.args]);
|
2023-08-28 22:16:56 -04:00
|
|
|
break;
|
2023-08-10 22:37:53 -04:00
|
|
|
}
|
2023-08-28 22:16:56 -04:00
|
|
|
case "serve" :
|
2023-08-10 22:37:53 -04:00
|
|
|
{
|
2023-09-24 09:19:50 -04:00
|
|
|
const args = ["run", `-A`, `--no-lock`, `--config=${config.path}`, RootHost+"run.tsx", ...Deno.args];
|
|
|
|
await SubProcess(args);
|
2023-08-28 22:16:56 -04:00
|
|
|
break;
|
2023-08-10 22:37:53 -04:00
|
|
|
}
|
2023-08-28 22:16:56 -04:00
|
|
|
case "cloud" :
|
2023-08-10 22:37:53 -04:00
|
|
|
{
|
2023-10-16 13:29:10 -04:00
|
|
|
const useToken = await collect("DENO_DEPLOY_TOKEN", arg, env);
|
|
|
|
const useProject = await collect("DENO_DEPLOY_PROJECT", arg, env);
|
2023-08-10 22:37:53 -04:00
|
|
|
|
2023-11-06 15:45:47 -05:00
|
|
|
let scanProd = confirm(`Do you want to deploy to *production*?`);
|
|
|
|
let argProd:string[] = [];
|
2023-08-10 22:37:53 -04:00
|
|
|
if(scanProd)
|
|
|
|
{
|
2023-11-06 15:45:47 -05:00
|
|
|
scanProd = confirm(`Are you sure? This will update the live project at "${useProject}"`);
|
|
|
|
argProd = scanProd ? ["--prod"] : [];
|
2023-08-10 22:37:53 -04:00
|
|
|
}
|
|
|
|
|
2023-10-16 13:29:10 -04:00
|
|
|
const command = [
|
2023-08-10 22:37:53 -04:00
|
|
|
"run",
|
|
|
|
"-A",
|
|
|
|
"--no-lock",
|
|
|
|
`--config=${config.path}`,
|
|
|
|
"https://deno.land/x/deploy/deployctl.ts",
|
|
|
|
"deploy",
|
|
|
|
`--project=${useProject}`,
|
|
|
|
`--token=${useToken}`,
|
|
|
|
`--import-map=${imports.path}`,
|
2023-10-16 13:29:10 -04:00
|
|
|
`--exclude=.*,.*/,`,
|
2023-11-06 15:45:47 -05:00
|
|
|
...argProd,
|
2023-10-16 13:29:10 -04:00
|
|
|
RootHost+"run.tsx"];
|
|
|
|
|
|
|
|
await SubProcess(command);
|
2023-10-16 10:27:22 -04:00
|
|
|
|
|
|
|
break;
|
2023-08-10 22:37:53 -04:00
|
|
|
}
|
2023-11-06 15:45:47 -05:00
|
|
|
case "baker" :
|
|
|
|
{
|
2023-11-06 17:05:40 -05:00
|
|
|
const args = ["run", `-A`, `--no-lock`, `--config=${config.path}`, RootHost+"run-baker.tsx", ...Deno.args];
|
2023-11-06 15:45:47 -05:00
|
|
|
await SubProcess(args);
|
|
|
|
break;
|
|
|
|
}
|
2023-09-24 09:19:50 -04:00
|
|
|
case "upgrade" :
|
|
|
|
{
|
|
|
|
await SubProcess(["install", `-A`, `-r`, `-f`, `--no-lock`, `--config=${config.path}`, RootHost+"cli.tsx", ...Deno.args]);
|
|
|
|
break;
|
|
|
|
}
|
2023-08-10 22:37:53 -04:00
|
|
|
}
|
|
|
|
}
|