Skip to content

Commit

Permalink
App: exit safely if dependencies or config.js aren't set up on launch
Browse files Browse the repository at this point in the history
  • Loading branch information
Morfent committed Jun 13, 2017
1 parent 846d250 commit 1a2828e
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ const path = require('path');
try {
require.resolve('sockjs');
} catch (e) {
throw new Error("Dependencies unmet; run npm install");
console.error('Dependencies are unmet; run npm install before launching Pokemon Showdown again.');
process.exit(1);
}

/*********************************************************
Expand All @@ -62,14 +63,16 @@ try {
if (err.code !== 'MODULE_NOT_FOUND') throw err; // should never happen

// Copy it over synchronously from config-example.js since it's needed before we can start the server
console.log("config.js doesn't exist - creating one with default settings...");
console.error("config.js doesn't exist. Creating one with default settings...");
fs.writeFileSync(path.resolve(__dirname, 'config/config.js'),
fs.readFileSync(path.resolve(__dirname, 'config/config-example.js'))
);
} finally {
global.Config = require('./config/config');
console.error('Pokemon Showdown will now exit. Modify whichever config settings you wish before relaunching the server.');
process.exit(1);
}

global.Config = require('./config/config');

if (Config.watchconfig) {
let configPath = require.resolve('./config/config');
fs.watchFile(configPath, (curr, prev) => {
Expand Down

0 comments on commit 1a2828e

Please sign in to comment.