Improves config loading and tests

This commit is contained in:
Florent Vilmart
2016-04-04 20:02:34 -04:00
parent 27dd2ebf5d
commit 8c92b80b8f
8 changed files with 155 additions and 39 deletions

View File

@@ -3,6 +3,7 @@ import express from 'express';
import { ParseServer } from '../index';
import definitions from './cli-definitions';
import program from './utils/commander';
import { mergeWithOptions } from './utils/commander';
import colors from 'colors';
program.loadDefinitions(definitions);
@@ -34,28 +35,7 @@ program.on('--help', function(){
program.parse(process.argv, process.env);
let options = {};
if (program.args.length > 0 ) {
let jsonPath = program.args[0];
jsonPath = path.resolve(jsonPath);
let jsonConfig = require(jsonPath);
if (jsonConfig.apps) {
if (jsonConfig.apps.length > 1) {
throw 'Multiple apps are not supported';
}
options = jsonConfig.apps[0];
} else {
options = jsonConfig;
}
console.log(`Configuation loaded from ${jsonPath}`)
}
options = Object.keys(definitions).reduce(function (options, key) {
if (typeof program[key] !== 'undefined') {
options[key] = program[key];
}
return options;
}, options);
let options = program.getOptions();
if (!options.serverURL) {
options.serverURL = `http://localhost:${options.port}${options.mountPath}`;