const MIN_NODE_VERSION = 12; const [major] = process.versions.node.split(".").map(Number); if (major < MIN_NODE_VERSION) { console.log( `[skip] Node v${process.versions.node} < v${MIN_NODE_VERSION}, skipping copy+zip step` ); process.exit(0); } const fs = require("fs"); const path = require("path"); const root = path.join(__dirname, ".."); const src = path.join(root, "buildAnnexation"); const dest = path.join(root, "yos"); function copyDir(srcDir, destDir) { fs.mkdirSync(destDir, { recursive: true }); const entries = fs.readdirSync(srcDir, { withFileTypes: true }); for (const entry of entries) { const srcPath = path.join(srcDir, entry.name); const destPath = path.join(destDir, entry.name); if (entry.isDirectory()) { copyDir(srcPath, destPath); } else { fs.copyFileSync(srcPath, destPath); } } } function zipDir(dir, zipPath) { return new Promise((resolve, reject) => { try { const archiver = require("archiver"); const output = fs.createWriteStream(zipPath); const archive = archiver("zip", { zlib: { level: 1 } }); output.on("close", resolve); archive.on("error", reject); archive.pipe(output); archive.directory(dir, false); archive.finalize(); } catch (err) { reject(err); } }); } async function main() { // 1. copy buildAnnexation into yos const entries = fs.readdirSync(src, { withFileTypes: true }); for (const entry of entries) { const srcPath = path.join(src, entry.name); const destPath = path.join(dest, entry.name); if (entry.isDirectory()) { copyDir(srcPath, destPath); } else { fs.copyFileSync(srcPath, destPath); } console.log("copied:", entry.name); } console.log("buildAnnexation -> yos done"); // 2. zip yos/ contents (without the yos folder itself) const zipPath = path.join(root, "yos.zip"); try { await zipDir(dest, zipPath); console.log("zip: yos.zip created"); } catch (err) { console.log("[skip] archiver not available, skipping zip step"); } } main().catch((err) => { console.error(err); process.exit(1); });