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

feat(config): allow custom properties in config file #455

Closed
wants to merge 3 commits into from
Closed
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
16 changes: 11 additions & 5 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ var normalizeConfig = function(config) {


var readConfigFile = function(filepath) {
var configEnv = {
var initSandbox = {
// constants
LOG_DISABLE: constant.LOG_DISABLE,
LOG_ERROR: constant.LOG_ERROR,
Expand All @@ -137,7 +137,7 @@ var readConfigFile = function(filepath) {
__filename: filepath,
__dirname: path.dirname(filepath)
};

var configEnv = vm.createContext(initSandbox);

// TODO(vojta): remove
var CONST_ERR = '%s is not supported anymore.\n\tPlease use `frameworks = ["%s"];` instead.';
Expand Down Expand Up @@ -169,7 +169,7 @@ var readConfigFile = function(filepath) {
configSrc = coffee.compile(configSrc.toString(), {bare: true});
}

vm.runInNewContext(configSrc, configEnv);
vm.runInContext(configSrc, configEnv);
} catch(e) {
if (e.name === 'SyntaxError') {
log.error('Syntax error in config file!\n' + e.message);
Expand All @@ -181,6 +181,11 @@ var readConfigFile = function(filepath) {

process.exit(1);
}

// Clean up the env before we return it.
for (var i in initSandbox) {
delete configEnv[i];
}

return configEnv;
};
Expand Down Expand Up @@ -228,11 +233,12 @@ var parseConfig = function(configFilePath, cliOptions) {
};

// merge the config from config file and cliOptions (precendense)
Object.getOwnPropertyNames(configFromFile).forEach(function(key) {
config[key] = configFromFile[key];
});
Object.getOwnPropertyNames(config).forEach(function(key) {
if (cliOptions.hasOwnProperty(key)) {
config[key] = cliOptions[key];
} else if (configFromFile.hasOwnProperty(key)) {
config[key] = configFromFile[key];
}
});

Expand Down