|
| 1 | +const fs = require('fs'); |
1 | 2 | const isCI = require('is-ci'); |
2 | 3 | const { notarize } = require('electron-notarize'); |
| 4 | +const utils = require('../../packager/utils'); |
| 5 | +const { getChannelFile } = utils; |
| 6 | +const join = require('path').join; |
| 7 | +const { hashFile } = require('./hash'); |
3 | 8 |
|
4 | 9 | exports.default = async function notarizing(context) { |
5 | | - if (!isCI) { |
6 | | - console.log('Skipping notarization: not on CI.'); |
7 | | - return; |
8 | | - } |
9 | | - if (process.env.IS_FORK === 'true') { |
10 | | - console.log('Skipping the app notarization: building from a fork.'); |
11 | | - return; |
12 | | - } |
13 | | - const { electronPlatformName, appOutDir } = context; |
14 | | - if (electronPlatformName !== 'darwin') { |
15 | | - return; |
16 | | - } |
| 10 | + if (!isCI) { |
| 11 | + console.log('Skipping notarization: not on CI.'); |
| 12 | + return; |
| 13 | + } |
| 14 | + if (process.env.IS_FORK === 'true') { |
| 15 | + console.log('Skipping the app notarization: building from a fork.'); |
| 16 | + return; |
| 17 | + } |
| 18 | + const { electronPlatformName, appOutDir } = context; |
| 19 | + if (electronPlatformName !== 'darwin') { |
| 20 | + return; |
| 21 | + } |
17 | 22 |
|
18 | | - const appName = context.packager.appInfo.productFilename; |
19 | | - const appBundleId = context.packager.config.appId; |
20 | | - console.log(`>>> Notarizing ${appBundleId} at ${appOutDir}/${appName}.app...`); |
| 23 | + const appName = context.packager.appInfo.productFilename; |
| 24 | + const appBundleId = context.packager.config.appId; |
| 25 | + console.log( |
| 26 | + `>>> Notarizing ${appBundleId} at ${appOutDir}/${appName}.app...` |
| 27 | + ); |
21 | 28 |
|
22 | | - return await notarize({ |
23 | | - appBundleId, |
24 | | - appPath: `${appOutDir}/${appName}.app`, |
25 | | - appleId: process.env.AC_USERNAME, |
26 | | - appleIdPassword: process.env.AC_PASSWORD, |
27 | | - }); |
| 29 | + await notarize({ |
| 30 | + appBundleId, |
| 31 | + appPath: `${appOutDir}/${appName}.app`, |
| 32 | + appleId: process.env.AC_USERNAME, |
| 33 | + appleIdPassword: process.env.AC_PASSWORD, |
| 34 | + }); |
| 35 | + return await recalculateHash(); |
28 | 36 | }; |
| 37 | + |
| 38 | +async function recalculateHash() { |
| 39 | + const { platform } = process; |
| 40 | + const cwd = join(__dirname, '..', 'build', 'dist'); |
| 41 | + const channelFilePath = join(cwd, getChannelFile(platform)); |
| 42 | + const yaml = require('yaml'); |
| 43 | + |
| 44 | + try { |
| 45 | + let fileContents = fs.readFileSync(channelFilePath, 'utf8'); |
| 46 | + const newChannelFile = yaml.parse(fileContents); |
| 47 | + const { files, path } = newChannelFile; |
| 48 | + const newSha512 = await hashFile(join(cwd, path)); |
| 49 | + newChannelFile.sha512 = newSha512; |
| 50 | + if (!!files) { |
| 51 | + const newFiles = []; |
| 52 | + for (let file of files) { |
| 53 | + const { url } = file; |
| 54 | + const { size } = fs.statSync(join(cwd, url)); |
| 55 | + const newSha512 = await hashFile(join(cwd, url)); |
| 56 | + newFiles.push({ ...file, sha512: newSha512, size }); |
| 57 | + } |
| 58 | + newChannelFile.files = newFiles; |
| 59 | + } |
| 60 | + console.log(channelFilePath); |
| 61 | + fs.writeFileSync(channelFilePath, yaml.stringify(newChannelFile)); |
| 62 | + } catch (e) { |
| 63 | + console.log(e); |
| 64 | + } |
| 65 | +} |
0 commit comments