refactor: move function parseConfig

This commit is contained in:
Unitech 2015-12-16 14:35:50 +01:00
parent d5485a0d53
commit d52a5d1ef3
2 changed files with 237 additions and 321 deletions

File diff suppressed because it is too large Load Diff

View File

@ -6,6 +6,9 @@ var cst = require('../constants.js');
var async = require('async');
var util = require('util');
var vm = require('vm');
var semver = require('semver');
var Utility = module.exports = {
getDate : function() {
return Date.now();
@ -128,5 +131,25 @@ var Utility = module.exports = {
})(types.splice(0, 1));
async.waterfall(flows, callback);
},
/**
* Parses a config file like ecosystem.json. Supported formats: JS, JSON, JSON5.
* @param {string} confString contents of the config file
* @param {string} filename path to the config file
* @return {Object} config object
*/
parseConfig : function(confString, filename) {
var code = '(' + confString + ')';
var sandbox = {};
if (semver.satisfies(process.version, '>= 0.12.0')) {
return vm.runInThisContext(code, sandbox, {
filename: path.resolve(filename),
displayErrors: false,
timeout: 1000
});
} else {
// Use the Node 0.10 API
return vm.runInNewContext(code, sandbox, filename);
}
}
};