Skip to content

Commit

Permalink
refactor: alternative approach
Browse files Browse the repository at this point in the history
  • Loading branch information
erikian committed Nov 30, 2023
1 parent 9d38a23 commit 3a3cf97
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 21 deletions.
17 changes: 15 additions & 2 deletions packages/api/core/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import init, { InitOptions } from './init';
import make, { MakeOptions } from './make';
import _package, { PackageOptions } from './package';
import publish, { PublishOptions } from './publish';
import start, { StartOptions } from './start';
import start, { restartApp, StartOptions } from './start';

export class ForgeAPI {
/**
Expand Down Expand Up @@ -61,4 +61,17 @@ export class ForgeAPI {
const api = new ForgeAPI();
const utils = new ForgeUtils();

export { ForgeMakeResult, ElectronProcess, ForgeUtils, ImportOptions, InitOptions, MakeOptions, PackageOptions, PublishOptions, StartOptions, api, utils };
export {
ElectronProcess,
ForgeMakeResult,
ForgeUtils,
ImportOptions,
InitOptions,
MakeOptions,
PackageOptions,
PublishOptions,
StartOptions,
api,
restartApp,
utils,
};
31 changes: 19 additions & 12 deletions packages/api/core/src/api/start.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { spawn, SpawnOptions } from 'child_process';
import { EventEmitter } from 'events';

import { getElectronVersion, listrCompatibleRebuildHook } from '@electron-forge/core-utils';
import { ElectronProcess, ForgeArch, ForgeListrTaskFn, ForgePlatform, ResolvedForgeConfig, StartOptions } from '@electron-forge/shared-types';
Expand All @@ -24,6 +25,8 @@ type StartContext = {
spawned: ElectronProcess;
};

const restartAppEventEmitter = new EventEmitter();

export default autoTrace(
{ name: 'start()', category: '@electron-forge/core' },
async (
Expand Down Expand Up @@ -213,20 +216,20 @@ export default autoTrace(
};

if (interactive) {
process.on('FORGE_RESTART_APP', async () => {
restartAppEventEmitter.on('restart', async () => {
if (lastSpawned) {
console.info(chalk.cyan('\nRestarting App\n'));
lastSpawned.restarted = true;
lastSpawned.kill('SIGTERM');
lastSpawned.emit('restarted', await forgeSpawnWrapper());
}
});
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.on('data', async (data) => {
if (data.toString().trim() === 'rs') {
restartApp();
}
});

process.stdin.resume();
}
Expand All @@ -238,3 +241,7 @@ export default autoTrace(
return spawned;
}
);

export function restartApp() {
restartAppEventEmitter.emit('restart');
}
7 changes: 0 additions & 7 deletions typings/nodejs/index.d.ts

This file was deleted.

0 comments on commit 3a3cf97

Please sign in to comment.