2023-04-24 19:42:49 +00:00
|
|
|
// hook that runs after electron-build
|
|
|
|
|
|
2024-06-20 15:35:28 +02:00
|
|
|
import fs from 'fs-extra';
|
|
|
|
|
import path from 'path';
|
|
|
|
|
import { execSync } from 'child_process';
|
|
|
|
|
import packageJson from '../package.json' assert { type: 'json' };
|
|
|
|
|
import { fileURLToPath } from 'url';
|
|
|
|
|
const rootPath = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
2023-04-24 19:42:49 +00:00
|
|
|
const distFolderPath = path.resolve(rootPath, 'dist');
|
|
|
|
|
|
|
|
|
|
const addPortableToPortableExecutableFileName = () => {
|
|
|
|
|
const files = fs.readdirSync(distFolderPath);
|
|
|
|
|
for (const file of files) {
|
|
|
|
|
if (file.endsWith('.exe') && !file.match('Setup')) {
|
|
|
|
|
const filePath = path.resolve(distFolderPath, file);
|
2023-12-16 16:49:26 +00:00
|
|
|
const renamedFilePath = path.resolve(distFolderPath, file.replace('plebchan', 'plebchan Portable'));
|
2023-04-24 19:42:49 +00:00
|
|
|
fs.moveSync(filePath, renamedFilePath);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const createHtmlArchive = () => {
|
|
|
|
|
if (process.platform !== 'linux') {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const zipBinPath = path.resolve(rootPath, 'node_modules', '7zip-bin', 'linux', 'x64', '7za');
|
2024-06-20 15:35:28 +02:00
|
|
|
const plebchanHtmlFolderName = `plebchan-html-${packageJson.version}`;
|
2023-04-24 19:42:49 +00:00
|
|
|
const outputFile = path.resolve(distFolderPath, `${plebchanHtmlFolderName}.zip`);
|
|
|
|
|
const inputFolder = path.resolve(rootPath, 'build');
|
|
|
|
|
try {
|
|
|
|
|
// will break if node_modules/7zip-bin changes
|
|
|
|
|
execSync(`${zipBinPath} a ${outputFile} ${inputFolder}`);
|
|
|
|
|
// rename 'build' folder to 'plebchan-html-version' inside the archive
|
|
|
|
|
execSync(`${zipBinPath} rn -r ${outputFile} build ${plebchanHtmlFolderName}`);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
e.message = 'electron build createHtmlArchive error: ' + e.message;
|
|
|
|
|
console.log(e);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2024-06-20 15:35:28 +02:00
|
|
|
export default async (buildResult) => {
|
2023-04-24 19:42:49 +00:00
|
|
|
addPortableToPortableExecutableFileName();
|
|
|
|
|
createHtmlArchive();
|
|
|
|
|
};
|