ts api for subprocess
This commit is contained in:
parent
c3f6e45a99
commit
e0e881a754
61
scripts/bundle.ts
Normal file
61
scripts/bundle.ts
Normal 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) }
|
||||||
|
}
|
@ -1,18 +1,13 @@
|
|||||||
const command = new Deno.Command("deno", {
|
import Bundler from "./bundle.ts";
|
||||||
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();
|
|
||||||
|
|
||||||
const textDecoder = new TextDecoder();
|
const result = Bundler({
|
||||||
console.log("stdout:", textDecoder.decode(result.stdout));
|
entry: "scripts/bundle_entry.ts",
|
||||||
console.log("stderr:", textDecoder.decode(result.stderr));
|
outdir: "dist",
|
||||||
|
inlineImports: true,
|
||||||
|
minify: true,
|
||||||
|
codeSplitting: true,
|
||||||
|
platform: "browser",
|
||||||
|
noLock: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(result);
|
@ -20,14 +20,12 @@ function Save(key, value)
|
|||||||
{
|
{
|
||||||
Time = setTimeout(Tick, 500);
|
Time = setTimeout(Tick, 500);
|
||||||
}
|
}
|
||||||
console.log("SAVE", key, value);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/** @type {(key:string)=>string|null} */
|
/** @type {(key:string)=>string|null} */
|
||||||
function Load(key)
|
function Load(key)
|
||||||
{
|
{
|
||||||
const value = sessionStorage.getItem(key);
|
const value = sessionStorage.getItem(key);
|
||||||
console.log("LOAD", key, value);
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user