Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create distributables for Windows + Linux #284

Merged
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 5 additions & 15 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,22 @@ on:

jobs:
build:
env:
NODE_ENV: "production"
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [windows-latest, ubuntu-latest]
node-version: [18]
node-version: [20.18.0]

steps:
- name: Check out Git repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install Node.js, NPM and Yarn
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: "npm"

- name: Ensure fresh npm version (Windows pre-requirement)
# https://github.com/actions/setup-node/issues/411
run: npm i -g npm@8
if: ${{ matrix.os == 'windows-latest' }}

- name: Ensure fresh npm version
run: npm install -g npm@latest
cache: npm

- name: Build Env Information
run: |
Expand All @@ -45,7 +35,7 @@ jobs:

- name: Electron Build & Publish
run: |
npm run build
npm run package
npm run release
env:
NODE_OPTIONS: "--max-old-space-size=8192"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Install Node.js, NPM and Yarn
uses: actions/setup-node@v4
with:
node-version: 20
node-version: 20.18.0
cache: npm

- name: Build Env Information
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ thumbs.db
/tsconfig.web.tsbuildinfo
debug.log
bun.lockb
*.pfx
12 changes: 6 additions & 6 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
"version": "0.2.0",
"configurations": [
{
"name": "Electron: Main",
"type": "node",
"env": {
"NODE_OPTIONS": "--enable-source-maps"
},
"request": "launch",
"name": "Electron: Main",
"cwd": "${workspaceFolder}",
"runtimeExecutable": "${workspaceFolder}/node_modules/@electron-forge/cli/script/vscode.sh",
"windows": {
"runtimeExecutable": "${workspaceFolder}/node_modules/@electron-forge/cli/script/vscode.cmd"
},
"cwd": "${workspaceFolder}",
"env": {
"NODE_OPTIONS": "--enable-source-maps"
},
"console": "integratedTerminal"
},
{
Expand All @@ -21,7 +21,7 @@
"request": "attach",
"port": 9223,
"webRoot": "${workspaceFolder}/src/renderer",
"timeout": 30000
"timeout": 60000
}
],
"compounds": [
Expand Down
82 changes: 79 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,87 @@ It is highly recommended to use [VSCode](https://code.visualstudio.com/) for dev

### Requirements

- [Node.js 20](https://nodejs.org/en/download/)
- [Node.js 20.18.0](https://nodejs.org/en/download/)

### Project setup:
### Local Development

```bash
npm install
npm run start
npm start
```

### Project Structure

```
.
├──buildResources # used by electron-builder
├──src
│ ├──main
│ │ ├──main.ts
│ │ └──...
│ ├──preload
│ │ ├──preload.ts
│ │ └──...
│ └──renderer # with vue
│ ├──public # (optional) publicDir for renderer
│ ├──index.ts
│ ├──index.html
│ └──...
├──electron-builder.config.ts
├──electron.vite.config.ts
├──package.json
└──...
```

- [**Main process**](https://www.electronjs.org/docs/latest/tutorial/process-model#the-main-process)
- Runs in a Node.js environment and has access to Node.js APIs
- Anything requiring access to the operating system or Node.js APIs needs to live here
- [**Preload script**](https://www.electronjs.org/docs/latest/tutorial/process-model#preload-scripts)
- Runs in a Node.js environment
- Defines global objects that can be used in the renderer
- Handles communication between the main and renderer processes
- Uses Electron's ipcMain and ipcRenderer modules for inter-process communication (IPC).
- [**Renderer process**](https://www.electronjs.org/docs/latest/tutorial/process-model#the-renderer-process)
- Runs in a web environment and has **no** direct access to Node.js APIs

### Build & Publish:

- [`electron-forge`](https://www.electronforge.io/config/plugins/vite)
- Builds the app with a pre-configured Vite setup for Electron apps
- This intentionally does not include `electron` or any other `node_modules` dependencies in the build
- Dependencies get added to the package by `electron-builder` with ASAR
- Note: apps that only have CJS exports need to be included in the build, e.g. `glob-promise`
- [`electron-builder`](https://www.electron.build/)
- Packages Electron app for distribution
- Configured for Windows NSIS installer and Linux AppImage
- Handles publishing updates
- Auto-updates TBD

### Commands

- `npm start`
- Runs `electron-forge` in `development` mode
- **renderer** runs with Hot Module Replacement (HMR)
- **main** and **preload** are directly bundled to `.vite/build`
- `npm run package`
- Runs `electron-forge` in `production` mode
- **renderer** us bundled to `.vite/renderer`
- **main** and **preload** are bundled to `.vite/build`
- `npm run preview`
- Runs `electron-forge` in `production` mode, and runs electron
- **main**, **preload**, and **renderer** are bundled to `.vite/build`
- This is useful for validating the `production` build without packaging the app
- `npm run build:win`
- Runs `npm run build` and `electron-builder`, building for Windows
- Outputs NSIS installer in `dist`
- `npm run build:linux`
- Runs `npm run build` and `electron-builder`, building for Linux
- Outputs AppImage executable in `dist`
- `npm run build:unpack`
- Runs `npm run build` and `electron-builder`, building an unpackaged directory
- Outputs the unpacked contents in `dist`
- Useful for testing
- `npm run dev-cert` (optional and only for Windows development)
- Runs `electron-builder` to create a self-signed cert for Windows apps.
- After selecting "None" in the pop-up, a cert file should be created called `BAR Team.pfx`
- Then run `npm run build:win:dev-cert` to build a signed Windows installer
Binary file added buildResources/icon.ico
Binary file not shown.
File renamed without changes
52 changes: 52 additions & 0 deletions electron-builder.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { Configuration } from "electron-builder";

/**
* @see https://www.electron.build/configuration
*/
const config: Configuration = {
appId: "BeyondAllReason",
productName: "Beyond All Reason",
files: [
"!**/.vscode/*",
"!{docs,src,out,tests,vendor}/*",
"!vite.*.config.{js,ts,mjs,cjs,mts}",
"!{eslint.config.mjs,.prettierignore,prettier.config.mjs,README.md}",
"!{.env,.env.*,.npmrc,pnpm-lock.yaml}",
"!{tsconfig.json,tsconfig.*.json}",
"!{electron-builder.config.ts,forge.config.cjs}",
],
directories: { buildResources: "buildResources" },
asarUnpack: ["resources/**"],

publish: { provider: "github" },
fileAssociations: [
{
ext: "sdfz",
description: "BAR Replay File",
role: "Viewer",
icon: "icon.ico",
name: "SDFZ NAME HERE",
},
],

// Windows
win: {
target: ["nsis"],
},
nsis: {
artifactName: "${productName}-${version}-setup.${ext}",
uninstallDisplayName: "${productName}",
oneClick: true,
perMachine: true,
allowToChangeInstallationDirectory: false,
},

// Linux
linux: {
target: ["AppImage"],
category: "Game",
},
appImage: {},
};

export default config;
41 changes: 0 additions & 41 deletions forge.config.cjs
Original file line number Diff line number Diff line change
@@ -1,33 +1,6 @@
const { MakerDeb } = require("@electron-forge/maker-deb");
const { MakerRpm } = require("@electron-forge/maker-rpm");
const { MakerFlatpak } = require("@electron-forge/maker-flatpak");
const { MakerSquirrel } = require("@electron-forge/maker-squirrel");
const { VitePlugin } = require("@electron-forge/plugin-vite");

const config = {
packagerConfig: {
asar: false, // Cannot enable asar, it breaks map parsing
},
rebuildConfig: {},
makers: [
new MakerSquirrel({
authors: "BAR Team",
description: "Beyond All Reason Lobby",
}),
new MakerRpm({
options: {
mimeType: ["application/sdfz"],
categories: ["Game"],
icon: "src/renderer/assets/images/icon.png",
homepage: "https://www.beyondallreason.info/",
license: "MIT",
name: "bar-lobby",
productName: "BAR Lobby",
},
}),
new MakerDeb({}),
new MakerFlatpak({}),
],
plugins: [
new VitePlugin({
build: [
Expand All @@ -49,20 +22,6 @@ const config = {
},
],
}),
// {
// name: "@electron-forge/plugin-auto-unpack-natives",
// config: {},
// },
// Uncomment and configure fuses if needed:
// new FusesPlugin({
// version: FuseVersion.V1,
// [FuseV1Options.RunAsNode]: false,
// [FuseV1Options.EnableCookieEncryption]: true,
// [FuseV1Options.EnableNodeOptionsEnvironmentVariable]: false,
// [FuseV1Options.EnableNodeCliInspectArguments]: false,
// [FuseV1Options.EnableEmbeddedAsarIntegrityValidation]: true,
// [FuseV1Options.OnlyLoadAppFromAsar]: true,
// }),
],
};

Expand Down
Loading
Loading