bzl

self-hosted ephemeral community engine
Log | Files | Refs | README | LICENSE

build-clean-install-zip.js (1712B)


      1 const fs = require("fs");
      2 const path = require("path");
      3 const AdmZip = require("adm-zip");
      4 
      5 const ROOT = path.join(__dirname, "..");
      6 const SRC = path.join(ROOT, "CLEAN_INSTALL");
      7 const OUT_DIR = path.join(ROOT, "dist");
      8 
      9 function readPkgVersion() {
     10   try {
     11     const pkg = JSON.parse(fs.readFileSync(path.join(ROOT, "package.json"), "utf8"));
     12     return String(pkg?.version || "0.0.0").trim() || "0.0.0";
     13   } catch {
     14     return "0.0.0";
     15   }
     16 }
     17 
     18 function shouldSkip(rel) {
     19   const r = rel.replace(/\\/g, "/");
     20   if (!r) return false;
     21   if (r.startsWith(".git/")) return true;
     22   if (r.startsWith("node_modules/")) return true;
     23   if (r.startsWith("data/")) return true;
     24   if (r.startsWith("dist/") && !r.startsWith("dist/plugins/")) return true;
     25   if (r.endsWith(".log")) return true;
     26   return false;
     27 }
     28 
     29 function walk(dir, baseRel = "") {
     30   const out = [];
     31   const items = fs.readdirSync(dir, { withFileTypes: true });
     32   for (const it of items) {
     33     const abs = path.join(dir, it.name);
     34     const rel = path.join(baseRel, it.name);
     35     if (shouldSkip(rel)) continue;
     36     if (it.isDirectory()) out.push(...walk(abs, rel));
     37     else if (it.isFile()) out.push({ abs, rel });
     38   }
     39   return out;
     40 }
     41 
     42 function main() {
     43   if (!fs.existsSync(SRC)) {
     44     console.error("Missing CLEAN_INSTALL directory.");
     45     process.exit(1);
     46   }
     47   fs.mkdirSync(OUT_DIR, { recursive: true });
     48 
     49   const version = readPkgVersion();
     50   const outPath = path.join(OUT_DIR, `Bzl-CLEAN_INSTALL-v${version}.zip`);
     51 
     52   const zip = new AdmZip();
     53   const files = walk(SRC, "");
     54   for (const f of files) {
     55     zip.addLocalFile(f.abs, path.dirname(f.rel), path.basename(f.rel));
     56   }
     57   zip.writeZip(outPath);
     58 
     59   console.log(`Built: ${outPath}`);
     60 }
     61 
     62 main();
     63