2020-07-03 23:46:20 +02:00
|
|
|
const fs = require('fs');
|
|
|
|
const path = require('path');
|
|
|
|
const os = require('os');
|
|
|
|
const sha512 = require('js-sha512');
|
2024-08-31 16:42:07 +02:00
|
|
|
const distDirName = 'dist';
|
|
|
|
const distPath = path.join(__dirname, distDirName);
|
2020-07-03 23:46:20 +02:00
|
|
|
|
|
|
|
const generateChecksumFile = () => {
|
2022-07-23 09:31:32 +02:00
|
|
|
if (os.platform() !== 'linux') {
|
2020-07-03 23:46:20 +02:00
|
|
|
return []; // SHA-512 is only for AppImage
|
|
|
|
}
|
2024-08-31 16:42:07 +02:00
|
|
|
|
2020-07-03 23:46:20 +02:00
|
|
|
let appImageName = '';
|
|
|
|
const files = fs.readdirSync(distPath);
|
|
|
|
for (const key in files) {
|
|
|
|
const filename = files[key];
|
|
|
|
if (filename.includes('AppImage')) {
|
|
|
|
appImageName = filename;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2022-07-23 09:31:32 +02:00
|
|
|
if (appImageName === '') {
|
2024-04-25 14:32:37 +02:00
|
|
|
throw new Error('AppImage not found!');
|
2020-07-03 23:46:20 +02:00
|
|
|
}
|
|
|
|
const appImagePath = path.join(distPath, appImageName);
|
|
|
|
const appImageContent = fs.readFileSync(appImagePath);
|
|
|
|
const checksum = sha512.sha512(appImageContent);
|
|
|
|
const sha512FileName = `${appImageName}.sha512`;
|
|
|
|
const sha512FilePath = path.join(distPath, sha512FileName);
|
|
|
|
fs.writeFileSync(sha512FilePath, checksum);
|
|
|
|
return [sha512FilePath];
|
|
|
|
};
|
|
|
|
|
2024-08-31 16:42:07 +02:00
|
|
|
const mainHook = () => {
|
|
|
|
generateChecksumFile();
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.default = mainHook;
|