-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcli.js
executable file
·27 lines (22 loc) · 918 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
#!/usr/bin/env node
import { program } from 'commander'
import { serveMocks } from './src/serve-mocks.js'
import { readFileSync } from 'fs'
import { fileURLToPath } from 'url'
import path from 'path'
const packageJsonPath = path.join(fileURLToPath(import.meta.url), '../package.json')
const { version } = JSON.parse(readFileSync(packageJsonPath, { encoding: 'utf-8' }))
const hostname = process.env.SERVEMOCKS_HOST || '127.0.0.1'
program
.version(version)
.arguments('<mock-directory>')
.option('-p, --port <port>', 'Change webserver port')
.option('-c, --compact-logging', 'Limits the number of endpoints which are being printed to the console on init')
.action(function (mockDirectory, env) {
const options = {}
if (env.compactLogging) {
options.endpointRegistrationLogging = 'compact'
}
serveMocks(mockDirectory, env.port || 8080, hostname, options)
})
.parse(process.argv)