-
Notifications
You must be signed in to change notification settings - Fork 9
/
app.js
63 lines (55 loc) · 1.82 KB
/
app.js
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
'use strict';
const fs = require('fs');
const commandExistsSync = require('command-exists').sync;
const logger = require('./bin/logger');
const { version } = require('./package.json');
logger.info(`Starting the twitter-to-discord application v${version}`);
// Extract all the env variables we will be using
const {
TWITTER_CONSUMER_KEY,
TWITTER_CONSUMER_SECRET,
TWITTER_ACCESS_TOKEN_KEY,
TWITTER_ACCESS_TOKEN_SECRET,
MONGO_URI,
DISCORD_BOT_TOKEN,
DISCORD_CMD_PREFIX,
DISCORD_BOT_OWNER_ID,
TEMP,
} = process.env;
// Exit if the env variable was not set or passed. None can be empty
function envTest(value, name) {
logger.debug(`${name}=${value}`);
if (!value) {
logger.error(`Missing the environment variable '${name}'`);
process.exit(1);
}
}
envTest(TWITTER_CONSUMER_KEY, 'TWITTER_CONSUMER_KEY');
envTest(TWITTER_CONSUMER_SECRET, 'TWITTER_CONSUMER_SECRET');
envTest(TWITTER_ACCESS_TOKEN_KEY, 'TWITTER_ACCESS_TOKEN_KEY');
envTest(TWITTER_ACCESS_TOKEN_SECRET, 'TWITTER_ACCESS_TOKEN_SECRET');
envTest(MONGO_URI, 'MONGO_URI');
envTest(DISCORD_BOT_TOKEN, 'DISCORD_BOT_TOKEN');
envTest(DISCORD_CMD_PREFIX, 'DISCORD_CMD_PREFIX');
envTest(DISCORD_BOT_OWNER_ID, 'DISCORD_BOT_OWNER_ID');
envTest(TEMP, 'TEMP');
// Ensure we can access the temp directory
try {
fs.accessSync(process.env.TEMP, fs.constants.F_OK);
} catch (err) {
logger.error(`Unable to access the temp directory: ${process.env.TEMP}`);
logger.debug(err);
process.exit(1);
}
// Ensure all the commands we need to function exist via PATH
if (!commandExistsSync('ffmpeg')) {
logger.error('\'ffmpeg\' is not available on the command line');
process.exit(1);
}
if (!commandExistsSync('gm')) {
logger.error('\'gm\' is not available on the command line');
process.exit(1);
}
// Passed all the startup tests
// Continue to load application
require('./bin');