|
1 | 1 | const { notarize } = require('electron-notarize');
|
2 | 2 | const path = require('path');
|
| 3 | +const fs = require('fs'); |
| 4 | +const jsYaml = require('js-yaml'); |
| 5 | + |
| 6 | +function findPackageJsonPath() { |
| 7 | + let dirName = process.cwd(); |
| 8 | + |
| 9 | + while(dirName) { |
| 10 | + const packageJsonFilePath = path.join(dirName, 'package.json'); |
| 11 | + if (fs.existsSync(packageJsonFilePath)) { |
| 12 | + return packageJsonFilePath; |
| 13 | + } else if (dirName === '/') { |
| 14 | + break; |
| 15 | + } |
| 16 | + dirName = path.dirname(dirName); |
| 17 | + } |
| 18 | + return undefined; |
| 19 | +} |
| 20 | + |
| 21 | +function getAppId(context) { |
| 22 | + // Try to get the appId from the packager |
| 23 | + const config = context.packager.info._configuration; |
| 24 | + if (config && config.appId) { |
| 25 | + console.log('Found appId in packager'); |
| 26 | + return config.appId; |
| 27 | + } |
| 28 | + |
| 29 | + // Try to get the appId from the builder-effective-config.yml file |
| 30 | + const builderEffectiveConfigPath = path.join(context.outDir, 'builder-effective-config.yaml'); |
| 31 | + if (fs.existsSync(builderEffectiveConfigPath)) { |
| 32 | + const builderEffectiveConfigText = fs.readFileSync(builderEffectiveConfigPath); |
| 33 | + const builderEffectiveConfig = jsYaml.load(builderEffectiveConfigText); |
| 34 | + if (builderEffectiveConfig['appId']) { |
| 35 | + console.log('Found appId in %s', builderEffectiveConfigPath); |
| 36 | + return builderEffectiveConfig['appId']; |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + // Try to get the appId from the package.json file |
| 41 | + const packageJsonFilePath = findPackageJsonPath(); |
| 42 | + if (packageJsonFilePath) { |
| 43 | + try { |
| 44 | + const packageJson = require(packageJsonFilePath); |
| 45 | + if (packageJson['build'] && packageJson['build']['appId']) { |
| 46 | + console.log('Found appId in %s', packageJsonFilePath); |
| 47 | + return packageJson['build']['appId']; |
| 48 | + } |
| 49 | + } catch (err) { |
| 50 | + // swallow the error |
| 51 | + console.log('Failed to read %s: %s', packageJsonFilePath, err); |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + // finally, check the APP_ID environment variable |
| 56 | + if (process.env.APP_ID) { |
| 57 | + console.log('Found appId in APP_ID environment variable'); |
| 58 | + return process.env.APP_ID; |
| 59 | + } |
| 60 | + throw new Error('Unable to find the application ID'); |
| 61 | +} |
3 | 62 |
|
4 | 63 | exports.default = async function notarizing(context) {
|
5 |
| - const { electronPlatformName, appOutDir } = context; |
6 |
| - if (electronPlatformName !== 'darwin') { |
| 64 | + const { electronPlatformName } = context; |
| 65 | + if (electronPlatformName !== 'darwin' || process.env.CSC_IDENTITY_AUTO_DISCOVERY === 'false') { |
7 | 66 | return;
|
8 | 67 | }
|
9 | 68 |
|
| 69 | + const appId = getAppId(context); |
10 | 70 | const appName = context.packager.appInfo.productFilename;
|
11 |
| - const appPath = path.normalize(path.join(process.cwd(), 'dist', 'mac', `${appName}.app`)); |
12 |
| - console.log('calling notarize with appPath = %s', appPath); |
13 |
| - return await notarize({ |
14 |
| - appBundleId: 'com.github.iffy.electronupdaterexample', |
| 71 | + const appPath = path.normalize(path.join(context.outDir, 'mac', `${appName}.app`)); |
| 72 | + console.log('calling notarize for appId = %s with appPath = %s', appId, appPath); |
| 73 | + return notarize({ |
| 74 | + appBundleId: appId, |
15 | 75 | appPath: appPath,
|
16 | 76 | appleId: process.env.APPLEID,
|
17 | 77 | appleIdPassword: process.env.APPLEIDPASS,
|
|
0 commit comments