forked from QwikDev/qwik
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.ts
139 lines (121 loc) · 4.1 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import { BuildConfig, ensureDir, panic } from './util';
import { apiExtractor } from './api';
import { buildCreateQwikCli } from './create-qwik-cli';
import { buildEslint } from './eslint';
import { buildPlatformBinding, copyPlatformBindingWasm } from './binding-platform';
import { buildQwikCity } from './qwik-city';
import { buildQwikReact } from './qwik-react';
import { buildWasmBinding } from './binding-wasm';
import { copyFiles } from './copy-files';
import { emptyDir } from './util';
import { generatePackageJson } from './package-json';
import {
commitPrepareReleaseVersion,
prepareReleaseVersion,
publish,
setDevVersion,
setReleaseVersion,
} from './release';
import { submoduleBuild } from './submodule-build';
import { submoduleCli } from './submodule-cli';
import { submoduleCore } from './submodule-core';
import { submoduleJsxRuntime } from './submodule-jsx-runtime';
import { submoduleOptimizer } from './submodule-optimizer';
import { submoduleQwikLoader } from './submodule-qwikloader';
import { submoduleServer } from './submodule-server';
import { submoduleTesting } from './submodule-testing';
import { tsc } from './tsc';
import { validateBuild } from './validate-build';
import { buildQwikAuth } from './qwik-auth';
/**
* Complete a full build for all of the package's submodules. Passed in
* config has all the correct absolute paths to read from and write to.
* Additionally, a dev build does not empty the directory, and uses
* esbuild for each of the submodules for speed. A production build will
* use TSC + Rollup + Terser for the core submodule.
*/
export async function build(config: BuildConfig) {
config.devRelease = config.devRelease || (!!config.release && config.setDistTag === 'dev');
try {
if (config.prepareRelease) {
// locally set the version for the upcoming release
await prepareReleaseVersion(config);
} else if (config.release && !config.dryRun && !config.devRelease) {
// ci release, npm publish
await setReleaseVersion(config);
} else {
// local build or ci commit that's not for publishing
await setDevVersion(config);
}
console.log(
`🌎 Qwik v${config.distVersion}`,
`[node ${process.version}, ${process.platform}/${process.arch}]`
);
if (config.tsc) {
await tsc(config);
}
if (config.build) {
if (config.dev) {
ensureDir(config.distPkgDir);
} else {
emptyDir(config.distPkgDir);
}
// create the dist package.json first so we get the version set
await generatePackageJson(config);
await Promise.all([
submoduleCore(config),
submoduleJsxRuntime(config),
submoduleQwikLoader(config),
submoduleBuild(config),
submoduleTesting(config),
submoduleCli(config),
copyFiles(config),
]);
// server bundling must happen after the results from the others
// because it inlines the qwik loader and prefetch scripts
await Promise.all([submoduleServer(config), submoduleOptimizer(config)]);
}
if (config.eslint) {
await buildEslint(config);
}
if (config.platformBinding) {
await buildPlatformBinding(config);
} else if (config.platformBindingWasmCopy) {
await copyPlatformBindingWasm(config);
}
if (config.wasm) {
await buildWasmBinding(config);
}
if (config.qwikcity) {
await buildQwikCity(config);
}
if (config.qwikreact) {
await buildQwikReact(config);
}
if (config.qwikauth) {
await buildQwikAuth(config);
}
if (config.api) {
apiExtractor(config);
}
if (config.validate) {
await validateBuild(config);
}
if (config.cli) {
await buildCreateQwikCli(config);
await submoduleCli(config);
}
if (config.prepareRelease) {
// locally commit the package.json change
await commitPrepareReleaseVersion(config);
} else if (config.release) {
// release from ci
await publish(config);
}
if (config.watch) {
console.log('👀 watching...');
}
} catch (e: any) {
panic(String(e ? e.stack || e : 'Error'));
}
}