ts api for subprocess

This commit is contained in:
Seth Trowbridge 2025-09-03 08:26:52 -04:00
parent c3f6e45a99
commit e0e881a754
3 changed files with 73 additions and 19 deletions

61
scripts/bundle.ts Normal file
View File

@ -0,0 +1,61 @@
export interface DenoBundleOptions {
entry: string;
output?: string;
outdir?: string;
check?: boolean | "all";
noCheck?: boolean | "remote";
frozen?: boolean;
importMap?: string;
lock?: string;
noLock?: boolean;
noNpm?: boolean;
noRemote?: boolean;
nodeModulesDir?: boolean;
reload?: boolean | string[];
vendor?: boolean;
allowImport?: string[];
allowScripts?: string[];
cert?: string;
codeSplitting?: boolean;
conditions?: string[];
config?: string;
denyImport?: string[];
inlineImports?: boolean;
minify?: boolean;
noConfig?: boolean;
packages?: "bundle" | "external";
platform?: "browser" | "deno";
preload?: string[];
sourcemap?: "linked" | "inline" | "external";
watch?: boolean;
}
export default (options: DenoBundleOptions):{ out: string; err: string; }=>
{
const argify =(str: string)=> "--"+str.replace(/[A-Z]/g, (m) => "-" + m.toLowerCase());
const args: string[] = ["bundle"];
const { entry, ...rest } = options;
for (const [key, value] of Object.entries(rest))
{
let flag = argify(key);
if (value !== true)
{
if(!value)
{
continue;
}
flag = flag + "=" + (Array.isArray(value) ? value.join(",") : value);
}
args.push(flag);
}
args.push(entry);
console.log(args);
const command = new Deno.Command("deno", {args});
const result = command.outputSync();
const decode = new TextDecoder("utf-8");
const output = (str:Uint8Array<ArrayBuffer>)=> decode.decode(str).replace(/\x1b\[[0-9;]*m/g,"").replace(/\n+$/, "");
return { out: output(result.stdout), err: output(result.stderr) }
}

View File

@ -1,18 +1,13 @@
const command = new Deno.Command("deno", {
args:[
"bundle",
"--no-lock",
"--platform=browser",
"--inline-imports=true",
"--output=dist/core.js",
"--outdir=dist",
"--minify",
"--code-splitting",
"scripts/bundle_entry.ts"
]
});
const result = command.outputSync();
import Bundler from "./bundle.ts";
const textDecoder = new TextDecoder();
console.log("stdout:", textDecoder.decode(result.stdout));
console.log("stderr:", textDecoder.decode(result.stderr));
const result = Bundler({
entry: "scripts/bundle_entry.ts",
outdir: "dist",
inlineImports: true,
minify: true,
codeSplitting: true,
platform: "browser",
noLock: true,
});
console.log(result);

View File

@ -20,14 +20,12 @@ function Save(key, value)
{
Time = setTimeout(Tick, 500);
}
console.log("SAVE", key, value);
};
/** @type {(key:string)=>string|null} */
function Load(key)
{
const value = sessionStorage.getItem(key);
console.log("LOAD", key, value);
return value;
}