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