UNPKG

gui-tool

Version:

Generating of ExtJS prototypes and skeleton applications with Siesta tests has never been so easy and fast.

54 lines (42 loc) 1.8 kB
/* * Reads the config parameters of the application from the config.yml file. */ // Load the YAML parser module var yaml = require('js-yaml'), fs = require('fs'); // Load the should module for validation require('should'); var configFile = {}; var parameters = {}; var setEnvironment = function(environment) { if (environment !== null && configFile.environments[environment].should.be.an.Object) { // Process default values combined with // the parameters of the selected environment parameters = configFile.environments['default']; parameters.environment = environment; Object.getOwnPropertyNames(configFile.environments[environment]).forEach(function(key) { parameters[key] = configFile.environments[environment][key]; }); } else { console.log('ERROR: Wrong environment "' + environment + '"'); } return parameters; }; /** Parse the config file and returns with the default config parameters */ var loadConfiguration = function(configFileName) { // Load the YAML format config file configFile = yaml.load(fs.readFileSync(configFileName)); configFile.should.be.an.instanceOf(Object); configFile.should.have.property('useEnvironment'); configFile.should.have.property('environments'); configFile.environments.should.be.an.instanceOf(Object); configFile.environments.should.have.property('default'); // configFile.environments[ 'default' ].useEnvironment = configFile.useEnvironment || "default"; setEnvironment(configFile.useEnvironment); return parameters; }; // Set the config parameters to the default environment var parameters = loadConfiguration(__dirname + '/config.yml'); exports.setEnvironment = setEnvironment; exports.parameters = parameters;