Skip to content
This repository was archived by the owner on Mar 29, 2022. It is now read-only.

[Fixes #77] CLI data parameter #78

Merged
merged 5 commits into from
Feb 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ start a firebase server on port 5555:

node_modules/.bin/firebase-server -p 5555

To bootstrap the server with some data you can use the `-d,--data` or the `-f,--file` option.
_Note: The file option will override the data option._

node_modules/.bin/firebase-server -d '{"foo": "bar"}'

node_modules/.bin/firebase-server -f ./path/to/file.json

For more information, run:

node_modules/.bin/firebase-server -h
Expand Down
28 changes: 26 additions & 2 deletions bin/firebase-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

'use strict';

var fs = require('fs');
var path = require('path');
var cli = require('cli');
var debug = require('debug');

cli.parse({
verbose: ['v', 'Enable verbose (debug) output'],
port: ['p', 'Listen on this port', 'number', 5000],
name: ['n', 'Hostname of the firebase server', 'string', 'localhost.firebaseio.test']
name: ['n', 'Hostname of the firebase server', 'string', 'localhost.firebaseio.test'],
data: ['d', 'JSON data to bootstrap the server with', 'string', '{}'],
file: ['f', 'JSON file to bootstrap the server with', 'file']
});

cli.main(function (args, options) {
Expand All @@ -18,7 +22,27 @@ cli.main(function (args, options) {

var FirebaseServer = require('../index.js');

new FirebaseServer(options.port, options.name, {}); // eslint-disable-line no-new
var rawData;
if (options.file) {
try {
rawData = fs.readFileSync(path.resolve(process.cwd(), options.file)); // eslint-disable-line no-sync
} catch (e) {
this.output(e);
this.fatal('Provided file could not be read.');
}
} else {
rawData = options.data;
}

var data = {};
try {
data = JSON.parse(rawData);
} catch (e) {
this.output(e);
this.fatal('Provided data was not valid JSON.');
}

new FirebaseServer(options.port, options.name, data); // eslint-disable-line no-new

this.ok('Listening on port ' + options.port);
});