feat(build): replace execSync with spawnSync for building backend and add integrity manifest generation for build files
This commit is contained in:
@@ -1,8 +1,57 @@
|
|||||||
#!/usr/bin/env node
|
#!/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 {
|
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) {
|
} catch (error) {
|
||||||
console.error("Build failed:", error.message);
|
console.error("Build failed:", error.message);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
|
|||||||
Reference in New Issue
Block a user