From 54b81663bd17b836c29ae308d6c297c31411f200 Mon Sep 17 00:00:00 2001 From: Sudo-Ivan Date: Sat, 3 Jan 2026 16:07:25 -0600 Subject: [PATCH] feat(build): replace execSync with spawnSync for building backend and add integrity manifest generation for build files --- scripts/build-backend.js | 53 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/scripts/build-backend.js b/scripts/build-backend.js index f43c168..c6a9202 100755 --- a/scripts/build-backend.js +++ b/scripts/build-backend.js @@ -1,8 +1,57 @@ #!/usr/bin/env node -const { execSync } = require("child_process"); +const { spawnSync } = require("child_process"); +const fs = require("fs"); +const path = require("path"); +const crypto = require("crypto"); + +function getFiles(dir, fileList = []) { + const files = fs.readdirSync(dir); + for (const file of files) { + const name = path.join(dir, file); + if (fs.statSync(name).isDirectory()) { + getFiles(name, fileList); + } else { + fileList.push(name); + } + } + return fileList; +} + +function generateManifest(buildDir, manifestPath) { + console.log("Generating backend integrity manifest..."); + const files = getFiles(buildDir); + const manifest = {}; + + for (const file of files) { + const relativePath = path.relative(buildDir, file); + const fileBuffer = fs.readFileSync(file); + const hash = crypto.createHash("sha256").update(fileBuffer).digest("hex"); + manifest[relativePath] = hash; + } + + fs.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2)); + console.log(`Manifest saved to ${manifestPath} (${Object.keys(manifest).length} files)`); +} + try { - execSync(`poetry run python cx_setup.py build`, { stdio: "inherit" }); + console.log("Building backend with cx_Freeze..."); + const result = spawnSync("poetry", ["run", "python", "cx_setup.py", "build"], { stdio: "inherit", shell: false }); + if (result.error) { + throw result.error; + } + if (result.status !== 0) { + process.exit(result.status || 1); + } + + const buildDir = path.join(__dirname, "..", "build", "exe"); + const manifestPath = path.join(__dirname, "..", "electron", "backend-manifest.json"); + + if (fs.existsSync(buildDir)) { + generateManifest(buildDir, manifestPath); + } else { + console.error("Build directory not found, manifest generation skipped."); + } } catch (error) { console.error("Build failed:", error.message); process.exit(1);