diff --git a/scripts/bundle.ts b/scripts/bundle.ts new file mode 100644 index 0000000..4379ab3 --- /dev/null +++ b/scripts/bundle.ts @@ -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)=> decode.decode(str).replace(/\x1b\[[0-9;]*m/g,"").replace(/\n+$/, ""); + return { out: output(result.stdout), err: output(result.stderr) } +} \ No newline at end of file diff --git a/scripts/bundle_subprocess.ts b/scripts/bundle_subprocess.ts index a49177e..7711e3f 100644 --- a/scripts/bundle_subprocess.ts +++ b/scripts/bundle_subprocess.ts @@ -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)); \ No newline at end of file +const result = Bundler({ + entry: "scripts/bundle_entry.ts", + outdir: "dist", + inlineImports: true, + minify: true, + codeSplitting: true, + platform: "browser", + noLock: true, +}); + +console.log(result); \ No newline at end of file diff --git a/src/hmr.js b/src/hmr.js index 844fd1d..b5735da 100644 --- a/src/hmr.js +++ b/src/hmr.js @@ -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; }