-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.js
48 lines (39 loc) · 1019 Bytes
/
utils.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
import assertEnv from "assert-env";
import chalk from "chalk";
import { inspect } from "util";
export function checkEnvironmentVariables() {
try {
assertEnv([
"CAN_TRACKER_ANNOUNCE_URL",
"CAN_TRACKER_PATH",
"CAN_TRACKER_PORT",
"CAN_TRACKER_WEB_SEED_URL"
]);
} catch (err) {
console.error(err.message);
process.exit(1);
}
}
const { CAN_TRACKER_DEBUG } = process.env;
const errorColor = chalk.bold.red;
const infoColor = chalk.bold;
const debugColor = chalk.cyan;
const warningColor = chalk.yellow;
function log(color) {
const sanitizedArgs = [...arguments]
.slice(1)
.map(x => (typeof x === "string" ? x : inspect(x)));
console.log(chalk.magenta`can-tracker:`, color(...sanitizedArgs));
}
export function DEBUG() {
CAN_TRACKER_DEBUG && log(debugColor, ...arguments);
}
export function INFO() {
log(infoColor, ...arguments);
}
export function ERROR() {
log(errorColor, ...arguments);
}
export function WARN() {
log(warningColor, ...arguments);
}