1
0
mirror of https://github.com/jaandrle/deka-dom-el synced 2025-07-01 12:22:15 +02:00

Add compressing and gzip files

This commit is contained in:
2023-11-07 09:53:10 +01:00
parent 4d56fa705e
commit 1195f93bed
7 changed files with 310 additions and 8 deletions

View File

@ -1,11 +1,12 @@
#!/usr/bin/env -S npx nodejsscript
import { bundle as bundleDTS } from "dts-bundler";
import compressing from "compressing";
const files= [ "index", "index-with-signals" ];
const filesOut= (file, mark= "esm")=> "dist/"+file.replace("index", mark);
$.api("", true)
.option("--minify", "Level of minification [ full (default), partial ]")
.action(function main({ minify= "full" }){
.action(async function main({ minify= "full" }){
for(const file_root of files){
const file= file_root+".js";
const out= filesOut(file);
@ -22,17 +23,23 @@ $.api("", true)
f=> f.replace(/^ +/gm, m=> "\t".repeat(m.length/2)),
f=> s.echo(f).to(out)
)(s.cat(out));
const file_gzip_out= filesOut(file_root+".gzip.js");
echo(` ${file_gzip_out}`)
await compressing.gzip.compressFile(out, file_gzip_out);
const file_dts= file_root+".d.ts";
const file_dts_out= filesOut(file_dts);
echo(` ${file_dts_out}`)
s.echo(bundleDTS(file_dts)).to(file_dts_out);
echo("⚡ Done");
toDDE(out, filesOut(file, "dde"));
await toDDE(out, file_root);
}
$.exit(0);
function toDDE(file, out){
async function toDDE(file, file_root){
const name= "dde";
const out= filesOut(file_root+".js", name);
echo(` ${out} (${file} → globalThis.${name})`);
let content= s.cat(file).toString().split(/export ?{/);
@ -44,8 +51,10 @@ $.api("", true)
content.join(""),
"})();"
].join("\n")).to(out);
echo("⚡ Done");
const out_gzip= filesOut(file_root+".gzip.js", name);
echo(` ${out_gzip}`);
await compressing.gzip.compressFile(out, out_gzip);
}
})
.parse();