electron-userland / electron-builder

A complete solution to package and build a ready for distribution Electron app with “auto update” support out of the box
https://www.electron.build
MIT License
13.57k stars 1.73k forks source link

extraResources per architecture #7891

Closed DrSkunk closed 4 months ago

DrSkunk commented 9 months ago

My electron application works as a GUI wrapper to start a subprocess. This is copied with extraResources key under each platform. However, the subprocess needs to be copied per architecture. Up until new we only supported x64.

Would it be possible to set extraResources per target instead of either global or per platform?

Or is it possible to have an intermediary build step where I can run a script which copies the appropriate binary?

Excerpt of my config:

  "build": {
    "appId": "my.app.id",
    "productName": "Awesome Application",
    "directories": {
      "output": "dist",
      "buildResources": "build-resources"
    },
    "files": [
      "electron/**/*"
    ],
    "extraResources": [
      "build-gui/**/*",
      "build-resources/**/*"
    ],
    "artifactName": "${productName}.${ext}",
    "afterSign": "scripts/notarize.js",
    "mac": {
      "hardenedRuntime": true,
      "target": [
        {
          "target": "dmg",
          "arch": "x64"
        }
      ],
      "extraResources": [
        {
          "from": "../app/dist/build/app-darwin-x64",
          "to": ".",
          "filter": [
            "**/*"
          ]
        }
      ],
      "category": "public.app-category.developer-tools"
    },
    "win": {
      "target": "nsis",
      "extraResources": {
        "from": "../app/dist/build/app-win32-x64.exe",
        "to": ".",
        "filter": [
          "**/*"
        ]
      }
    }
  },

Suggested config:

  {
  "mac": {
    "hardenedRuntime": true,
    "target": [
      {
        "target": "dmg",
        "arch": "x64",
        "extraResources": [
          {
            "from": "../app/dist/build/app-darwin-x64",
            "to": ".",
            "filter": ["**/*"]
          }
        ]
      },
      {
        "target": "dmg",
        "arch": "arm64",
        "extraResources": [
          {
            "from": "../app/dist/build/app-darwin-arm64",
            "to": ".",
            "filter": ["**/*"]
          }
        ]
      }
    ]    
  }
}

Thanks in advance.

DrSkunk commented 9 months ago

Under the hooks documentation I found the key afterPack. Using that I implemented my own copying function for asset movement. I'll be testing this:

const { Arch, Platform } = require("electron-builder");
const fs = require("fs/promises");
const path = require("path");

module.exports = async function afterPack(context) {
  let appName;
  let to;
  if (context.packager.platform === Platform.MAC) {
    appName = `app-darwin-${Arch[context.arch]}`;
    to = path.resolve(
      context.appOutDir,
      `${context.packager.appInfo.productFilename}.app`,
      "Contents",
      "Resources",
      appName
    );
  } else if (context.packager.platform === Platform.WINDOWS) {
    appName = `app-win32-${Arch[context.arch]}.exe`;
    to = path.resolve(context.appOutDir, "resources", appName);
  } else {
    throw new Error(
      `Could not determine platform. Should be either '${Platform.MAC.name}' or '${Platform.WINDOWS.name}', but was: ${context.packager.platform}`
    );
  }
  const from = path.resolve("..", "app", "dist", "build", appName);

  try {
    console.log(`Copying "${from}" to "${to}"`);
    await fs.copyFile(from, to);
  } catch (error) {
    console.error(error);
    throw new Error(
      `Could not copy "${from}" to "${to}".\n Did you build the app first and ran the 'movebinary' script?`
    );
  }
};
github-actions[bot] commented 5 months ago

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 30 days.

github-actions[bot] commented 4 months ago

This issue was closed because it has been stalled for 30 days with no activity.