mirror of
https://github.com/Unitech/pm2.git
synced 2025-12-08 20:35:53 +00:00
refactor: move function parseConfig
This commit is contained in:
parent
d5485a0d53
commit
d52a5d1ef3
535
lib/CLI.js
535
lib/CLI.js
File diff suppressed because it is too large
Load Diff
@ -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);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user