Skip to content

Commit

Permalink
feat: add mocks logging messages
Browse files Browse the repository at this point in the history
  • Loading branch information
pedbernardo committed Jun 26, 2022
1 parent f6cffc6 commit 3842e4c
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/scripts/mock.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import fs from 'node:fs'
import jsonServer from 'json-server'
import { logger, printMocksHost } from '../logger.mjs'

export function mock ({ config }) {
const dbExists = fs.existsSync(config.mocks.file)

if (!dbExists) {
console.log(`Can't find the mock JSON config at ${config.mocks.file}`)
if (!dbExists && !config.explicitMocks) return
if (!dbExists && config.explicitMocks) {
logger(`Can't start Mocks Server. The config file at [output] wasn't found`, {
output: config.mocks.file,
level: 'warn',
script: 'mocks'
})
return
}

Expand All @@ -18,6 +24,6 @@ export function mock ({ config }) {
server.use(config.mocks.route, router)

server.listen(config.mocks.port, () => {
console.log('JSON Server is running')
printMocksHost({ mocks: config.mocks })
})
}

0 comments on commit 3842e4c

Please sign in to comment.