snapshot of https://github.com/toeverything/AFFiNE.git (canary, 2026-09-16; blobs > 131072B omitted)
Some checks failed
Build & Test / Analyze (javascript, blocksuite) (push) Failing after 3s
Build & Test / Rust test filter (push) Failing after 3s
Build & Test / E2E BlockSuite Test (2) (push) Failing after 3s
Build & Test / E2E BlockSuite Test (3) (push) Failing after 4s
Build & Test / E2E BlockSuite Test (4) (push) Failing after 3s
Build & Test / E2E BlockSuite Cross Browser Test (push) Failing after 3s
Build & Test / E2E Mobile Test (1) (push) Failing after 3s
Build & Test / E2E Mobile Test (2) (push) Failing after 3s
Build & Test / Build AFFiNE native (x86_64-unknown-linux-gnu) (push) Failing after 4s
Build & Test / Unit Test (1) (push) Has been skipped
Build & Test / Unit Test (2) (push) Has been skipped
Build & Test / Unit Test (3) (push) Has been skipped
Build & Test / Build Server native (push) Failing after 3s
Build & Test / Check Git Status (push) Has been skipped
Build & Test / Server Test (0, 4) (push) Has been skipped
Build & Test / Server Test (1, 4) (push) Has been skipped
Build & Test / Analyze (javascript, affine) (push) Failing after 3s
Build & Test / Analyze (typescript, affine) (push) Failing after 3s
Build & Test / Analyze (typescript, blocksuite) (push) Failing after 3s
Build & Test / Mobile native build filter (push) Failing after 3s
Build & Test / Check yarn binary (push) Failing after 3s
Build & Test / E2E BlockSuite Test (1) (push) Failing after 4s
Build & Test / E2E BlockSuite Test (5) (push) Failing after 3s
Build & Test / Unit Test (4) (push) Has been skipped
Build & Test / Unit Test (5) (push) Has been skipped
Build & Test / Native Unit Test (push) Has been skipped
Build & Test / Server Test (2, 4) (push) Has been skipped
Build & Test / Server Test (3, 4) (push) Has been skipped
Build & Test / Server Test with Elasticsearch (push) Has been skipped
Build & Test / Server Test with Embedded Search (push) Has been skipped
Build & Test / Server Test with Manticore Search (push) Has been skipped
Build & Test / Server E2E Test (push) Has been skipped
Build & Test / Cloud Desktop E2E Test (push) Has been skipped
Build & Test / Cloud E2E Test 1/2 (push) Has been skipped
Build & Test / Cloud E2E Test 2/2 (push) Has been skipped
Build & Test / Build @affine/electron renderer (push) Failing after 3s
Build & Test / Copilot test filter (push) Failing after 4s
Build & Test / Lint Rust (push) Has been skipped
Build & Test / Build Android app (push) Has been skipped
Build & Test / Test Android app (push) Has been skipped
Build & Test / Run native tests (push) Has been skipped
Build & Test / Server Copilot Api Test (push) Has been skipped
Build & Test / Frontend Copilot E2E Test (3, 5) (push) Has been skipped
Build & Test / Frontend Copilot E2E Test (4, 5) (push) Has been skipped
Build & Test / Frontend Copilot E2E Test (1, 5) (push) Has been skipped
Build & Test / Frontend Copilot E2E Test (2, 5) (push) Has been skipped
Build & Test / Frontend Copilot E2E Test (5, 5) (push) Has been skipped
Build & Test / Desktop Test (ubuntu-latest, linux, x64, x86_64-unknown-linux-gnu, true) (push) Has been cancelled
Build & Test / Desktop Test (windows-latest, windows, x64, x86_64-pc-windows-msvc, true) (push) Has been cancelled
Build & Test / 3, 2, 1 Launch (push) Has been cancelled
Build & Test / Lint (push) Has been cancelled
Build & Test / Typecheck (push) Has been cancelled
Build & Test / Build iOS app (push) Has been cancelled
Build & Test / Build AFFiNE native (aarch64-apple-darwin) (push) Has been cancelled
Build & Test / E2E Test (1) (push) Has been cancelled
Build & Test / E2E Test (2) (push) Has been cancelled
Build & Test / E2E Test (3) (push) Has been cancelled
Build & Test / E2E Test (4) (push) Has been cancelled
Build & Test / E2E Test (5) (push) Has been cancelled
Build & Test / Build AFFiNE native (x86_64-apple-darwin) (push) Has been cancelled
Build & Test / Build AFFiNE native (aarch64-pc-windows-msvc) (push) Has been cancelled
Build & Test / Build AFFiNE native (x86_64-pc-windows-msvc) (push) Has been cancelled
Build & Test / Desktop Test (macos-latest, macos, arm64, aarch64-apple-darwin, true) (push) Has been cancelled
Build & Test / Desktop Test (macos-latest, macos, x64, x86_64-apple-darwin, false) (push) Has been cancelled
Some checks failed
Build & Test / Analyze (javascript, blocksuite) (push) Failing after 3s
Build & Test / Rust test filter (push) Failing after 3s
Build & Test / E2E BlockSuite Test (2) (push) Failing after 3s
Build & Test / E2E BlockSuite Test (3) (push) Failing after 4s
Build & Test / E2E BlockSuite Test (4) (push) Failing after 3s
Build & Test / E2E BlockSuite Cross Browser Test (push) Failing after 3s
Build & Test / E2E Mobile Test (1) (push) Failing after 3s
Build & Test / E2E Mobile Test (2) (push) Failing after 3s
Build & Test / Build AFFiNE native (x86_64-unknown-linux-gnu) (push) Failing after 4s
Build & Test / Unit Test (1) (push) Has been skipped
Build & Test / Unit Test (2) (push) Has been skipped
Build & Test / Unit Test (3) (push) Has been skipped
Build & Test / Build Server native (push) Failing after 3s
Build & Test / Check Git Status (push) Has been skipped
Build & Test / Server Test (0, 4) (push) Has been skipped
Build & Test / Server Test (1, 4) (push) Has been skipped
Build & Test / Analyze (javascript, affine) (push) Failing after 3s
Build & Test / Analyze (typescript, affine) (push) Failing after 3s
Build & Test / Analyze (typescript, blocksuite) (push) Failing after 3s
Build & Test / Mobile native build filter (push) Failing after 3s
Build & Test / Check yarn binary (push) Failing after 3s
Build & Test / E2E BlockSuite Test (1) (push) Failing after 4s
Build & Test / E2E BlockSuite Test (5) (push) Failing after 3s
Build & Test / Unit Test (4) (push) Has been skipped
Build & Test / Unit Test (5) (push) Has been skipped
Build & Test / Native Unit Test (push) Has been skipped
Build & Test / Server Test (2, 4) (push) Has been skipped
Build & Test / Server Test (3, 4) (push) Has been skipped
Build & Test / Server Test with Elasticsearch (push) Has been skipped
Build & Test / Server Test with Embedded Search (push) Has been skipped
Build & Test / Server Test with Manticore Search (push) Has been skipped
Build & Test / Server E2E Test (push) Has been skipped
Build & Test / Cloud Desktop E2E Test (push) Has been skipped
Build & Test / Cloud E2E Test 1/2 (push) Has been skipped
Build & Test / Cloud E2E Test 2/2 (push) Has been skipped
Build & Test / Build @affine/electron renderer (push) Failing after 3s
Build & Test / Copilot test filter (push) Failing after 4s
Build & Test / Lint Rust (push) Has been skipped
Build & Test / Build Android app (push) Has been skipped
Build & Test / Test Android app (push) Has been skipped
Build & Test / Run native tests (push) Has been skipped
Build & Test / Server Copilot Api Test (push) Has been skipped
Build & Test / Frontend Copilot E2E Test (3, 5) (push) Has been skipped
Build & Test / Frontend Copilot E2E Test (4, 5) (push) Has been skipped
Build & Test / Frontend Copilot E2E Test (1, 5) (push) Has been skipped
Build & Test / Frontend Copilot E2E Test (2, 5) (push) Has been skipped
Build & Test / Frontend Copilot E2E Test (5, 5) (push) Has been skipped
Build & Test / Desktop Test (ubuntu-latest, linux, x64, x86_64-unknown-linux-gnu, true) (push) Has been cancelled
Build & Test / Desktop Test (windows-latest, windows, x64, x86_64-pc-windows-msvc, true) (push) Has been cancelled
Build & Test / 3, 2, 1 Launch (push) Has been cancelled
Build & Test / Lint (push) Has been cancelled
Build & Test / Typecheck (push) Has been cancelled
Build & Test / Build iOS app (push) Has been cancelled
Build & Test / Build AFFiNE native (aarch64-apple-darwin) (push) Has been cancelled
Build & Test / E2E Test (1) (push) Has been cancelled
Build & Test / E2E Test (2) (push) Has been cancelled
Build & Test / E2E Test (3) (push) Has been cancelled
Build & Test / E2E Test (4) (push) Has been cancelled
Build & Test / E2E Test (5) (push) Has been cancelled
Build & Test / Build AFFiNE native (x86_64-apple-darwin) (push) Has been cancelled
Build & Test / Build AFFiNE native (aarch64-pc-windows-msvc) (push) Has been cancelled
Build & Test / Build AFFiNE native (x86_64-pc-windows-msvc) (push) Has been cancelled
Build & Test / Desktop Test (macos-latest, macos, arm64, aarch64-apple-darwin, true) (push) Has been cancelled
Build & Test / Desktop Test (macos-latest, macos, x64, x86_64-apple-darwin, false) (push) Has been cancelled
This commit is contained in:
57
packages/frontend/apps/electron/scripts/build-layers.ts
Normal file
57
packages/frontend/apps/electron/scripts/build-layers.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
import fs from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
|
||||
import * as esbuild from 'esbuild';
|
||||
|
||||
import { config, electronDir, mode, rootDir } from './common';
|
||||
|
||||
async function assertNoRuntimeWorkspaceDependencies() {
|
||||
const packageJson = JSON.parse(
|
||||
await fs.readFile(path.resolve(electronDir, 'package.json'), 'utf8')
|
||||
) as { dependencies?: Record<string, string> };
|
||||
const workspaceDependencies = Object.entries(
|
||||
packageJson.dependencies ?? {}
|
||||
).filter(([, version]) => version.startsWith('workspace:'));
|
||||
|
||||
if (workspaceDependencies.length) {
|
||||
throw new Error(
|
||||
`Electron workspace dependencies must be bundled and declared as devDependencies: ${workspaceDependencies
|
||||
.map(([name]) => name)
|
||||
.join(', ')}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async function buildLayers() {
|
||||
await assertNoRuntimeWorkspaceDependencies();
|
||||
const common = config();
|
||||
|
||||
const define: Record<string, string> = {
|
||||
...common.define,
|
||||
'process.env.NODE_ENV': `"${mode}"`,
|
||||
'process.env.BUILD_TYPE': `"${process.env.BUILD_TYPE || 'stable'}"`,
|
||||
};
|
||||
|
||||
if (process.env.BUILD_TYPE_OVERRIDE) {
|
||||
define['process.env.BUILD_TYPE_OVERRIDE'] =
|
||||
`"${process.env.BUILD_TYPE_OVERRIDE}"`;
|
||||
}
|
||||
|
||||
const metafile = process.env.METAFILE;
|
||||
|
||||
const result = await esbuild.build({
|
||||
...common,
|
||||
define: define,
|
||||
metafile: !!metafile,
|
||||
});
|
||||
|
||||
if (metafile) {
|
||||
await fs.writeFile(
|
||||
path.resolve(rootDir, `metafile-${Date.now()}.json`),
|
||||
JSON.stringify(result.metafile, null, 2)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
await buildLayers();
|
||||
console.log('Build layers done');
|
||||
111
packages/frontend/apps/electron/scripts/common.ts
Normal file
111
packages/frontend/apps/electron/scripts/common.ts
Normal file
@@ -0,0 +1,111 @@
|
||||
import { resolve } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
import { getBuildConfig } from '@affine-tools/utils/build-config';
|
||||
import { Package } from '@affine-tools/utils/workspace';
|
||||
import { sentryEsbuildPlugin } from '@sentry/esbuild-plugin';
|
||||
import type { BuildOptions, Plugin } from 'esbuild';
|
||||
|
||||
export const electronDir = fileURLToPath(new URL('..', import.meta.url));
|
||||
|
||||
export const rootDir = resolve(electronDir, '..', '..', '..', '..');
|
||||
|
||||
export const NODE_MAJOR_VERSION = 22;
|
||||
|
||||
export const mode = (process.env.NODE_ENV =
|
||||
process.env.NODE_ENV || 'development');
|
||||
|
||||
export const config = (): BuildOptions => {
|
||||
const define = {
|
||||
'process.env.GITHUB_SHA': process.env.GITHUB_SHA,
|
||||
'process.env.SENTRY_RELEASE': process.env.SENTRY_RELEASE,
|
||||
'process.env.SENTRY_DSN': process.env.SENTRY_DSN,
|
||||
'process.env.DEV_SERVER_URL': process.env.DEV_SERVER_URL,
|
||||
'process.env.NODE_ENV': process.env.NODE_ENV,
|
||||
REPLACE_ME_BUILD_ENV: process.env.BUILD_TYPE ?? 'stable',
|
||||
...Object.entries(
|
||||
getBuildConfig(new Package('@affine/electron'), {
|
||||
mode:
|
||||
process.env.NODE_ENV === 'production' ? 'production' : 'development',
|
||||
channel: (process.env.BUILD_TYPE as any) ?? 'canary',
|
||||
})
|
||||
).reduce(
|
||||
(def, [key, val]) => {
|
||||
def[`BUILD_CONFIG.${key}`] = val;
|
||||
return def;
|
||||
},
|
||||
{} as Record<string, any>
|
||||
),
|
||||
};
|
||||
|
||||
const plugins: Plugin[] = [];
|
||||
|
||||
if (
|
||||
process.env.SENTRY_AUTH_TOKEN &&
|
||||
process.env.SENTRY_ORG &&
|
||||
process.env.SENTRY_PROJECT
|
||||
) {
|
||||
plugins.push(
|
||||
sentryEsbuildPlugin({
|
||||
org: process.env.SENTRY_ORG,
|
||||
project: process.env.SENTRY_PROJECT,
|
||||
authToken: process.env.SENTRY_AUTH_TOKEN,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
plugins.push({
|
||||
name: 'no-side-effects',
|
||||
setup(build) {
|
||||
build.onResolve({ filter: /\.js/ }, async args => {
|
||||
if (args.pluginData) return; // Ignore this if we called ourselves
|
||||
|
||||
const { path, ...rest } = args;
|
||||
|
||||
// mark all blocksuite packages as side-effect free
|
||||
// because they will include a lot of files that are not used in node_modules
|
||||
if (rest.resolveDir.includes('blocksuite')) {
|
||||
rest.pluginData = true; // Avoid infinite recursion
|
||||
const result = await build.resolve(path, rest);
|
||||
|
||||
result.sideEffects = false;
|
||||
return result;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
entryPoints: [
|
||||
resolve(electronDir, './src/main/index.ts'),
|
||||
resolve(electronDir, './src/preload/index.ts'),
|
||||
resolve(electronDir, './src/helper/index.ts'),
|
||||
],
|
||||
entryNames: '[dir]',
|
||||
outdir: resolve(electronDir, './dist'),
|
||||
bundle: true,
|
||||
target: `node${NODE_MAJOR_VERSION}`,
|
||||
platform: 'node',
|
||||
external: ['electron', 'electron-updater', 'yjs', 'semver'],
|
||||
format: 'cjs',
|
||||
loader: {
|
||||
'.node': 'copy',
|
||||
},
|
||||
define: Object.entries(define).reduce(
|
||||
(def, [key, val]) => {
|
||||
def[key] =
|
||||
JSON.stringify(val) ??
|
||||
String(
|
||||
val
|
||||
); /* JSON.stringify(undefined) == undefined, but we need 'undefined' */
|
||||
return def;
|
||||
},
|
||||
{} as Record<string, string>
|
||||
),
|
||||
assetNames: '[name]',
|
||||
treeShaking: true,
|
||||
sourcemap: 'linked',
|
||||
plugins,
|
||||
};
|
||||
};
|
||||
117
packages/frontend/apps/electron/scripts/dev.ts
Normal file
117
packages/frontend/apps/electron/scripts/dev.ts
Normal file
@@ -0,0 +1,117 @@
|
||||
import type { ChildProcessWithoutNullStreams } from 'node:child_process';
|
||||
import { spawn } from 'node:child_process';
|
||||
import { resolve } from 'node:path';
|
||||
|
||||
import type { BuildContext } from 'esbuild';
|
||||
import * as esbuild from 'esbuild';
|
||||
import kill from 'tree-kill';
|
||||
|
||||
import { config, electronDir, rootDir } from './common';
|
||||
|
||||
// this means we don't spawn electron windows, mainly for testing
|
||||
const watchMode = process.argv.includes('--watch');
|
||||
|
||||
/** Messages on stderr that match any of the contained patterns will be stripped from output */
|
||||
const stderrFilterPatterns = [
|
||||
// warning about devtools extension
|
||||
// https://github.com/cawa-93/vite-electron-builder/issues/492
|
||||
// https://github.com/MarshallOfSound/electron-devtools-installer/issues/143
|
||||
/ExtensionLoadWarning/,
|
||||
];
|
||||
|
||||
let spawnProcess: ChildProcessWithoutNullStreams | null = null;
|
||||
|
||||
function spawnOrReloadElectron() {
|
||||
if (watchMode) {
|
||||
return;
|
||||
}
|
||||
if (spawnProcess !== null && spawnProcess.pid) {
|
||||
spawnProcess.off('exit', process.exit);
|
||||
kill(spawnProcess.pid);
|
||||
spawnProcess = null;
|
||||
}
|
||||
|
||||
const ext = process.platform === 'win32' ? '.cmd' : '';
|
||||
const exe = resolve(rootDir, 'node_modules', '.bin', `electron${ext}`);
|
||||
|
||||
// remove import loader option
|
||||
const NODE_OPTIONS = process.env.NODE_OPTIONS;
|
||||
if (NODE_OPTIONS) {
|
||||
process.env.NODE_OPTIONS = NODE_OPTIONS.replace(/--import=[^\s]*/, '');
|
||||
}
|
||||
|
||||
spawnProcess = spawn(exe, ['.', '--inspect'], {
|
||||
cwd: electronDir,
|
||||
env: process.env,
|
||||
shell: true,
|
||||
});
|
||||
|
||||
spawnProcess.stdout.on('data', d => {
|
||||
const str = d.toString().trim();
|
||||
if (str) {
|
||||
console.log(str);
|
||||
}
|
||||
});
|
||||
|
||||
spawnProcess.stderr.on('data', d => {
|
||||
const data = d.toString().trim();
|
||||
if (!data) return;
|
||||
const mayIgnore = stderrFilterPatterns.some(r => r.test(data));
|
||||
if (mayIgnore) return;
|
||||
console.error(data);
|
||||
});
|
||||
|
||||
// Stops the watch script when the application has quit
|
||||
spawnProcess.on('exit', code => {
|
||||
if (code && code !== 0) {
|
||||
console.log(`Electron exited with code ${code}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const common = config();
|
||||
|
||||
async function watchLayers() {
|
||||
let initialBuild = false;
|
||||
return new Promise<BuildContext>(resolve => {
|
||||
const buildContextPromise = esbuild.context({
|
||||
...common,
|
||||
plugins: [
|
||||
...(common.plugins ?? []),
|
||||
{
|
||||
name: 'electron-dev:reload-app-on-layers-change',
|
||||
setup(build) {
|
||||
build.onEnd(() => {
|
||||
if (initialBuild) {
|
||||
console.log(`[layers] has changed, [re]launching electron...`);
|
||||
spawnOrReloadElectron();
|
||||
} else {
|
||||
buildContextPromise.then(resolve).catch(e => {
|
||||
console.error(e);
|
||||
});
|
||||
initialBuild = true;
|
||||
}
|
||||
});
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
buildContextPromise
|
||||
.then(buildContext => {
|
||||
return buildContext.watch();
|
||||
})
|
||||
.catch(e => {
|
||||
console.error(e);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
await watchLayers();
|
||||
|
||||
if (watchMode) {
|
||||
console.log(`Watching for changes...`);
|
||||
} else {
|
||||
console.log('Starting electron...');
|
||||
spawnOrReloadElectron();
|
||||
console.log(`Electron is started, watching for changes...`);
|
||||
}
|
||||
74
packages/frontend/apps/electron/scripts/generate-assets.ts
Executable file
74
packages/frontend/apps/electron/scripts/generate-assets.ts
Executable file
@@ -0,0 +1,74 @@
|
||||
import { spawnSync } from 'node:child_process';
|
||||
import { createRequire } from 'node:module';
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
import fs from 'fs-extra';
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
const __dirname = fileURLToPath(new URL('.', import.meta.url));
|
||||
|
||||
const repoRootDir = path.join(__dirname, '..', '..', '..', '..', '..');
|
||||
const electronRootDir = path.join(__dirname, '..');
|
||||
const publicDistDir = path.join(electronRootDir, 'resources');
|
||||
const webDir = path.join(
|
||||
repoRootDir,
|
||||
'packages',
|
||||
'frontend',
|
||||
'apps',
|
||||
'electron-renderer'
|
||||
);
|
||||
const affineWebOutDir = path.join(webDir, 'dist');
|
||||
const publicAffineOutDir = path.join(publicDistDir, `web-static`);
|
||||
const releaseVersionEnv = process.env.RELEASE_VERSION || '';
|
||||
|
||||
console.log('build with following variables', {
|
||||
repoRootDir,
|
||||
electronRootDir,
|
||||
publicDistDir,
|
||||
affineSrcDir: webDir,
|
||||
affineSrcOutDir: affineWebOutDir,
|
||||
publicAffineOutDir,
|
||||
releaseVersionEnv,
|
||||
});
|
||||
|
||||
// step 0: check version match
|
||||
const electronPackageJson = require(`${electronRootDir}/package.json`);
|
||||
if (releaseVersionEnv && electronPackageJson.version !== releaseVersionEnv) {
|
||||
throw new Error(
|
||||
`Version mismatch, expected ${releaseVersionEnv} but got ${electronPackageJson.version}`
|
||||
);
|
||||
}
|
||||
// copy web dist files to electron dist
|
||||
|
||||
const cwd = repoRootDir;
|
||||
|
||||
// step 1: build web dist
|
||||
if (!process.env.SKIP_WEB_BUILD) {
|
||||
spawnSync('yarn', ['affine', '@affine/electron-renderer', 'build'], {
|
||||
stdio: 'inherit',
|
||||
env: process.env,
|
||||
cwd,
|
||||
shell: true,
|
||||
});
|
||||
|
||||
spawnSync('yarn', ['affine', '@affine/electron', 'build'], {
|
||||
stdio: 'inherit',
|
||||
env: process.env,
|
||||
cwd,
|
||||
shell: true,
|
||||
});
|
||||
|
||||
await fs.move(affineWebOutDir, publicAffineOutDir, { overwrite: true });
|
||||
}
|
||||
|
||||
// step 2: update app-updater.yml content with build type in resources folder
|
||||
if (process.env.BUILD_TYPE === 'internal') {
|
||||
const appUpdaterYml = path.join(publicDistDir, 'app-update.yml');
|
||||
const appUpdaterYmlContent = await fs.readFile(appUpdaterYml, 'utf-8');
|
||||
const newAppUpdaterYmlContent = appUpdaterYmlContent.replace(
|
||||
'AFFiNE',
|
||||
'AFFiNE-Releases'
|
||||
);
|
||||
await fs.writeFile(appUpdaterYml, newAppUpdaterYmlContent);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
const outputRoot = fileURLToPath(
|
||||
new URL(
|
||||
'../out/canary/AFFiNE-canary-darwin-arm64/AFFiNE-canary.app/Contents/Resources',
|
||||
import.meta.url
|
||||
)
|
||||
);
|
||||
|
||||
// todo: use asar package to check contents
|
||||
fs.existsSync(path.resolve(outputRoot, 'app.asar'));
|
||||
|
||||
console.log('Output check passed');
|
||||
94
packages/frontend/apps/electron/scripts/make-env.ts
Normal file
94
packages/frontend/apps/electron/scripts/make-env.ts
Normal file
@@ -0,0 +1,94 @@
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { parseArgs } from 'node:util';
|
||||
|
||||
import debug from 'debug';
|
||||
import { z } from 'zod';
|
||||
|
||||
const log = debug('affine:make-env');
|
||||
|
||||
const ReleaseTypeSchema = z.enum(['stable', 'beta', 'canary', 'internal']);
|
||||
|
||||
const __dirname = fileURLToPath(new URL('.', import.meta.url));
|
||||
|
||||
const REPO_ROOT = path.resolve(__dirname, '..', '..', '..', '..', '..');
|
||||
const ROOT = path.resolve(__dirname, '..');
|
||||
|
||||
const envBuildType = (process.env.BUILD_TYPE || 'canary').trim().toLowerCase();
|
||||
const buildType = ReleaseTypeSchema.parse(envBuildType);
|
||||
const stableBuild = buildType === 'stable';
|
||||
const productName = !stableBuild ? `AFFiNE-${buildType}` : 'AFFiNE';
|
||||
const icoPath = path.join(
|
||||
ROOT,
|
||||
!stableBuild
|
||||
? `./resources/icons/icon_${buildType}.ico`
|
||||
: './resources/icons/icon.ico'
|
||||
);
|
||||
|
||||
const iconX64PngPath = path.join(
|
||||
ROOT,
|
||||
`./resources/icons/icon_${buildType}_64x64.png`
|
||||
);
|
||||
|
||||
const iconX512PngPath = path.join(
|
||||
ROOT,
|
||||
`./resources/icons/icon_${buildType}_512x512.png`
|
||||
);
|
||||
|
||||
const icnsPath = path.join(
|
||||
ROOT,
|
||||
!stableBuild
|
||||
? `./resources/icons/icon_${buildType}.icns`
|
||||
: './resources/icons/icon.icns'
|
||||
);
|
||||
|
||||
const iconPngPath = path.join(ROOT, './resources/icons/icon.png');
|
||||
|
||||
const iconUrl = `https://cdn.affine.pro/app-icons/icon_${buildType}.ico`;
|
||||
|
||||
log(`buildType=${buildType}, productName=${productName}, icoPath=${icoPath}`);
|
||||
|
||||
const {
|
||||
values: { arch, platform },
|
||||
} = parseArgs({
|
||||
options: {
|
||||
arch: {
|
||||
type: 'string',
|
||||
description: 'The architecture to build for',
|
||||
default: process.arch,
|
||||
},
|
||||
platform: {
|
||||
type: 'string',
|
||||
description: 'The platform to build for',
|
||||
default: process.platform,
|
||||
},
|
||||
},
|
||||
allowPositionals: true,
|
||||
strict: false,
|
||||
});
|
||||
|
||||
log(`parsed args: arch=${arch}, platform=${platform}`);
|
||||
|
||||
const appIdMap = {
|
||||
internal: 'pro.affine.internal',
|
||||
canary: 'pro.affine.canary',
|
||||
beta: 'pro.affine.beta',
|
||||
stable: 'pro.affine.app',
|
||||
};
|
||||
|
||||
export {
|
||||
appIdMap,
|
||||
arch,
|
||||
buildType,
|
||||
icnsPath,
|
||||
iconPngPath,
|
||||
iconUrl,
|
||||
iconX64PngPath,
|
||||
iconX512PngPath,
|
||||
icoPath,
|
||||
platform,
|
||||
productName,
|
||||
REPO_ROOT,
|
||||
ROOT,
|
||||
stableBuild,
|
||||
};
|
||||
94
packages/frontend/apps/electron/scripts/make-nsis.ts
Normal file
94
packages/frontend/apps/electron/scripts/make-nsis.ts
Normal file
@@ -0,0 +1,94 @@
|
||||
import path from 'node:path';
|
||||
|
||||
import { buildForge } from 'app-builder-lib';
|
||||
import debug from 'debug';
|
||||
import fs from 'fs-extra';
|
||||
|
||||
import {
|
||||
appIdMap,
|
||||
arch,
|
||||
buildType,
|
||||
iconPngPath,
|
||||
icoPath,
|
||||
platform,
|
||||
productName,
|
||||
REPO_ROOT,
|
||||
ROOT,
|
||||
} from './make-env.js';
|
||||
|
||||
const log = debug('affine:make-nsis');
|
||||
|
||||
async function make() {
|
||||
const appName = productName;
|
||||
const makeDir = path.resolve(ROOT, 'out', buildType, 'make');
|
||||
const outPath = path.resolve(makeDir, `nsis.windows/${arch}`);
|
||||
const appDirectory = path.resolve(
|
||||
ROOT,
|
||||
'out',
|
||||
buildType,
|
||||
`${appName}-${platform}-${arch}`
|
||||
);
|
||||
|
||||
await fs.ensureDir(outPath);
|
||||
await fs.emptyDir(outPath);
|
||||
|
||||
// create tmp dir
|
||||
const tmpPath = await fs.mkdtemp(appName);
|
||||
|
||||
// copy app to tmp dir
|
||||
log(`Copying app to ${tmpPath}`);
|
||||
await fs.copy(appDirectory, tmpPath);
|
||||
|
||||
log(`Calling app-builder-lib's buildForge() with ${tmpPath}`);
|
||||
const output = await buildForge(
|
||||
{ dir: tmpPath },
|
||||
{
|
||||
win: [`nsis:${arch}`],
|
||||
// @ts-expect-error - upstream type is wrong
|
||||
publish: null, // buildForge will incorrectly publish the build
|
||||
config: {
|
||||
appId: appIdMap[buildType],
|
||||
productName,
|
||||
executableName: productName,
|
||||
icon: iconPngPath,
|
||||
extraMetadata: {
|
||||
// do not use package.json's name
|
||||
name: productName,
|
||||
},
|
||||
nsis: {
|
||||
differentialPackage: false,
|
||||
perMachine: false,
|
||||
oneClick: false,
|
||||
license: path.resolve(REPO_ROOT, 'LICENSE'),
|
||||
include: path.resolve(ROOT, 'scripts', 'nsis-installer.nsh'),
|
||||
installerIcon: icoPath,
|
||||
allowToChangeInstallationDirectory: true,
|
||||
installerSidebar: path.resolve(
|
||||
ROOT,
|
||||
'resources',
|
||||
'icons',
|
||||
'nsis-sidebar.bmp'
|
||||
),
|
||||
},
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
// Move the output to the actual output folder, app-builder-lib might get it wrong
|
||||
log('making nsis.windows done:', output);
|
||||
|
||||
const result: Array<string> = [];
|
||||
for (const file of output) {
|
||||
const filePath = path.resolve(outPath, path.basename(file));
|
||||
result.push(filePath);
|
||||
|
||||
await fs.move(file, filePath);
|
||||
}
|
||||
|
||||
// cleanup
|
||||
await fs.remove(tmpPath);
|
||||
}
|
||||
|
||||
make().catch(e => {
|
||||
console.error(e);
|
||||
});
|
||||
84
packages/frontend/apps/electron/scripts/make-squirrel.ts
Normal file
84
packages/frontend/apps/electron/scripts/make-squirrel.ts
Normal file
@@ -0,0 +1,84 @@
|
||||
import path from 'node:path';
|
||||
|
||||
import debug from 'debug';
|
||||
import type { Options as ElectronWinstallerOptions } from 'electron-winstaller';
|
||||
import { convertVersion, createWindowsInstaller } from 'electron-winstaller';
|
||||
import fs from 'fs-extra';
|
||||
|
||||
import {
|
||||
arch,
|
||||
buildType,
|
||||
iconUrl,
|
||||
icoPath,
|
||||
platform,
|
||||
productName,
|
||||
ROOT,
|
||||
} from './make-env.js';
|
||||
|
||||
const log = debug('affine:make-squirrel');
|
||||
|
||||
// taking from https://github.com/electron/forge/blob/main/packages/maker/squirrel/src/MakerSquirrel.ts
|
||||
// it was for forge's maker, but can be used standalone as well
|
||||
async function make() {
|
||||
const appName = productName;
|
||||
const makeDir = path.resolve(ROOT, 'out', buildType, 'make');
|
||||
const outPath = path.resolve(makeDir, `squirrel.windows/${arch}`);
|
||||
const appDirectory = path.resolve(
|
||||
ROOT,
|
||||
'out',
|
||||
buildType,
|
||||
`${appName}-${platform}-${arch}`
|
||||
);
|
||||
log('making squirrel.windows: appDirectory', appDirectory);
|
||||
await fs.ensureDir(outPath);
|
||||
|
||||
const packageJSON = await fs.readJson(path.resolve(ROOT, 'package.json'));
|
||||
|
||||
const winstallerConfig: ElectronWinstallerOptions = {
|
||||
name: appName,
|
||||
title: appName,
|
||||
noMsi: true,
|
||||
exe: `${appName}.exe`,
|
||||
setupExe: `${appName}-${packageJSON.version} Setup.exe`,
|
||||
version: packageJSON.version,
|
||||
appDirectory,
|
||||
outputDirectory: outPath,
|
||||
iconUrl: iconUrl,
|
||||
setupIcon: icoPath,
|
||||
loadingGif: path.resolve(ROOT, './resources/icons/affine_installing.gif'),
|
||||
};
|
||||
|
||||
await createWindowsInstaller(winstallerConfig);
|
||||
const nupkgVersion = convertVersion(packageJSON.version);
|
||||
const artifacts = [
|
||||
path.resolve(outPath, 'RELEASES'),
|
||||
path.resolve(outPath, winstallerConfig.setupExe || `${appName}Setup.exe`),
|
||||
path.resolve(
|
||||
outPath,
|
||||
`${winstallerConfig.name}-${nupkgVersion}-full.nupkg`
|
||||
),
|
||||
];
|
||||
const deltaPath = path.resolve(
|
||||
outPath,
|
||||
`${winstallerConfig.name}-${nupkgVersion}-delta.nupkg`
|
||||
);
|
||||
if (
|
||||
(winstallerConfig.remoteReleases && !winstallerConfig.noDelta) ||
|
||||
(await fs.pathExists(deltaPath))
|
||||
) {
|
||||
artifacts.push(deltaPath);
|
||||
}
|
||||
const msiPath = path.resolve(
|
||||
outPath,
|
||||
winstallerConfig.setupMsi || `${appName}Setup.msi`
|
||||
);
|
||||
if (!winstallerConfig.noMsi && (await fs.pathExists(msiPath))) {
|
||||
artifacts.push(msiPath);
|
||||
}
|
||||
log('making squirrel.windows done:', artifacts);
|
||||
return artifacts;
|
||||
}
|
||||
|
||||
make().catch(e => {
|
||||
console.error(e);
|
||||
});
|
||||
@@ -0,0 +1 @@
|
||||
ManifestDPIAware true
|
||||
3
packages/frontend/apps/electron/scripts/package.json
Normal file
3
packages/frontend/apps/electron/scripts/package.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"type": "module"
|
||||
}
|
||||
Reference in New Issue
Block a user