Add message when creating default db

This commit is contained in:
typicode
2016-10-07 00:29:11 +02:00
parent b11d18d037
commit e9ab8fe99f
2 changed files with 17 additions and 0 deletions

9
src/cli/example.json Normal file
View File

@ -0,0 +1,9 @@
{
"posts": [
{ "id": 1, "title": "json-server", "author": "typicode" }
],
"comments": [
{ "id": 1, "body": "some comment", "postId": 1 }
],
"profile": { "name": "typicode" }
}

View File

@ -7,6 +7,7 @@ const enableDestroy = require('server-destroy')
const pause = require('connect-pause') const pause = require('connect-pause')
const is = require('./utils/is') const is = require('./utils/is')
const load = require('./utils/load') const load = require('./utils/load')
const example = require('./example.json')
const jsonServer = require('../server') const jsonServer = require('../server')
function prettyPrint (argv, object, rules) { function prettyPrint (argv, object, rules) {
@ -97,6 +98,13 @@ module.exports = function (argv) {
function start (cb) { function start (cb) {
console.log() console.log()
// Be nice and create a default db.json if it doesn't exist
if (is.JSON(source) && !fs.existsSync(source)) {
console.log(chalk.gray(` ${source} doesn't seem to exist, creating one`))
fs.writeFileSync(source, JSON.stringify(example, null, 2))
}
console.log(chalk.gray(' Loading', source)) console.log(chalk.gray(' Loading', source))
// Load JSON, JS or HTTP database // Load JSON, JS or HTTP database