Spaces:
Sleeping
Sleeping
File size: 2,435 Bytes
7aec436 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
const {downloadArtifact} = require('@electron/get');
const rcedit = require('rcedit');
const path = require('path');
const fs = require('fs');
const zlib = require('zlib');
const rimraf = require('rimraf');
const extractZip = require('extract-zip');
const archiver = require('archiver');
const crypto = require('crypto');
const {electronVersion} = require('./version.json');
const newIconPath = path.join(__dirname, '../src/packager/images/default-icon.ico');
const download = (arch) => downloadArtifact({
version: electronVersion,
artifactName: 'electron',
platform: 'win32',
arch
});
const getTempFile = (name) => path.join(__dirname, 'temp/windows', name);
const extract = async (from, name) => {
const to = getTempFile(name);
fs.mkdirSync(path.join(to, '..'), {recursive: true});
rimraf.sync(to);
await extractZip(from, {dir: to});
return to;
};
const compress = (from, to) => new Promise((resolve, reject) => {
const archive = archiver('zip', {
zlib: {
level: zlib.constants.Z_BEST_COMPRESSION
}
});
const outStream = fs.createWriteStream(to);
outStream.on('error', (err) => reject(err));
outStream.on('close', () => resolve());
archive.directory(from, false);
archive.pipe(outStream);
archive.finalize();
});
const run = async (arch) => {
console.log(`Downloading ${arch}`);
const downloadPath = await download(arch);
console.log('Extracting');
const extractedPath = await extract(downloadPath, arch);
console.log('Running rcedit');
const executablePath = path.join(extractedPath, 'electron.exe');
await rcedit(executablePath, {
icon: newIconPath,
// Replace Electron's version with something generic
'version-string': '1.0.0',
'file-version': '1.0.0',
'product-version': '1.0.0'
});
console.log('Compressing');
const outputPath = getTempFile(`electron-v${electronVersion}-win32-${arch}.zip`);
await compress(extractedPath, outputPath);
console.log(`Output: ${outputPath}`);
const outputFileData = fs.readFileSync(outputPath);
console.log(`Size: ${outputFileData.length} bytes`)
const sha256 = crypto.createHash('sha256').update(outputFileData).digest('hex');
console.log(`SHA-256: ${sha256}`);
};
run('ia32')
.then(() => run('x64'))
.then(() => run('arm64'))
.catch((err) => {
console.error(err);
process.exit(1);
});
|