mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-09-22 19:53:48 +08:00
chore: add monorepo tools (#9196)
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
import type { BUILD_CONFIG_TYPE } from '@affine/env/global';
|
||||
import type { Package } from '@affine-tools/utils/workspace';
|
||||
|
||||
import { PackageToDistribution } from './distribution';
|
||||
|
||||
export interface BuildFlags {
|
||||
channel: 'stable' | 'beta' | 'internal' | 'canary';
|
||||
mode: 'development' | 'production';
|
||||
}
|
||||
|
||||
export function getBuildConfig(
|
||||
pkg: Package,
|
||||
buildFlags: BuildFlags
|
||||
): BUILD_CONFIG_TYPE {
|
||||
const distribution = PackageToDistribution.get(pkg.name);
|
||||
|
||||
if (!distribution) {
|
||||
throw new Error(`Distribution for ${pkg.name} is not found`);
|
||||
}
|
||||
|
||||
const buildPreset: Record<BuildFlags['channel'], BUILD_CONFIG_TYPE> = {
|
||||
get stable() {
|
||||
return {
|
||||
debug: buildFlags.mode === 'development',
|
||||
distribution,
|
||||
isDesktopEdition: (
|
||||
['web', 'desktop', 'admin'] as BUILD_CONFIG_TYPE['distribution'][]
|
||||
).includes(distribution),
|
||||
isMobileEdition: (
|
||||
['mobile', 'ios', 'android'] as BUILD_CONFIG_TYPE['distribution'][]
|
||||
).includes(distribution),
|
||||
isElectron: distribution === 'desktop',
|
||||
isWeb: distribution === 'web',
|
||||
isMobileWeb: distribution === 'mobile',
|
||||
isIOS: distribution === 'ios',
|
||||
isAndroid: distribution === 'android',
|
||||
isAdmin: distribution === 'admin',
|
||||
|
||||
appBuildType: 'stable' as const,
|
||||
serverUrlPrefix: 'https://app.affine.pro',
|
||||
appVersion: pkg.version,
|
||||
editorVersion: pkg.dependencies['@blocksuite/affine'],
|
||||
githubUrl: 'https://github.com/toeverything/AFFiNE',
|
||||
changelogUrl: 'https://affine.pro/what-is-new',
|
||||
downloadUrl: 'https://affine.pro/download',
|
||||
imageProxyUrl: '/api/worker/image-proxy',
|
||||
linkPreviewUrl: '/api/worker/link-preview',
|
||||
};
|
||||
},
|
||||
get beta() {
|
||||
return {
|
||||
...this.stable,
|
||||
appBuildType: 'beta' as const,
|
||||
serverUrlPrefix: 'https://insider.affine.pro',
|
||||
changelogUrl: 'https://github.com/toeverything/AFFiNE/releases',
|
||||
};
|
||||
},
|
||||
get internal() {
|
||||
return {
|
||||
...this.stable,
|
||||
appBuildType: 'internal' as const,
|
||||
serverUrlPrefix: 'https://insider.affine.pro',
|
||||
changelogUrl: 'https://github.com/toeverything/AFFiNE/releases',
|
||||
};
|
||||
},
|
||||
// canary will be aggressive and enable all features
|
||||
get canary() {
|
||||
return {
|
||||
...this.stable,
|
||||
appBuildType: 'canary' as const,
|
||||
serverUrlPrefix: 'https://affine.fail',
|
||||
changelogUrl: 'https://github.com/toeverything/AFFiNE/releases',
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
const currentBuild = buildFlags.channel;
|
||||
|
||||
if (!(currentBuild in buildPreset)) {
|
||||
throw new Error(`BUILD_TYPE ${currentBuild} is not supported`);
|
||||
}
|
||||
|
||||
const currentBuildPreset = buildPreset[currentBuild];
|
||||
|
||||
const environmentPreset = {
|
||||
changelogUrl: process.env.CHANGELOG_URL ?? currentBuildPreset.changelogUrl,
|
||||
};
|
||||
|
||||
if (buildFlags.mode === 'development') {
|
||||
currentBuildPreset.serverUrlPrefix = 'http://localhost:8080';
|
||||
}
|
||||
|
||||
return {
|
||||
...currentBuildPreset,
|
||||
// environment preset will overwrite current build preset
|
||||
// this environment variable is for debug proposes only
|
||||
// do not put them into CI
|
||||
...(process.env.CI ? {} : environmentPreset),
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user