forked from XpRienzo/DragonHeaven
-
Notifications
You must be signed in to change notification settings - Fork 1
/
pokemon-showdown
executable file
·79 lines (67 loc) · 2.54 KB
/
pokemon-showdown
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/sh
true /*
# Shell script will interpret above as a command and execute everything after
# it, while JavaScript will interpret this as beginning of a comment and skip
# shell script contents.
#
# As shell script parses lines only when they are needed, nothing after exit 1
# can possibly cause a syntax error.
if nodepath="$(command -v node || command -v nodejs)"; then
exec "$nodepath" "$0" "$@"
fi
echo "We require Node.js version 8 or later; Node.js not found"
exit 1
*/;
const child_process = require('child_process');
const fs = require('fs');
const path = require('path');
// Make sure we're Node 8+
try {
eval('{ let a = async () => {}; }');
} catch (e) {
console.log("We require Node.js version 8 or later; you're using " + process.version);
process.exit(1);
}
// Make sure our dependencies are available, and install them if they
// aren't
try {
require.resolve('sockjs');
} catch (e) {
console.log('Installing dependencies...');
child_process.execSync('npm install --production', {stdio: 'inherit'});
}
// Make sure config.js exists. If not, copy it over synchronously from
// config-example.js, since it's needed before we can start the server
try {
require.resolve('./config/config');
} catch (err) {
if (err.code !== 'MODULE_NOT_FOUND') throw err; // should never happen
console.log('config.js does not exist. Creating one with default settings...');
fs.writeFileSync(
path.resolve(__dirname, 'config/config.js'),
fs.readFileSync(path.resolve(__dirname, 'config/config-example.js'))
);
}
if (!process.argv[2] || /^[0-9]+$/.test(process.argv[2])) {
// Start the server. We manually load app.js so it can be configured to run as
// the main module, rather than this file being considered the main module.
// This ensures any dependencies that were just installed can be found when
// running on Windows and avoids any other potential side effects of the main
// module not being app.js like it is assumed to be.
//
// The port the server should host on can be passed using the second argument
// when launching with this file the same way app.js normally allows, e.g. to
// host on port 9000:
// $ ./pokemon-showdown 9000
require('module')._load('./app', module, true);
} else switch (process.argv[2]) {
case 'generate-team':
const Dex = require('./sim/dex');
global.toId = Dex.getId;
const seed = process.argv[4] ? process.argv[4].split(',').map(Number) : undefined;
console.log(Dex.packTeam(Dex.generateTeam(process.argv[3], seed)));
break;
default:
console.error('Unrecognized command: ' + process.argv[2]);
process.exit(1);
}