-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
executable file
·77 lines (73 loc) · 1.9 KB
/
index.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env node
const fs = require('fs');
const os = require('os');
const path = require('path');
const Yargs = require('yargs');
const findUp = require('find-up');
const winston = require('winston');
const { combine, label, printf } = winston.format;
const Kolibri = require('./kolibri');
const CONFIG_DEFAULTS = {
homeDirectory: path.resolve(os.homedir(), '.kolibri-pexer'),
homeTemplate: path.resolve(os.homedir(), '.kolibri'),
contentDirectory: path.resolve(os.homedir(), '.kolibri', 'content'),
python: 'python',
runMode: 'test',
};
const configPath = findUp.sync(['.pexerrc', '.pexerrc.json']);
const config = configPath
? Object.assign({}, CONFIG_DEFAULTS, JSON.parse(fs.readFileSync(configPath)))
: CONFIG_DEFAULTS;
if (!config.runMode) {
config.runMode = 'test';
}
Yargs
.config(config)
.option('verbose', {
type: 'boolean',
description: 'enable verbose output',
default: false,
})
.option('python', {
alias: 'p',
type: 'string',
description: 'python binary to use',
})
.option('port', {
type: 'number',
description: 'the port to run Kolibri on',
default: 8080,
})
.option('clean', {
type: 'boolean',
description: 'do not use content directory or home template',
default: false,
})
.middleware((argv) => {
return {
kolibri: Kolibri.build(argv),
logger: winston.createLogger({
level: argv.verbose ? 'verbose' : 'warn',
exitOnError: false,
transports: [
new winston.transports.Console(),
],
format: combine(
label({label: 'PEXER'}),
printf(({level, message, label}) => {
return `[${label}] ${level.toUpperCase()}: ${message}`;
})
)
})
};
})
.command({
command: 'config',
describe: 'outputs the config',
handler() { console.log(config) },
})
.commandDir('commands')
.demandCommand()
.help()
.argv
;