-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
executable file
·79 lines (65 loc) · 1.65 KB
/
index.js
File metadata and controls
executable file
·79 lines (65 loc) · 1.65 KB
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
#!/usr/bin/env node
const minimist = require('minimist');
const path = require('path');
require('colors');
const {
usageMessage,
Runner,
getEnvFlag,
exitProcess,
getProcessCWD,
print,
printException,
printNewLines,
printInfo,
DEFAULT_CONFIGURATION,
ENV_FLAGS
} = require('./dist');
// printing a couple empty lines to give BigBrother some space
printNewLines(2);
const readArguments = () => {
const argv = minimist(process.argv.slice(2));
return {
pattern: argv._[0],
help: argv.help || argv.h,
configPath: argv.config || argv.c
};
};
const handleDefaultConfiguration = () => printInfo('Loading default configuration.');
const handleUsageHelp = () => {
print(usageMessage);
exitProcess(1);
};
const loadConfigFile = (cwd, configPath) => {
let config = DEFAULT_CONFIGURATION;
try {
if (configPath) {
const requirePath = path.join(cwd, configPath);
config = require(requirePath);
} else {
handleDefaultConfiguration();
}
} catch(e) {
printException(e);
handleDefaultConfiguration();
}
return config;
};
const loadEnvConfig = () => ({
headless: getEnvFlag(ENV_FLAGS.HEADLESS),
cacheEnabled: getEnvFlag(ENV_FLAGS.CACHE_ENABLED)
});
const cwd = getProcessCWD();
const getModuleConfig = () => ({
cwd
});
const args = readArguments();
const { help, configPath } = args;
if (help) handleUsageHelp();
const runnerConfig = Object.assign(
DEFAULT_CONFIGURATION,
getModuleConfig(),
loadEnvConfig(),
args,
loadConfigFile(cwd, configPath));
Runner.start(runnerConfig);