feat(cli): build infra and plugins before dev-core (#3470)

This commit is contained in:
Pratik Kumar
2023-08-06 22:32:30 +05:30
committed by GitHub
parent a74a549b8c
commit 5bc923d58e

View File

@@ -1,3 +1,4 @@
import type { ChildProcess } from 'node:child_process';
import { spawn } from 'node:child_process'; import { spawn } from 'node:child_process';
import { existsSync } from 'node:fs'; import { existsSync } from 'node:fs';
import path from 'node:path'; import path from 'node:path';
@@ -93,6 +94,51 @@ flags.channel = buildFlags.channel as any;
flags.coverage = buildFlags.coverage; flags.coverage = buildFlags.coverage;
watchI18N(); watchI18N();
function awaitChildProcess(child: ChildProcess): Promise<number> {
return new Promise<number>((resolve, reject) => {
const handleExitCode = (code: number | null) => {
if (code) {
reject(
new Error(
`Child process at ${
(child as any).cwd
} fails: ${child.spawnargs.join(' ')}`
)
);
} else {
resolve(0);
}
};
child.on('error', () => handleExitCode(child.exitCode));
child.on('exit', code => handleExitCode(code));
});
}
try {
// Build:infra
await awaitChildProcess(
spawn('yarn', ['build:infra'], {
cwd,
stdio: 'inherit',
shell: true,
env: process.env,
})
);
// Build:plugins
await awaitChildProcess(
spawn('yarn', ['build:plugins'], {
cwd,
stdio: 'inherit',
shell: true,
env: process.env,
})
);
// Start webpack
await awaitChildProcess(
spawn( spawn(
'node', 'node',
[ [
@@ -111,4 +157,9 @@ spawn(
shell: true, shell: true,
env: process.env, env: process.env,
} }
)
); );
} catch (error) {
console.error('Error during build:', error);
process.exit(1);
}