Skip to content

Commit

Permalink
refactor(core): allow restart logic to be triggered using an event
Browse files Browse the repository at this point in the history
  • Loading branch information
erikian committed Nov 30, 2023
1 parent a7efb59 commit 9d38a23
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
23 changes: 15 additions & 8 deletions packages/api/core/src/api/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,14 +213,21 @@ export default autoTrace(
};

if (interactive) {
process.stdin.on('data', async (data) => {
if (data.toString().trim() === 'rs' && lastSpawned) {
console.info(chalk.cyan('\nRestarting App\n'));
lastSpawned.restarted = true;
lastSpawned.kill('SIGTERM');
lastSpawned.emit('restarted', await forgeSpawnWrapper());
}
});
process.on('FORGE_RESTART_APP', async () => {
if (lastSpawned) {
console.info(chalk.cyan('\nRestarting App\n'));
lastSpawned.restarted = true;
lastSpawned.kill('SIGTERM');
lastSpawned.emit('restarted', await forgeSpawnWrapper());
}
});

process.stdin.on('data', async (data) => {
if (data.toString().trim() === 'rs') {
process.emit('FORGE_RESTART_APP');
}
});

process.stdin.resume();
}

Expand Down
7 changes: 7 additions & 0 deletions typings/nodejs/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
declare namespace NodeJS {
interface Process extends EventEmitter {
emit(event: 'FORGE_RESTART_APP'): boolean;

on(event: 'FORGE_RESTART_APP', listener: () => void): NodeJS.Process;
}
}

0 comments on commit 9d38a23

Please sign in to comment.