-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathprepare.js
More file actions
54 lines (45 loc) · 1.61 KB
/
Copy pathprepare.js
File metadata and controls
54 lines (45 loc) · 1.61 KB
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
/**
* @license
* Copyright 2026 Qwen Team
* SPDX-License-Identifier: Apache-2.0
*/
import { spawnSync } from 'node:child_process';
// Release workflow jobs set this when they run explicit build/bundle steps after
// npm ci. Workflows that rely on prepare-during-install should leave it unset.
const skipPrepare = ['1', 'true'].includes(
(process.env.QWEN_SKIP_PREPARE ?? '').toLowerCase(),
);
if (skipPrepare) {
// The heavy build/bundle/husky are skipped, but git-commit.ts (gitignored,
// imported by e.g. cli's systemInfo) is still required to build or typecheck
// the packages that import it. Generate it here so a later per-workspace
// build/typecheck — such as the review tooling's — doesn't fail on the
// missing module. The non-skip path generates it via `npm run build`.
run('npm', ['run', 'generate']);
console.log(
'Skipping prepare build/bundle/husky because QWEN_SKIP_PREPARE is set.',
);
process.exit(0);
}
run('husky');
run('npm', ['run', 'build']);
run('npm', ['run', 'bundle']);
function run(command, args = []) {
const result = spawnSync(command, args, {
shell: process.platform === 'win32',
stdio: 'inherit',
});
const label = args.length ? `${command} ${args.join(' ')}` : command;
if (result.error) {
console.error(`prepare: ${label} failed: ${result.error.message}`);
process.exit(1);
}
if (result.signal) {
console.error(`prepare: ${label} killed by signal ${result.signal}`);
process.exit(1);
}
if (result.status !== 0) {
console.error(`prepare: ${label} exited with status ${result.status}`);
process.exit(result.status ?? 1);
}
}