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)=> decode.decode(str).replace(/\x1b\[[0-9;]*m/g,"").replace(/\n+$/, ""); return { out: output(result.stdout), err: output(result.stderr) } }