Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Config File Support for Rhino Wrapper, solves #704 #1130

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 29 additions & 3 deletions src/platforms/rhino.js
Expand Up @@ -5,13 +5,25 @@
"use strict";

var filenames = [];
var flags = {};
var optstr; // arg1=val1,arg2=val2,...
var predef; // global1=true,global2,global3,...
var opts = {};
var retval = 0;

args.forEach(function (arg) {
if (arg.indexOf("=") > -1) {
if (arg.indexOf("--") === 0) {
// Configuration Flags might be boolean or will be split into name and value
if (arg.indexOf("=") > -1) {
var o = arg.split("=");
flags[o[0].slice(2)] = o[1];
} else {
flags[arg.slice(2)] = true;
}

return;
} else if (arg.indexOf("=") > -1) {
// usual rhino configuration, like "boss=true,browser=true"
if (!optstr) {
// First time it's the options.
optstr = arg;
Expand All @@ -35,6 +47,19 @@
quit(1);
}

// If a config flag has been provided, try and load that
if ("config" in flags) {
var cfgFileContent;
try {
cfgFileContent = readFile(flags.config);
} catch (e) {
print("Could not read config file " + flags.config);
quit(1);
}

opts = JSON.parse(cfgFileContent);
}

if (optstr) {
optstr.split(",").forEach(function (arg) {
var o = arg.split("=");
Expand All @@ -55,9 +80,10 @@
});
}

if (predef) {
opts.predef = {};
opts.predef = opts.globals || {};
delete(opts.globals);

if (predef) {
predef.split(",").forEach(function (arg) {
var global = arg.split("=");
opts.predef[global[0]] = global[1] === "true" ? true : false;
Expand Down