feat(cli): build infra and plugins before dev-core (#3470)
This commit is contained in:
@@ -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,22 +94,72 @@ flags.channel = buildFlags.channel as any;
|
|||||||
flags.coverage = buildFlags.coverage;
|
flags.coverage = buildFlags.coverage;
|
||||||
|
|
||||||
watchI18N();
|
watchI18N();
|
||||||
spawn(
|
|
||||||
'node',
|
function awaitChildProcess(child: ChildProcess): Promise<number> {
|
||||||
[
|
return new Promise<number>((resolve, reject) => {
|
||||||
'--loader',
|
const handleExitCode = (code: number | null) => {
|
||||||
'ts-node/esm/transpile-only',
|
if (code) {
|
||||||
'../../node_modules/webpack/bin/webpack.js',
|
reject(
|
||||||
flags.mode === 'development' ? 'serve' : undefined,
|
new Error(
|
||||||
'--mode',
|
`Child process at ${
|
||||||
flags.mode === 'development' ? 'development' : 'production',
|
(child as any).cwd
|
||||||
'--env',
|
} fails: ${child.spawnargs.join(' ')}`
|
||||||
'flags=' + Buffer.from(JSON.stringify(flags), 'utf-8').toString('hex'),
|
)
|
||||||
].filter((v): v is string => !!v),
|
);
|
||||||
{
|
} else {
|
||||||
cwd,
|
resolve(0);
|
||||||
stdio: 'inherit',
|
}
|
||||||
shell: true,
|
};
|
||||||
env: process.env,
|
|
||||||
}
|
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(
|
||||||
|
'node',
|
||||||
|
[
|
||||||
|
'--loader',
|
||||||
|
'ts-node/esm/transpile-only',
|
||||||
|
'../../node_modules/webpack/bin/webpack.js',
|
||||||
|
flags.mode === 'development' ? 'serve' : undefined,
|
||||||
|
'--mode',
|
||||||
|
flags.mode === 'development' ? 'development' : 'production',
|
||||||
|
'--env',
|
||||||
|
'flags=' + Buffer.from(JSON.stringify(flags), 'utf-8').toString('hex'),
|
||||||
|
].filter((v): v is string => !!v),
|
||||||
|
{
|
||||||
|
cwd,
|
||||||
|
stdio: 'inherit',
|
||||||
|
shell: true,
|
||||||
|
env: process.env,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error during build:', error);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user