Skip to content

Commit

Permalink
fixes #397, allow for multiple profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
dbashford committed Jun 23, 2014
1 parent 660011b commit 85ed05f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 31 deletions.
39 changes: 21 additions & 18 deletions lib/util/configurer.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ _applyAndValidateDefaults = function(config, callback) {
};

processConfig = function(opts, callback) {
var config, err, mainConfigPath, profileConfig, profileConfigPath;
var config, err, mainConfigPath;
config = {};
mainConfigPath = _findConfigPath("mimosa-config");
if (mainConfigPath != null) {
Expand All @@ -341,24 +341,27 @@ processConfig = function(opts, callback) {
if (!config.profileLocation) {
config.profileLocation = "profiles";
}
profileConfigPath = _findConfigPath(path.join(config.profileLocation, opts.profile));
if (profileConfigPath != null) {
try {
profileConfig = _requireConfig(profileConfigPath).config;
} catch (_error) {
err = _error;
return logger.fatal("Improperly formatted configuration file [[ " + profileConfigPath + " ]]: " + err);
}
if (logger.isDebug()) {
logger.debug("Profile config:\n" + (JSON.stringify(profileConfig, null, 2)));
}
config = _extend(config, profileConfig);
if (logger.isDebug()) {
logger.debug("mimosa config after profile applied:\n" + (JSON.stringify(config, null, 2)));
opts.profile.split("#").forEach(function(profileName) {
var profileConfig, profileConfigPath;
profileConfigPath = _findConfigPath(path.join(config.profileLocation, profileName));
if (profileConfigPath != null) {
try {
profileConfig = _requireConfig(profileConfigPath).config;
} catch (_error) {
err = _error;
return logger.fatal("Improperly formatted configuration file [[ " + profileConfigPath + " ]]: " + err);
}
if (logger.isDebug()) {
logger.debug("Profile config:\n" + (JSON.stringify(profileConfig, null, 2)));
}
config = _extend(config, profileConfig);
if (logger.isDebug()) {
return logger.debug("mimosa config after profile applied:\n" + (JSON.stringify(config, null, 2)));
}
} else {
return logger.fatal("Profile provided but not found at [[ " + (path.join('profiles', profileName)) + " ]]");
}
} else {
return logger.fatal("Profile provided but not found at [[ " + (path.join('profiles', opts.profile)) + " ]]");
}
});
}
config.isServer = opts != null ? opts.server : void 0;
config.isOptimize = opts != null ? opts.optimize : void 0;
Expand Down
29 changes: 16 additions & 13 deletions src/util/configurer.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -299,22 +299,25 @@ processConfig = (opts, callback) ->
unless config.profileLocation
config.profileLocation = "profiles"

profileConfigPath = _findConfigPath path.join(config.profileLocation, opts.profile)
if profileConfigPath?
try
profileConfig = _requireConfig(profileConfigPath).config
catch err
return logger.fatal "Improperly formatted configuration file [[ #{profileConfigPath} ]]: #{err}"
opts.profile.split("#").forEach (profileName) ->

if logger.isDebug()
logger.debug "Profile config:\n#{JSON.stringify(profileConfig, null, 2)}"
profileConfigPath = _findConfigPath path.join(config.profileLocation, profileName)
if profileConfigPath?
try
profileConfig = _requireConfig(profileConfigPath).config
catch err
return logger.fatal "Improperly formatted configuration file [[ #{profileConfigPath} ]]: #{err}"

config = _extend config, profileConfig
if logger.isDebug()
logger.debug "Profile config:\n#{JSON.stringify(profileConfig, null, 2)}"

config = _extend config, profileConfig

if logger.isDebug()
logger.debug "mimosa config after profile applied:\n#{JSON.stringify(config, null, 2)}"
else
return logger.fatal "Profile provided but not found at [[ #{path.join('profiles', profileName)} ]]"

if logger.isDebug()
logger.debug "mimosa config after profile applied:\n#{JSON.stringify(config, null, 2)}"
else
return logger.fatal "Profile provided but not found at [[ #{path.join('profiles', opts.profile)} ]]"

config.isServer = opts?.server
config.isOptimize = opts?.optimize
Expand Down

0 comments on commit 85ed05f

Please sign in to comment.