How can mobile-config.js
be dynamically changed per environment without manually editing it pre-build each time?
For example, we want to differentiate the app name on our app icon between Dev and Prod versions - so:
App.info({
name: 'AppNameDev',
version: '0.2.0'
});
and then for production:
App.info({
name: 'AppName',
version: '0.2.0'
});
We’d also like to be able to have ONE source of truth for the version and display that in app. Meaning we’d either need to be able to dynamically set the version in mobile-config
as well (preferred) OR read in mobile-config
to the app / everywhere else and use that as the single source of truth.
Looking more broadly, we use raix for push notifications and that has a config.push.json
file and we have the same issue there.
We made a config package local to our app where we put all our configuration and used Meteor.settings / environment variable to set the environment and dynamically set configuration accordingly (api keys, etc. that are different between dev and prod) and that’s been working great. But that’s run time only? We need a way to do the same for build time.
Config ={};
Config.ENV =false;
//http://stackoverflow.com/questions/14184643/detecting-environment-with-meteor-js
Meteor.methods({
getEnvironment: function() {
var env ='dev'; //DEFAULT
if(Meteor.isServer) {
if(process.env !==undefined && process.env.ENV !==undefined) {
env =process.env.ENV;
}
else if(Meteor.settings !==undefined && Meteor.settings.env !==undefined) {
env =Meteor.settings.env;
}
Config.ENV =env;
console.log('Config.ENV: '+Config.ENV);
}
return env;
}
});
if(Meteor.isClient) {
Meteor.call("getEnvironment", function(err, result) {
Config.ENV =result;
console.log('Config.ENV: '+Config.ENV);
});
}
Config.appInfo =function(params) {
var ret ={
name: 'AppNameDev'
};
if(Config.ENV ==='prod') {
ret.name ='AppName';
}
return ret;
};
So basically, how to automate builds for different environments? I.e. for use with Continuous Integration and just in general to reduce manual (error prone) steps when building for different environments.
In past (non meteor) apps I’ve used Grunt with Grunt.template to dynamically handle this for build time.