summaryrefslogtreecommitdiff
path: root/desktop/node_modules/electron-packager/src/universal.js
blob: 8ae7cb1f93c5399407f6ee62bb68808e53ef2eb3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
'use strict'

const universal = require('@electron/universal')
const common = require('./common')
const fs = require('fs-extra')
const path = require('path')

async function packageUniversalMac (packageForPlatformAndArchWithOpts, buildDir, comboOpts, downloadOpts, tempBase) {
  // In order to generate a universal macOS build we actually need to build the x64 and the arm64 app
  // and then glue them together
  common.info(`Packaging app for platform ${comboOpts.platform} universal using electron v${comboOpts.electronVersion} - Building x64 and arm64 slices now`, comboOpts.quiet)
  await fs.mkdirp(tempBase)
  const tempDir = await fs.mkdtemp(path.resolve(tempBase, 'electron-packager-universal-'))

  const { App } = require('./mac')
  const app = new App(comboOpts, buildDir)
  const universalStagingPath = app.stagingPath
  const finalUniversalPath = common.generateFinalPath(app.opts)

  if (await fs.pathExists(finalUniversalPath)) {
    if (comboOpts.overwrite) {
      await fs.remove(finalUniversalPath)
    } else {
      common.info(`Skipping ${comboOpts.platform} ${comboOpts.arch} (output dir already exists, use --overwrite to force)`, comboOpts.quiet)
      return true
    }
  }

  const tempPackages = {}

  for (const tempArch of ['x64', 'arm64']) {
    const tempOpts = {
      ...comboOpts,
      arch: tempArch,
      out: tempDir
    }
    const tempDownloadOpts = {
      ...downloadOpts,
      arch: tempArch
    }
    // Do not sign or notarize the individual slices, we sign and notarize the merged app later
    delete tempOpts.osxSign
    delete tempOpts.osxNotarize

    tempPackages[tempArch] = await packageForPlatformAndArchWithOpts(tempOpts, tempDownloadOpts)
  }

  const x64AppPath = tempPackages.x64
  const arm64AppPath = tempPackages.arm64

  common.info(`Stitching universal app for platform ${comboOpts.platform}`, comboOpts.quiet)

  const generatedFiles = await fs.readdir(x64AppPath)
  const appName = generatedFiles.filter(file => path.extname(file) === '.app')[0]

  await universal.makeUniversalApp({
    ...comboOpts.osxUniversal,
    x64AppPath: path.resolve(x64AppPath, appName),
    arm64AppPath: path.resolve(arm64AppPath, appName),
    outAppPath: path.resolve(universalStagingPath, appName)
  })

  await app.signAppIfSpecified()
  await app.notarizeAppIfSpecified()
  await app.move()

  for (const generatedFile of generatedFiles) {
    if (path.extname(generatedFile) === '.app') continue

    await fs.copy(path.resolve(x64AppPath, generatedFile), path.resolve(finalUniversalPath, generatedFile))
  }

  await fs.remove(tempDir)

  return finalUniversalPath
}

module.exports = {
  packageUniversalMac
}