Skip to content

Commit

Permalink
Rework codegen process spawn (#2171)
Browse files Browse the repository at this point in the history
  • Loading branch information
frandiox committed May 30, 2024
1 parent 91c7698 commit af90c44
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions packages/cli/src/lib/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,39 @@ export function spawnCodegenProcess({
appDirectory,
configFilePath,
}: CodegenOptions) {
const child = spawn(
'node',
[
let command: string;
let args: string[];

const hydrogenArgvIndex = process.argv.findIndex((a) => a === 'hydrogen');

if (hydrogenArgvIndex >= 1) {
// Call the `h2 codegen --watch` command in a separate process.
command = process.argv[0]!;
args = [
...process.argv.slice(1, hydrogenArgvIndex + 1),
'codegen',
'--watch',
'--path',
rootDirectory,
];

if (configFilePath) {
args.push('--codegen-config-path', configFilePath);
}
} else {
// Legacy: in case this command wasn't run using our CLI
// (is this even possible?) just do what we used to do
// before CLI bundling:
command = 'node';
args = [
fileURLToPath(import.meta.url),
rootDirectory,
appDirectory ?? resolvePath('app'),
configFilePath ?? '',
],
{stdio: ['inherit', 'ignore', 'pipe']},
);
];
}

const child = spawn(command, args, {stdio: ['inherit', 'ignore', 'pipe']});

child.stderr.on('data', (data) => {
const dataString: string =
Expand Down

0 comments on commit af90c44

Please sign in to comment.