AFFiNE/packages/frontend/electron/forge.config.mjs

173 lines
4.3 KiB
JavaScript
Raw Normal View History

import cp from 'node:child_process';
import { rm, symlink } from 'node:fs/promises';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
2023-06-14 13:40:13 +03:00
import { utils } from '@electron-forge/core';
import {
2023-08-22 18:16:26 +03:00
arch,
buildType,
icnsPath,
2023-10-16 18:54:28 +03:00
iconPngPath,
iconUrl,
icoPath,
2023-08-22 18:16:26 +03:00
platform,
productName,
} from './scripts/make-env.js';
2023-07-12 17:35:45 +03:00
const fromBuildIdentifier = utils.fromBuildIdentifier;
const __dirname = fileURLToPath(new URL('.', import.meta.url));
2023-08-02 18:56:00 +03:00
const makers = [
!process.env.SKIP_BUNDLE &&
platform === 'darwin' && {
name: '@electron-forge/maker-dmg',
config: {
format: 'ULFO',
icon: icnsPath,
name: 'AFFiNE',
'icon-size': 128,
background: path.join(
__dirname,
'./resources/icons/dmg-background.png'
),
contents: [
{
x: 176,
y: 192,
type: 'file',
path: path.join(
__dirname,
'out',
buildType,
`${productName}-darwin-${arch}`,
`${productName}.app`
),
},
{ x: 432, y: 192, type: 'link', path: '/Applications' },
],
2023-08-30 07:30:45 +03:00
iconSize: 118,
file: path.join(
__dirname,
'out',
buildType,
`${productName}-darwin-${arch}`,
`${productName}.app`
),
},
2023-08-02 18:56:00 +03:00
},
{
name: '@electron-forge/maker-zip',
config: {
name: 'affine',
iconUrl: icoPath,
setupIcon: icoPath,
platforms: ['darwin', 'linux', 'win32'],
},
},
!process.env.SKIP_BUNDLE && {
name: '@electron-forge/maker-squirrel',
config: {
name: productName,
2023-08-02 18:56:00 +03:00
setupIcon: icoPath,
2023-08-22 18:16:26 +03:00
iconUrl: iconUrl,
2023-08-02 18:56:00 +03:00
loadingGif: './resources/icons/affine_installing.gif',
},
},
!process.env.SKIP_BUNDLE && {
name: '@reforged/maker-appimage',
config: {
name: 'AFFiNE',
2023-10-16 18:54:28 +03:00
icon: iconPngPath,
2023-08-02 18:56:00 +03:00
platforms: ['linux'],
options: {
bin: productName,
},
},
},
].filter(Boolean);
/**
* @type {import('@electron-forge/shared-types').ForgeConfig}
*/
export default {
2023-04-21 19:52:55 +03:00
buildIdentifier: buildType,
2023-03-16 17:58:21 +03:00
packagerConfig: {
name: productName,
appBundleId: fromBuildIdentifier({
2023-05-15 08:35:30 +03:00
internal: 'pro.affine.internal',
canary: 'pro.affine.canary',
2023-04-21 19:52:55 +03:00
beta: 'pro.affine.beta',
stable: 'pro.affine.app',
}),
icon: icnsPath,
2023-04-21 13:25:46 +03:00
osxSign: {
identity: 'Developer ID Application: TOEVERYTHING PTE. LTD.',
'hardened-runtime': true,
},
osxNotarize: process.env.APPLE_ID
? {
tool: 'notarytool',
appleId: process.env.APPLE_ID,
appleIdPassword: process.env.APPLE_PASSWORD,
teamId: process.env.APPLE_TEAM_ID,
}
: undefined,
2023-06-15 15:48:10 +03:00
// We need the following line for updater
extraResource: ['./resources/app-update.yml'],
protocols: [
{
name: productName,
schemes: [productName.toLowerCase()],
},
],
2023-03-16 17:58:21 +03:00
},
2023-08-02 18:56:00 +03:00
makers,
hooks: {
readPackageJson: async (_, packageJson) => {
// we want different package name for canary build
// so stable and canary will not share the same app data
packageJson.productName = productName;
},
2023-06-14 13:40:13 +03:00
prePackage: async () => {
if (!process.env.HOIST_NODE_MODULES) {
await rm(path.join(__dirname, 'node_modules'), {
recursive: true,
force: true,
});
2023-06-14 13:40:13 +03:00
await symlink(
path.join(__dirname, '..', '..', '..', 'node_modules'),
path.join(__dirname, 'node_modules')
);
}
2023-06-14 13:40:13 +03:00
},
generateAssets: async (_, platform, arch) => {
if (process.env.SKIP_GENERATE_ASSETS) {
return;
}
// TODO: right now we do not need the following
// it is for octobase-node, but we dont use it for now.
if (platform === 'darwin' && arch === 'arm64') {
// In GitHub Actions runner, MacOS is always x64
// we need to manually set TARGET to aarch64-apple-darwin
process.env.TARGET = 'aarch64-apple-darwin';
}
cp.spawnSync('yarn', ['generate-assets'], {
stdio: 'inherit',
env: {
...process.env,
NODE_OPTIONS: (process.env.NODE_OPTIONS ?? '').replace(
'--loader ts-node/esm',
''
),
},
cwd: __dirname,
});
},
},
2023-03-16 17:58:21 +03:00
};