2023-04-17 19:32:10 +03:00
|
|
|
/* eslint-disable @typescript-eslint/no-var-requires */
|
2023-06-14 13:40:13 +03:00
|
|
|
|
2023-05-11 05:42:56 +03:00
|
|
|
const { z } = require('zod');
|
|
|
|
|
2023-04-17 19:32:10 +03:00
|
|
|
const {
|
|
|
|
utils: { fromBuildIdentifier },
|
|
|
|
} = require('@electron-forge/core');
|
|
|
|
|
2023-04-21 13:06:54 +03:00
|
|
|
const path = require('node:path');
|
2023-04-17 19:32:10 +03:00
|
|
|
|
2023-05-11 05:42:56 +03:00
|
|
|
const ReleaseTypeSchema = z.enum(['stable', 'beta', 'canary', 'internal']);
|
|
|
|
|
|
|
|
const envBuildType = (process.env.BUILD_TYPE || 'canary').trim().toLowerCase();
|
|
|
|
const buildType = ReleaseTypeSchema.parse(envBuildType);
|
2023-04-21 19:52:55 +03:00
|
|
|
const stableBuild = buildType === 'stable';
|
|
|
|
const productName = !stableBuild ? `AFFiNE-${buildType}` : 'AFFiNE';
|
|
|
|
const icoPath = !stableBuild
|
|
|
|
? `./resources/icons/icon_${buildType}.ico`
|
2023-04-17 19:32:10 +03:00
|
|
|
: './resources/icons/icon.ico';
|
2023-04-21 19:52:55 +03:00
|
|
|
const icnsPath = !stableBuild
|
|
|
|
? `./resources/icons/icon_${buildType}.icns`
|
2023-04-17 19:32:10 +03:00
|
|
|
: './resources/icons/icon.icns';
|
|
|
|
|
2023-04-21 13:06:54 +03:00
|
|
|
const arch =
|
|
|
|
process.argv.indexOf('--arch') > 0
|
|
|
|
? process.argv[process.argv.indexOf('--arch') + 1]
|
|
|
|
: process.arch;
|
|
|
|
|
2023-07-12 17:35:45 +03:00
|
|
|
const windowsIconUrl = `https://cdn.affine.pro/app-icons/icon_${buildType}.ico`;
|
|
|
|
|
2023-08-02 18:56:00 +03:00
|
|
|
const makers = [
|
|
|
|
!process.env.SKIP_BUNDLE && {
|
|
|
|
name: '@affine/maker-dmg',
|
|
|
|
config: {
|
|
|
|
format: 'ULFO',
|
|
|
|
icon: icnsPath,
|
|
|
|
name: 'AFFiNE',
|
|
|
|
'icon-size': 128,
|
|
|
|
background: path.resolve(
|
|
|
|
__dirname,
|
|
|
|
'./resources/icons/dmg-background.png'
|
|
|
|
),
|
|
|
|
file: path.resolve(
|
|
|
|
__dirname,
|
|
|
|
'out',
|
|
|
|
buildType,
|
|
|
|
`${productName}-darwin-${arch}`,
|
|
|
|
`${productName}.app`
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
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: 'AFFiNE',
|
|
|
|
setupIcon: icoPath,
|
|
|
|
iconUrl: windowsIconUrl,
|
|
|
|
loadingGif: './resources/icons/affine_installing.gif',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
!process.env.SKIP_BUNDLE && {
|
|
|
|
name: '@reforged/maker-appimage',
|
|
|
|
config: {
|
|
|
|
name: 'AFFiNE',
|
|
|
|
iconUrl: icoPath,
|
|
|
|
setupIcon: icoPath,
|
|
|
|
platforms: ['linux'],
|
|
|
|
options: {
|
|
|
|
bin: productName,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
].filter(Boolean);
|
|
|
|
|
2023-04-17 19:32:10 +03:00
|
|
|
/**
|
|
|
|
* @type {import('@electron-forge/shared-types').ForgeConfig}
|
|
|
|
*/
|
2023-03-16 17:58:21 +03:00
|
|
|
module.exports = {
|
2023-04-21 19:52:55 +03:00
|
|
|
buildIdentifier: buildType,
|
2023-03-16 17:58:21 +03:00
|
|
|
packagerConfig: {
|
2023-04-17 19:32:10 +03:00
|
|
|
name: productName,
|
|
|
|
appBundleId: fromBuildIdentifier({
|
2023-05-15 08:35:30 +03:00
|
|
|
internal: 'pro.affine.internal',
|
2023-04-17 19:32:10 +03:00
|
|
|
canary: 'pro.affine.canary',
|
2023-04-21 19:52:55 +03:00
|
|
|
beta: 'pro.affine.beta',
|
2023-04-17 19:32:10 +03:00
|
|
|
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,
|
|
|
|
},
|
2023-04-09 04:44:47 +03:00
|
|
|
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'],
|
2023-03-16 17:58:21 +03:00
|
|
|
},
|
2023-08-02 18:56:00 +03:00
|
|
|
makers,
|
2023-04-04 15:40:07 +03:00
|
|
|
hooks: {
|
2023-04-17 19:32:10 +03:00
|
|
|
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 () => {
|
|
|
|
const { rm, cp } = require('node:fs/promises');
|
|
|
|
const { resolve } = require('node:path');
|
|
|
|
|
|
|
|
await rm(
|
|
|
|
resolve(__dirname, './node_modules/@toeverything/plugin-infra'),
|
|
|
|
{
|
|
|
|
recursive: true,
|
|
|
|
force: true,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
await cp(
|
|
|
|
resolve(__dirname, '../../packages/plugin-infra'),
|
|
|
|
resolve(__dirname, './node_modules/@toeverything/plugin-infra'),
|
|
|
|
{
|
|
|
|
recursive: true,
|
|
|
|
force: true,
|
|
|
|
}
|
|
|
|
);
|
2023-08-03 07:47:05 +03:00
|
|
|
|
|
|
|
await rm(resolve(__dirname, './node_modules/@affine/sdk'), {
|
|
|
|
recursive: true,
|
|
|
|
force: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
await cp(
|
|
|
|
resolve(__dirname, '../../packages/sdk'),
|
|
|
|
resolve(__dirname, './node_modules/@affine/sdk'),
|
|
|
|
{
|
|
|
|
recursive: true,
|
|
|
|
force: true,
|
|
|
|
}
|
|
|
|
);
|
2023-06-14 13:40:13 +03:00
|
|
|
},
|
2023-04-04 15:40:07 +03:00
|
|
|
generateAssets: async (_, platform, arch) => {
|
2023-04-18 12:50:29 +03:00
|
|
|
if (process.env.SKIP_GENERATE_ASSETS) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-04-04 15:40:07 +03:00
|
|
|
const { $ } = await import('zx');
|
|
|
|
|
2023-04-18 12:50:29 +03:00
|
|
|
// TODO: right now we do not need the following
|
|
|
|
// it is for octobase-node, but we dont use it for now.
|
2023-04-04 15:40:07 +03:00
|
|
|
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';
|
|
|
|
}
|
|
|
|
|
2023-04-17 03:28:29 +03:00
|
|
|
if (platform === 'win32') {
|
|
|
|
$.shell = 'powershell.exe';
|
|
|
|
$.prefix = '';
|
|
|
|
}
|
|
|
|
|
2023-04-04 15:40:07 +03:00
|
|
|
// run yarn generate-assets
|
|
|
|
await $`yarn generate-assets`;
|
|
|
|
},
|
|
|
|
},
|
2023-03-16 17:58:21 +03:00
|
|
|
};
|