From 7b2388bb568154e597f9d1b15e3da5039ee69294 Mon Sep 17 00:00:00 2001 From: Jordan Date: Thu, 16 Feb 2012 00:22:53 -0500 Subject: [PATCH] Allow the location/name of settings.json to be passed through an optional --settings arg --- bin/installDeps.sh | 15 +++++++++++---- bin/run.sh | 4 ++-- node/utils/Settings.js | 8 ++++++-- package.json | 3 ++- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/bin/installDeps.sh b/bin/installDeps.sh index 6767b693e..6693a994f 100755 --- a/bin/installDeps.sh +++ b/bin/installDeps.sh @@ -40,10 +40,17 @@ if [ ! $(echo $NODE_VERSION | cut -d "." -f 1-2) = "v0.6" ]; then exit 1 fi -#Does a settings.json exist? if no copy the template -if [ ! -f "settings.json" ]; then - echo "Copy the settings template to settings.json..." - cp -v settings.json.template settings.json || exit 1 +#Get the name of the settings file +settings="settings.json" +a=''; +for arg in $*; do + if [ "$a" = "--settings" ]; then settings=$arg; fi + a=$arg +done +#Does a $settings exist? if no copy the template +if [ ! -f $settings ]; then + echo "Copy the settings template to $settings..." + cp -v settings.json.template $settings || exit 1 fi echo "Ensure that all dependencies are up to date..." diff --git a/bin/run.sh b/bin/run.sh index a5245ff77..c409920e7 100755 --- a/bin/run.sh +++ b/bin/run.sh @@ -21,9 +21,9 @@ if [ "$(id -u)" -eq 0 ]; then fi #prepare the enviroment -bin/installDeps.sh || exit 1 +bin/installDeps.sh $* || exit 1 #Move to the node folder and start echo "start..." cd "node" -node server.js +node server.js $* diff --git a/node/utils/Settings.js b/node/utils/Settings.js index e95702112..18832921e 100644 --- a/node/utils/Settings.js +++ b/node/utils/Settings.js @@ -22,6 +22,7 @@ var fs = require("fs"); var os = require("os"); var path = require('path'); +var argv = require('optimist').argv; /** * The IP ep-lite should listen to @@ -88,9 +89,12 @@ exports.abiwordAvailable = function() } } +// Discover where the settings file lives +var settingsFilename = argv.settings || "settings.json"; +var settingsPath = settingsFilename.charAt(0) == '/' ? '' : path.normalize(__dirname + "/../../"); + //read the settings sync -var settingsPath = path.normalize(__dirname + "/../../"); -var settingsStr = fs.readFileSync(settingsPath + "settings.json").toString(); +var settingsStr = fs.readFileSync(settingsPath + settingsFilename).toString(); //remove all comments settingsStr = settingsStr.replace(/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/gm,"").replace(/#.*/g,"").replace(/\/\/.*/g,""); diff --git a/package.json b/package.json index c05a909a2..4f761a4fe 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,8 @@ "formidable" : "1.0.7", "log4js" : "0.4.1", "jsdom-nocontextifiy" : "0.2.10", - "async-stacktrace" : "0.0.2" + "async-stacktrace" : "0.0.2", + "optimist" : "0.3.1" }, "devDependencies": { "jshint" : "*"