Skip to content

Commit 46865e3

Browse files
committed
Added shutdownOnExit option; moved onExit to core
1 parent 0d2210c commit 46865e3

File tree

4 files changed

+28
-16
lines changed

4 files changed

+28
-16
lines changed

packages/launchpad/index.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { LaunchpadCore } from './lib/launchpad-core.js';
44
import { launch as launchContent } from '@bluecadet/launchpad-content';
55
import { launch as launchMonitor, LaunchpadMonitor } from '@bluecadet/launchpad-monitor';
66
import { launch as launchScaffold } from '@bluecadet/launchpad-scaffold';
7-
import { launchFromCli, onExit } from '@bluecadet/launchpad-utils';
7+
import { launchFromCli } from '@bluecadet/launchpad-utils';
88

99
export default LaunchpadCore;
1010

@@ -45,10 +45,6 @@ launchFromCli(import.meta, {
4545
}).then(async config => {
4646
const launchpad = new LaunchpadCore(config);
4747

48-
onExit(async () => {
49-
await launchpad.shutdown();
50-
});
51-
5248
switch (config.startupCommand) {
5349
case StartupCommands.SCAFFOLD: {
5450
await launchScaffold(config);

packages/launchpad/lib/launchpad-core.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import autoBind from 'auto-bind';
66

77
import LaunchpadOptions from './launchpad-options.js';
8-
import { LogManager, Logger } from '@bluecadet/launchpad-utils';
8+
import { LogManager, Logger, onExit } from '@bluecadet/launchpad-utils';
99
import LaunchpadContent from '@bluecadet/launchpad-content';
1010
import LaunchpadMonitor from '@bluecadet/launchpad-monitor';
1111
import CommandCenter, { Command } from './command-center.js';
@@ -55,6 +55,10 @@ export class LaunchpadCore {
5555
this._commands.add(new Command({name: 'update-content', callback: this._runUpdateContent}));
5656

5757
this._commands.addCommandHooks(this._config.hooks);
58+
59+
if (this._config.shutdownOnExit) {
60+
onExit(this.shutdown);
61+
}
5862
}
5963

6064
/**

packages/launchpad/lib/launchpad-options.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,17 @@ export class LaunchpadOptions {
1818
commands = new CommandOptions(),
1919
hooks = new CommandHooks(),
2020
logging = new LogOptions(),
21+
shutdownOnExit = true,
2122
...rest
2223
} = {}) {
2324

25+
/**
26+
* Will listen for exit events
27+
* @type {boolean}
28+
* @default true
29+
*/
30+
this.shutdownOnExit = true;
31+
2432
/**
2533
* @type {ContentOptions}
2634
*/

packages/launchpad/test/test.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import LaunchpadCore from '@bluecadet/launchpad';
2-
import { ConfigManager, launchFromCli } from '@bluecadet/launchpad-utils';
2+
import { ConfigManager, launchFromCli, onExit } from '@bluecadet/launchpad-utils';
33

44
const getConfig = async (paths = ['user-config.js', 'config.js']) => {
55
return ConfigManager.importJsConfig(paths, import.meta);
@@ -17,17 +17,21 @@ launchFromCli(import.meta, {
1717

1818
await launchpad.startup();
1919

20-
const appNames = launchpad._monitor.getAllAppNames();
21-
await Promise.all([...appNames, 'fake-app'].map(async (appName) => {
22-
const isRunning = await launchpad._monitor.isRunning(appName);
23-
console.debug(`App '${appName}' is running: ${isRunning}`);
24-
}));
20+
// const appNames = launchpad._monitor.getAllAppNames();
21+
// await Promise.all([...appNames, 'fake-app'].map(async (appName) => {
22+
// const isRunning = await launchpad._monitor.isRunning(appName);
23+
// console.debug(`App '${appName}' is running: ${isRunning}`);
24+
// }));
2525

26-
await wait(10);
27-
await launchpad.updateContent();
26+
// onExit(async () => {
27+
// await launchpad.shutdown();
28+
// });
2829

29-
await wait(10);
30-
await launchpad.shutdown();
30+
// await wait(10);
31+
// await launchpad.updateContent();
32+
33+
// await wait(10);
34+
// await launchpad.shutdown();
3135

3236
}).catch(err => {
3337
if (err) {

0 commit comments

Comments
 (0)