build(electron): allow customizing channel type for internal build (#4511)

This commit is contained in:
Peng Xiao
2023-10-17 09:15:19 +08:00
committed by GitHub
parent a0095496d7
commit 5e9eeaddbd
6 changed files with 47 additions and 17 deletions

View File

@@ -15,12 +15,21 @@ if (process.platform === 'win32') {
async function buildLayers() {
const common = config();
const define = {
'process.env.NODE_ENV': `"${NODE_ENV}"`,
'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}"`;
}
await esbuild.build({
...common.layers,
define: {
'process.env.NODE_ENV': `"${NODE_ENV}"`,
'process.env.BUILD_TYPE': `"${process.env.BUILD_TYPE || 'stable'}"`,
},
define: define,
});
}

View File

@@ -46,6 +46,8 @@ if (!process.env.SKIP_WEB_BUILD) {
await $`yarn -T run build:plugins`;
await $`yarn nx build @affine/core`;
await $`yarn workspace @affine/electron build`;
// step 1.5: amend sourceMappingURL to allow debugging in devtools
await glob('**/*.{js,css}', { cwd: affineCoreOutDir }).then(files => {
return files.map(async file => {

View File

@@ -7,9 +7,16 @@ export const ReleaseTypeSchema = z.enum([
'internal',
]);
export const envBuildType = (process.env.BUILD_TYPE || 'canary')
export const envBuildType = (
process.env.BUILD_TYPE_OVERRIDE ||
process.env.BUILD_TYPE ||
'canary'
)
.trim()
.toLowerCase();
export const overrideSession = process.env.BUILD_TYPE === 'internal';
export const buildType = ReleaseTypeSchema.parse(envBuildType);
export const mode = process.env.NODE_ENV;

View File

@@ -1,8 +1,11 @@
import './security-restrictions';
import path from 'node:path';
import { app } from 'electron';
import { createApplicationMenu } from './application-menu/create';
import { buildType, overrideSession } from './config';
import { setupDeepLink } from './deep-link';
import { registerEvents } from './events';
import { registerHandlers } from './handlers';
@@ -14,6 +17,14 @@ import { registerUpdater } from './updater';
app.enableSandbox();
// use the same data for internal & beta for testing
if (overrideSession) {
const appName = buildType === 'stable' ? 'AFFiNE' : `AFFiNE-${buildType}`;
const userDataPath = path.join(app.getPath('appData'), appName);
app.setPath('userData', userDataPath);
app.setPath('sessionData', userDataPath);
}
if (require('electron-squirrel-startup')) app.quit();
// allow tests to overwrite app name through passing args
if (process.argv.includes('--app-name')) {

View File

@@ -1,23 +1,12 @@
import { app } from 'electron';
import { autoUpdater } from 'electron-updater';
import { z } from 'zod';
import { isMacOS, isWindows } from '../../shared/utils';
import { buildType } from '../config';
import { logger } from '../logger';
import { CustomGitHubProvider } from './custom-github-provider';
import { updaterSubjects } from './event';
export const ReleaseTypeSchema = z.enum([
'stable',
'beta',
'canary',
'internal',
]);
export const envBuildType = (process.env.BUILD_TYPE || 'canary')
.trim()
.toLowerCase();
export const buildType = ReleaseTypeSchema.parse(envBuildType);
const mode = process.env.NODE_ENV;
const isDev = mode === 'development';