2024-06-07 16:54:12 -04:00
|
|
|
import { parse as JSONC } from "https://deno.land/x/jsonct@v0.1.0/mod.ts";
|
2024-06-12 17:05:41 -04:00
|
|
|
import { parseArgs } from "jsr:@std/cli/parse-args";
|
|
|
|
|
|
|
|
if(Deno.mainModule == import.meta.url)
|
|
|
|
{
|
|
|
|
serve(parseArgs(Deno.args) as ServeArgs);
|
|
|
|
}
|
2024-06-07 16:54:12 -04:00
|
|
|
|
2024-06-12 14:48:53 -04:00
|
|
|
type JsonLike = { [key: string]: string | string[] | JsonLike; };
|
2024-06-10 16:23:31 -04:00
|
|
|
|
2024-06-12 17:05:41 -04:00
|
|
|
/** A `file://` url version of Deno.cwd() (contains trailing slash) */
|
2024-06-10 16:23:31 -04:00
|
|
|
export const Root = new URL(`file://${Deno.cwd().replaceAll("\\", "/")}`).toString() + "/";
|
2024-06-12 17:05:41 -04:00
|
|
|
export default async function HuntConfig(directory=Root)
|
2024-06-07 16:54:12 -04:00
|
|
|
{
|
|
|
|
let path:string, json:JsonLike|undefined;
|
|
|
|
|
|
|
|
const loadJSON =async(inPath:string)=>{
|
|
|
|
try{
|
2024-06-12 17:05:41 -04:00
|
|
|
const resp = await fetch(directory + inPath);
|
2024-06-07 16:54:12 -04:00
|
|
|
if(inPath.endsWith(".jsonc"))
|
|
|
|
{
|
|
|
|
const text = await resp.text();
|
|
|
|
json = JSONC(text) as JsonLike;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
json = await resp.json();
|
|
|
|
}
|
|
|
|
return json;
|
|
|
|
}
|
|
|
|
catch(_e)
|
|
|
|
{
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
try// look for `deno.json`
|
|
|
|
{
|
|
|
|
json = await loadJSON("deno.json");
|
|
|
|
}
|
|
|
|
catch(_e)
|
|
|
|
{
|
|
|
|
|
|
|
|
try // look for `deno.jsonc`
|
|
|
|
{
|
|
|
|
json = await loadJSON("deno.jsonc");
|
|
|
|
}
|
|
|
|
catch(_e)
|
|
|
|
{
|
|
|
|
try // look in the vscode plugin settings
|
|
|
|
{
|
|
|
|
json = await loadJSON(".vscode/settings.json")
|
|
|
|
path = json ? json["deno.config"] as string : "";
|
|
|
|
json = undefined;
|
|
|
|
if(path)
|
|
|
|
{
|
|
|
|
json = await loadJSON(path)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(_e)
|
|
|
|
{
|
|
|
|
// cant find a config using the vscode plugin
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!json)
|
|
|
|
{
|
|
|
|
json = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
path = json.importMap as string;
|
|
|
|
if(!json.imports && path)
|
|
|
|
{
|
2024-06-12 14:48:53 -04:00
|
|
|
json.imports = await loadJSON(path) as JsonLike;
|
2024-06-07 16:54:12 -04:00
|
|
|
}
|
|
|
|
|
2024-06-12 14:48:53 -04:00
|
|
|
return json as {imports:JsonLike, compilerOptions:JsonLike};
|
2024-06-07 16:54:12 -04:00
|
|
|
|
|
|
|
}
|