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();
|
|
|
|
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 = 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" :
|
|
|
|
{
|
2023-09-24 09:19:50 -04:00
|
|
|
await SubProcess(["run", `-A`, `--no-lock`, `--config=${config.path}`, `--inspect-brk`, 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];
|
|
|
|
console.log("args are", 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
|
|
|
|
|
|
|
let scanProd:string[]|string|null = prompt(`Do you want to deploy to *production*?`);
|
|
|
|
if(scanProd)
|
|
|
|
{
|
|
|
|
scanProd = prompt(`Are you sure? This will update the live project at "${useProject}"`);
|
|
|
|
scanProd = scanProd ? ["--prod"] : [];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
scanProd = [];
|
|
|
|
}
|
|
|
|
|
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-08-10 22:37:53 -04:00
|
|
|
...scanProd,
|
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-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
|
|
|
}
|
|
|
|
}
|