Skip to content

Commit

Permalink
feat: wait for input before exit
Browse files Browse the repository at this point in the history
  • Loading branch information
tutinoko2048 committed Aug 15, 2024
1 parent 40a807b commit 8a93150
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/updater/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { CacheManager } from './CacheManager';
import { Installer } from './Installer';
import type { VersionList, ServerBuildInfo, VersionInfo } from './types';
import { askSwitchVersion, askLicense, askVersion } from './cli';
import { exit } from '../utils/util';

enum SwitchVersionReason {
Update = 'updated',
Expand Down Expand Up @@ -59,7 +60,7 @@ class ServerUpdater {
const result = await askLicense();
if (!result) {
this.logger.error('You must agree to the Minecraft EULA to use the server');
process.exit(1);
exit(1);
}
this.cacheManager.setLicense(true);
}
Expand All @@ -73,8 +74,9 @@ class ServerUpdater {
const updater = new ServerUpdater();
try {
await updater.run();
exit();
} catch(err: any) {
updater.logger.error(`Failed to update server: ${err}`);
console.error(err?.stack)
process.exit(1);
exit(1);
}
6 changes: 6 additions & 0 deletions src/utils/util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export function exit(code: number = 0) {
console.log('\x1b[3m\nPress any key to exit...\x1b[0m');
process.stdin.setRawMode(true);
process.stdin.resume();
process.stdin.on('data', process.exit.bind(process, code));
}

0 comments on commit 8a93150

Please sign in to comment.