UNPKG

@gameroom/cli

Version:

A command line tool for Gameroom

28 lines (25 loc) 985 B
const { writeFileSync } = require('fs'), { homedir } = require('os'), { join } = require('path'), { checkDir } = require('../middlewares'), { config } = require('../refs') const exitHandler = (options, exitCode) => { process.stdin.resume() checkDir() const path = join(homedir(), '.gameroom', `${process.env.NODE_ENV === 'development' ? 'dev_' : ''}config.json`) config.exit_gracefully = false //always reset exit gracefully config.should_exit = false //always reset should_ exit writeFileSync(path, JSON.stringify(config)) // print code if not 0 if (exitCode) console.log(`gameroom ended with exit code ${exitCode}`) process.exit() } //do something when app is closing process.on('exit', exitHandler) //catches ctrl+c event process.on('SIGINT', exitHandler) // catches "kill pid" (for example: nodemon restart) process.on('SIGUSR1', exitHandler) process.on('SIGUSR2', exitHandler) //catches uncaught exceptions process.on('uncaughtException', exitHandler)