| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- 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);
- });
|