|
| 1 | +// Based on: https://github.com/atom/atom/blob/v1.51.0/script/redownload-electron-bins.js |
| 2 | + |
| 3 | +let downloadMksnapshotPath |
| 4 | + |
| 5 | +try { |
| 6 | + downloadMksnapshotPath = require.resolve('electron-mksnapshot/download-mksnapshot.js'); |
| 7 | +} catch { } |
| 8 | + |
| 9 | +if (typeof(downloadMksnapshotPath) !== 'undefined') { |
| 10 | + |
| 11 | + const { spawn } = require('child_process'); |
| 12 | + const path = require('path'); |
| 13 | + const fs = require('fs'); |
| 14 | + |
| 15 | + const atomRepoPath = path.join('..', '..', '..', '..', 'atom', 'package.json'); |
| 16 | + const electronVersion = fs.existsSync(atomRepoPath) ? require(atomrepoPath).electronVersion : '6.1.12' |
| 17 | + // TODO: Keep the above "electronVersion" in sync with "electronVersion" from Atom's package.json |
| 18 | + |
| 19 | + if (process.env.ELECTRON_CUSTOM_VERSION !== electronVersion) { |
| 20 | + const electronEnv = process.env.ELECTRON_CUSTOM_VERSION; |
| 21 | + console.info( |
| 22 | + `env var ELECTRON_CUSTOM_VERSION is not set,\n` + |
| 23 | + `or doesn't match electronVersion in atom/package.json.\n` + |
| 24 | + `(is: "${electronEnv}", wanted: "${electronVersion}").\n` + |
| 25 | + `Setting, and re-downloading mksnapshot.\n` |
| 26 | + ); |
| 27 | + |
| 28 | + process.env.ELECTRON_CUSTOM_VERSION = electronVersion; |
| 29 | + const downloadMksnapshot = spawn('node', [downloadMksnapshotPath]); |
| 30 | + var exitStatus; |
| 31 | + |
| 32 | + downloadMksnapshot.on('close', code => { |
| 33 | + if (code === 0) { |
| 34 | + exitStatus = 'success'; |
| 35 | + } else { |
| 36 | + exitStatus = 'error'; |
| 37 | + } |
| 38 | + |
| 39 | + console.info(`info: Done re-downloading mksnapshot. Status: ${exitStatus}`); |
| 40 | + }); |
| 41 | + } else { |
| 42 | + console.info( |
| 43 | + 'info: env var "ELECTRON_CUSTOM_VERSION" is already set correctly.\n(No need to re-download mksnapshot). Skipping.\n' |
| 44 | + ); |
| 45 | + } |
| 46 | +} else { |
| 47 | + console.log('devDependency "electron-mksnapshot/download-mksnapshot.js" not found.\nSkipping "redownload electron bins" script.\n') |
| 48 | +} |
0 commit comments