forked from toeverything/AFFiNE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ts
76 lines (64 loc) · 1.87 KB
/
build.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import path from 'node:path';
import webpack from 'webpack';
import type { BuildFlags } from '../config/index';
import { projectRoot } from '../config/index';
import { buildI18N } from '../util/i18n';
import { createWebpackConfig } from '../webpack/webpack.config';
let cwd: string;
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const buildType = process.env.BUILD_TYPE_OVERRIDE || process.env.BUILD_TYPE;
if (process.env.BUILD_TYPE_OVERRIDE) {
process.env.BUILD_TYPE = process.env.BUILD_TYPE_OVERRIDE;
}
const getChannel = () => {
switch (buildType) {
case 'canary':
case 'beta':
case 'stable':
case 'internal':
return buildType;
case '':
throw new Error('BUILD_TYPE is not set');
default: {
throw new Error(
`BUILD_TYPE must be one of canary, beta, stable, internal, received [${buildType}]`
);
}
}
};
let entry: string | undefined;
const { DISTRIBUTION } = process.env;
const getDistribution = () => {
switch (DISTRIBUTION) {
case 'browser':
case undefined:
cwd = path.join(projectRoot, 'packages/frontend/web');
return 'browser';
case 'desktop':
cwd = path.join(projectRoot, 'packages/frontend/electron');
entry = path.join(cwd, 'renderer', 'index.tsx');
return DISTRIBUTION;
default: {
throw new Error('DISTRIBUTION must be one of browser, desktop');
}
}
};
const flags = {
distribution: getDistribution(),
mode: 'production',
channel: getChannel(),
coverage: process.env.COVERAGE === 'true',
entry,
} satisfies BuildFlags;
buildI18N();
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
webpack(createWebpackConfig(cwd!, flags), (err, stats) => {
if (err) {
console.error(err);
process.exit(1);
}
if (stats?.hasErrors()) {
console.error(stats.toString('errors-only'));
process.exit(1);
}
});