Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
};
18 changes: 16 additions & 2 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,14 +216,21 @@ export default autoTrace(
};

if (interactive) {
process.stdin.on('data', async (data) => {
if (data.toString().trim() === 'rs' && lastSpawned) {
restartAppEventEmitter.on('restart', 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') {
restartApp();
}
});

process.stdin.resume();
}

Expand All @@ -231,3 +241,7 @@ export default autoTrace(
return spawned;
}
);

export function restartApp() {
restartAppEventEmitter.emit('restart');
}