-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
28 lines (22 loc) · 887 Bytes
/
cli.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
#!/usr/bin/env node
const path = require('path');
const chalk = require('chalk');
const commander = require('commander');
const { start, add, restore } = require('./app');
const defaultConfig = 'mock-server.config.js';
commander
.option('-c, --config [path]', 'Path to mock-server config', defaultConfig)
.option('-p, --port <n>', 'Port to run the mock server', 3001)
.parse(process.argv);
const filePath = commander.config || defaultConfig;
let config;
try {
config = require(path.join(process.cwd(), filePath));
} catch(err) {
console.log(chalk.red('[ERROR json-mock-server] - Could not resolve path:'), chalk.yellow(`"${path.join(process.cwd(), filePath)}"`));
if (commander.config === defaultConfig) {
console.log(chalk.red('Default config file could not be found. To specify a filepath use `--config`'));
}
process.exit();
}
start(config, commander.port);