2025-03-23 23:22:22 +02:00
|
|
|
const child_process = require("child_process");
|
2025-04-27 23:47:51 +03:00
|
|
|
const fs = require("fs");
|
2025-04-28 20:51:44 +03:00
|
|
|
const path = require("path");
|
2025-03-23 23:22:22 +02:00
|
|
|
|
2025-05-01 20:45:04 +03:00
|
|
|
function sign(sourcePath) {
|
2025-03-24 17:00:37 +02:00
|
|
|
const { WINDOWS_SIGN_EXECUTABLE } = process.env;
|
|
|
|
if (!WINDOWS_SIGN_EXECUTABLE) {
|
|
|
|
console.warn("[Sign] Skip signing due to missing environment variable.");
|
|
|
|
return;
|
2025-04-28 21:57:48 +03:00
|
|
|
}
|
2025-04-27 23:47:51 +03:00
|
|
|
|
2025-04-28 20:09:27 +03:00
|
|
|
try {
|
2025-04-28 21:23:42 +03:00
|
|
|
const command = `${WINDOWS_SIGN_EXECUTABLE} --executable "${sourcePath}"`;
|
|
|
|
console.log(`[Sign] ${command}`);
|
2025-04-28 20:09:27 +03:00
|
|
|
child_process.execSync(command);
|
|
|
|
} catch (e) {
|
2025-04-28 20:20:16 +03:00
|
|
|
console.error("[Sign] Got error while signing " + e.output.toString("utf-8"));
|
2025-05-01 20:45:04 +03:00
|
|
|
printSigningErrorLogs();
|
2025-04-28 20:51:44 +03:00
|
|
|
process.exit(2);
|
2025-04-28 20:09:27 +03:00
|
|
|
}
|
2025-04-28 21:23:42 +03:00
|
|
|
}
|
|
|
|
|
2025-05-01 20:45:04 +03:00
|
|
|
function printSigningErrorLogs() {
|
|
|
|
const logLocation = path.join(path.dirname(WINDOWS_SIGN_EXECUTABLE), "ev_signer_trilium.err.log");
|
2025-04-28 21:57:48 +03:00
|
|
|
|
2025-05-01 20:45:04 +03:00
|
|
|
if (!fs.existsSync(logLocation)) {
|
2025-04-28 21:57:48 +03:00
|
|
|
console.warn("[Sign] No debug log file found.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2025-05-01 20:45:04 +03:00
|
|
|
const logContent = fs.readFileSync(logLocation, "utf-8");
|
2025-04-28 21:57:48 +03:00
|
|
|
console.error("[Sign] Debug log content:\n" + logContent);
|
|
|
|
}
|
|
|
|
|
2025-05-01 20:45:04 +03:00
|
|
|
module.exports = sign;
|