mirror of
https://github.com/typicode/json-server.git
synced 2025-07-27 12:12:41 +08:00
Add message when creating default db
This commit is contained in:
9
src/cli/example.json
Normal file
9
src/cli/example.json
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"posts": [
|
||||||
|
{ "id": 1, "title": "json-server", "author": "typicode" }
|
||||||
|
],
|
||||||
|
"comments": [
|
||||||
|
{ "id": 1, "body": "some comment", "postId": 1 }
|
||||||
|
],
|
||||||
|
"profile": { "name": "typicode" }
|
||||||
|
}
|
@ -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
|
||||||
|
Reference in New Issue
Block a user