3

I have an after-sign module which handles notarization.

I want to execute it only when building mac app.

My package.json is like this.

"scripts": {
  "build:mac": "node .electron-vue/build.js && electron-builder --mac",
  "build:win": "node .electron-vue/build.js && electron-builder --win --x64 --ia32",
},
"build": {
    "mac": {
      "hardenedRuntime": true,
      "entitlements": "./notarlization/entitlement.plist",
      "entitlementsInherit": "./notarlization/entitlement.plist"
    },
    "afterSign": "./notarlization/after-sign.js"
  }

And my after-sign module is like this.

module.exports = async () => {
  if (process.platform === 'darwin') {
    console.log(`公証通過申請中...`)
    try {
      await notarize({
        appBundleId,
        appPath,
        appleId,
        appleIdPassword,
        ascProvider
      })
      console.log('公証通過完了')
    } catch (error) {
      console.log('公証通過失敗: ', error)
    }
  }
}

Actually, it works fine.

Because I build mac app in macOS and Win app in WinOS.

But I think if (process.platform === 'darwin') {} is not kool.

I want to do something like this in package.json.

Any one know how to do this?

Akao
  • 121
  • 9

2 Answers2

2

From the electron-builder documentation you can see at the bottom of the page that you can use afterSign inside the mac configuration object "...And all common platform-specific options.", which I think is the best way to do that.

Otherwise you can see other available options here

Tasos
  • 1,880
  • 13
  • 19
  • 2
    I have ```"mac": { "category": "productivity", "target": "dmg", "icon": "icon.png", "entitlements": "build/entitlements.mac.plist", "entitlementsInherit": "build/entitlements.mac.plist", "hardenedRuntime": true, "gatekeeperAssess": false, "afterSign": "electron_js/notarize.js" },``` but I keep getting 'configuration.mac has an unknown property 'afterSign'. I am on electron-builder 22.4.0 – user1361529 Mar 07 '20 at 12:47
  • 2
    @user1361529 Can you post the whole of your JSON? (hide the sensitive data if any) before that, check if your the "mac" property is at the top level of your json, and not under "build" – Tasos Mar 08 '20 at 21:38
0
function getBuilderFlags () {
  // https://www.electron.build/cli
  const winFlags = ['--win', '-w', '--windows']
  const macFlags = ['--mac', '-m', '-o', '--macos']
  const cmd = process.argv

  console.log('Checking cmd arguments:', cmd)

  const result = {}
  result.isWinOn = cmd.some(flag => winFlags.includes(flag))
  result.isMacOn = cmd.some(flag => macFlags.includes(flag))
  return result
}

exports.default = async function (context) {
  console.log(' start: After Sign Hook')
  const flags = getBuilderFlags()

  if (flags.isWinOn) {
    console.log('processing windows...')
  }
  if (flags.isMacOn) {
    console.log('processing mac...')
  }
  console.log('finish: After Sign Hook')
}
Oleks
  • 1,011
  • 1
  • 14
  • 25