In my production applications, I solved this problem as follows:
Files
App /.git/hooks/post.commit
App / MeteorApp / hooks / post-commit-version
Application Structure:
App .git hooks post-commit (file) MeteorApp client server both private version.json hooks post-commit-version (file)
Whenever a developer executes .git/hooks/post-commit code, the nodejs script is nodejs script , which is stored in App/MeteorApp/hooks/post-commit-version .
Script post-commit-version generates version.json in App/MeteorApp/private dir in the format:
{ "timestamp": "29-08-2014 23:16", "branch": "master", "commit": "3332f6dcbde57105a8dc353e5e878651cab89856" }
Everything that is stored in private is available to the server during production.
How to display version.json in application?
App / MeteorApp / both / collections / Version.js
Version = new Meteor.Collection('version');
App / MeteorApp / server / startup.js
Meteor.startup(function(){ if (Version.find().count() > 0){ Version.remove({}); } Version.insert(JSON.parse(Assets.getText("version.json"))); })
After the application is deployed, it will launch startup callbacks and the version will be inserted into the Version collection.
App / MeteorApp / server / publications / version.js
Meteor.publish('version', function () { return Version.find(); });
App / MeteorApp / client / startup.js :
Meteor.startup(function(){ Meteor.subscribe("version"); })
And then somewhere in the template just create an assistant:
Template.template_name.helpers({ version:function(){ return Version.findOne(); } })
In template_name, you display the version using {{version.commit}} {{version.branch}} {{version.timestamp}} .
Side Note 1
Script post-commit-version do not have the js extension because I do not want the meteor to include it in the package or reload the application during development every time I change this file. However, you can use post-commit-version.js if this file is stored in .dir (for example, App/MeteorApp/.hooks ), because directories have . since the first character is not processed by a meteorite.
Side Note 2
Another option might be to download version.json on the server side Meteor.startup , parse json and join a global variable like App.version . Use it Meteor.method with Meteor.method :
Meteor.methods({ getVersion:function(){ return App.version; } })
On the client, you simply call the method:
Meteor.call("getVersion", function(error,version){ if(error) { throw new Error("Cannot get version"); return; } Session.set("version",version) })
Some template helpers may use it:
Template.template_name.helpers({ version:function(){ return Session.get("version"); } })