2023-09-05 09:25:47 +02:00
|
|
|
#!/usr/bin/env -S npx nodejsscript
|
2023-10-19 15:01:54 +02:00
|
|
|
import { bundle as bundleDTS } from "dts-bundler";
|
|
|
|
const files= [ "index", "index-with-signals" ];
|
2023-09-05 09:25:47 +02:00
|
|
|
const filesOut= (file, mark= "esm")=> "dist/"+file.replace("index", mark);
|
|
|
|
|
2023-10-19 14:23:10 +02:00
|
|
|
$.api("", true)
|
|
|
|
.option("--minify", "Level of minification [ full (default), partial ]")
|
|
|
|
.action(function main({ minify= "full" }){
|
2023-10-19 15:01:54 +02:00
|
|
|
for(const file_root of files){
|
|
|
|
const file= file_root+".js";
|
2023-10-19 14:23:10 +02:00
|
|
|
const out= filesOut(file);
|
|
|
|
s.run([
|
|
|
|
"npx esbuild '::file::'",
|
|
|
|
"--platform=neutral",
|
|
|
|
"--bundle",
|
|
|
|
minify==="full" ? "--minify" : "--minify-syntax --minify-identifiers",
|
|
|
|
"--legal-comments=inline",
|
|
|
|
"--packages=external",
|
|
|
|
"--outfile='::out::'"
|
|
|
|
].join(" "), { file, out });
|
|
|
|
pipe(
|
|
|
|
f=> f.replace(/^ +/gm, m=> "\t".repeat(m.length/2)),
|
|
|
|
f=> s.echo(f).to(out)
|
|
|
|
)(s.cat(out));
|
2023-10-19 15:01:54 +02:00
|
|
|
const file_dts= file_root+".d.ts";
|
2023-10-19 15:28:44 +02:00
|
|
|
const file_dts_out= filesOut(file_dts);
|
|
|
|
echo(` ${file_dts_out}`)
|
|
|
|
s.echo(bundleDTS(file_dts)).to(file_dts_out);
|
|
|
|
echo("⚡ Done");
|
2023-10-19 14:23:10 +02:00
|
|
|
toDDE(out, filesOut(file, "dde"));
|
|
|
|
}
|
|
|
|
$.exit(0);
|
2023-09-05 09:25:47 +02:00
|
|
|
|
2023-10-19 14:23:10 +02:00
|
|
|
function toDDE(file, out){
|
|
|
|
const name= "dde";
|
2023-10-19 15:28:44 +02:00
|
|
|
echo(` ${out} (${file} → globalThis.${name})`);
|
2023-10-19 14:23:10 +02:00
|
|
|
|
|
|
|
let content= s.cat(file).toString().split(/export ?{/);
|
|
|
|
content.splice(1, 0, `\nglobalThis.${name}= {`);
|
|
|
|
content[2]= content[2].replace(/,(?!\n)/g, ",\n").replace(/(?<!\n)}/, "\n}").replace(/^(\t*)(.*) as ([^,\n]*)(,?)$/mg, "$1$3: $2$4");
|
|
|
|
s.echo([
|
|
|
|
`//deka-dom-el library is available via global namespace \`${name}\``,
|
|
|
|
"(()=> {",
|
|
|
|
content.join(""),
|
|
|
|
"})();"
|
|
|
|
].join("\n")).to(out);
|
|
|
|
|
2023-10-19 15:28:44 +02:00
|
|
|
echo("⚡ Done");
|
2023-10-19 14:23:10 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.parse();
|