|
| 1 | +const {spawnSync} = require('child_process'); |
| 2 | + |
| 3 | +const stripCSC = function (environment) { |
| 4 | + const { |
| 5 | + CSC_LINK: _CSC_LINK, |
| 6 | + CSC_KEY_PASSWORD: _CSC_KEY_PASSWORD, |
| 7 | + WIN_CSC_LINK: _WIN_CSC_LINK, |
| 8 | + WIN_CSC_KEY_PASSWORD: _WIN_CSC_KEY_PASSWORD, |
| 9 | + ...strippedEnvironment |
| 10 | + } = environment; |
| 11 | + return strippedEnvironment; |
| 12 | +}; |
| 13 | + |
| 14 | +const getPlatformFlag = function () { |
| 15 | + switch (process.platform) { |
| 16 | + case 'win32': return '--windows'; |
| 17 | + case 'darwin': return '--macos'; |
| 18 | + case 'linux': return '--linux'; |
| 19 | + } |
| 20 | + throw new Error(`Could not determine platform flag for platform: ${process.platform}`); |
| 21 | +} |
| 22 | + |
| 23 | +const runBuilder = function (targetGroup) { |
| 24 | + // the appx build fails if CSC_* or WIN_CSC_* variables are set |
| 25 | + const shouldStripCSC = (targetGroup === 'appx'); |
| 26 | + const childEnvironment = shouldStripCSC ? stripCSC(process.env) : process.env; |
| 27 | + if ((targetGroup === 'nsis') && !(childEnvironment.CSC_LINK || childEnvironment.WIN_CSC_LINK)) { |
| 28 | + throw new Error(`NSIS build requires CSC_LINK or WIN_CSC_LINK`); |
| 29 | + } |
| 30 | + const platformFlag = getPlatformFlag(); |
| 31 | + const command = `electron-builder ${platformFlag} ${targetGroup}`; |
| 32 | + console.log(`running: ${command}`); |
| 33 | + spawnSync(command, { |
| 34 | + env: childEnvironment, |
| 35 | + shell: true, |
| 36 | + stdio: 'inherit' |
| 37 | + }); |
| 38 | +}; |
| 39 | + |
| 40 | +const calculateTargets = function () { |
| 41 | + switch (process.platform) { |
| 42 | + case 'win32': |
| 43 | + // run in two passes so we can skip signing the appx |
| 44 | + return ['nsis', 'appx']; |
| 45 | + case 'darwin': |
| 46 | + // run in one pass for slightly better speed |
| 47 | + return ['dmg mas']; |
| 48 | + } |
| 49 | + throw new Error(`Could not determine targets for platform: ${process.platform}`); |
| 50 | +}; |
| 51 | + |
| 52 | +// TODO: allow user to specify targets? We could theoretically build NSIS on Mac, for example. |
| 53 | +const targets = calculateTargets(); |
| 54 | +for (const targetGroup of targets) { |
| 55 | + runBuilder(targetGroup); |
| 56 | +} |
0 commit comments