-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
41 lines (31 loc) · 909 Bytes
/
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
#!/usr/bin/env node
const cosmiconfig = require('cosmiconfig')
const chalk = require('chalk')
const server = require('./lib/server')
const _ = require('lodash')
const explorer = cosmiconfig('envoy')
const result = explorer.searchSync()
if (!result) {
console.error(chalk.red('Config not found'))
process.exit(1)
}
const DEFAULT_OPTIONS = {
port: 3001,
saveResponse: false,
fileType: 'es6'
}
const options = {
...DEFAULT_OPTIONS,
...result.config
}
const checkOptions = _.difference(['target', 'routesPath'], Object.keys(result.config))
if (checkOptions.length > 0) {
console.error(chalk.red(`Missing config key: ${checkOptions.join(', ')}`))
process.exit(1)
}
if (options.saveResponse && !options.hasOwnProperty('responsePath')) {
console.error(chalk.red('Missing config key: responsePath'))
process.exit(1)
}
const routes = require(options.routesPath)
server(routes, options)