universo-platform-2d
84 строки · 2.9 Кб
1import type { BUILD_CONFIG_TYPE } from '@affine/env/global';
2
3import packageJson from '../../package.json' assert { type: 'json' };
4import type { BuildFlags } from '../config';
5
6export function getBuildConfig(buildFlags: BuildFlags): BUILD_CONFIG_TYPE {
7const buildPreset: Record<BuildFlags['channel'], BUILD_CONFIG_TYPE> = {
8get stable() {
9return {
10debug: buildFlags.mode === 'development',
11distribution: buildFlags.distribution,
12isDesktopEdition: (
13['web', 'desktop', 'admin'] as BuildFlags['distribution'][]
14).includes(buildFlags.distribution),
15isMobileEdition: (['mobile'] as BuildFlags['distribution'][]).includes(
16buildFlags.distribution
17),
18isElectron: buildFlags.distribution === 'desktop',
19isWeb: buildFlags.distribution === 'web',
20isMobileWeb: buildFlags.distribution === 'mobile',
21
22isSelfHosted: process.env.SELF_HOSTED === 'true',
23appBuildType: 'stable' as const,
24serverUrlPrefix: 'https://app.affine.pro',
25appVersion: packageJson.version,
26editorVersion: packageJson.devDependencies['@blocksuite/affine'],
27githubUrl: 'https://github.com/toeverything/AFFiNE',
28changelogUrl: 'https://affine.pro/what-is-new',
29downloadUrl: 'https://affine.pro/download',
30imageProxyUrl: '/api/worker/image-proxy',
31linkPreviewUrl: '/api/worker/link-preview',
32};
33},
34get beta() {
35return {
36...this.stable,
37appBuildType: 'beta' as const,
38serverUrlPrefix: 'https://insider.affine.pro',
39changelogUrl: 'https://github.com/toeverything/AFFiNE/releases',
40};
41},
42get internal() {
43return {
44...this.stable,
45appBuildType: 'internal' as const,
46serverUrlPrefix: 'https://insider.affine.pro',
47changelogUrl: 'https://github.com/toeverything/AFFiNE/releases',
48};
49},
50// canary will be aggressive and enable all features
51get canary() {
52return {
53...this.stable,
54appBuildType: 'canary' as const,
55serverUrlPrefix: 'https://affine.fail',
56changelogUrl: 'https://github.com/toeverything/AFFiNE/releases',
57};
58},
59};
60
61const currentBuild = buildFlags.channel;
62
63if (!(currentBuild in buildPreset)) {
64throw new Error(`BUILD_TYPE ${currentBuild} is not supported`);
65}
66
67const currentBuildPreset = buildPreset[currentBuild];
68
69const environmentPreset = {
70changelogUrl: process.env.CHANGELOG_URL ?? currentBuildPreset.changelogUrl,
71};
72
73if (buildFlags.mode === 'development') {
74currentBuildPreset.serverUrlPrefix = 'http://localhost:8080';
75}
76
77return {
78...currentBuildPreset,
79// environment preset will overwrite current build preset
80// this environment variable is for debug proposes only
81// do not put them into CI
82...(process.env.CI ? {} : environmentPreset),
83};
84}
85