How can I put the version number of the Meteor app in the user interface?

I have a meteor app that has different branches for different clients. This is because customers want special things. Of course, right?

I would like to place a git branch somewhere and a tag / hash for the deployed version of the application for this client in the user interface.

The question is how? Is there a way in Meteor to get this information and just use it?

Thanks!

+8
git meteor
source share
4 answers

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"); } }) 
+10
source share

I just wrote a package for this and published it on Atmosphere . The package comes with a Helper Template to show your git hash code, tag or branch, as shown below:

 <div> <p>short hash: {{gitRev 'short'}}</p> <p>long hash: {{gitRev 'long'}}</p> <p>tag: {{gitRev 'tag'}}</p> <p>branch: {{gitRev 'branch'}}</p> </div> 

See atmospherejs.com/johdirr/meteor-git-rev for details.

+5
source share

For the most part, I liked Cuba's answer, and I actually tried using its node script, but ran into problems with the promise library. Anyway, I wrote my own post-fix bash script, and I think it is cleaner and simpler.

 ver=$(git describe --abbrev=0) complete=$(git describe) branch=$(git rev-parse --abbrev-ref HEAD) commit=$(git rev-parse HEAD) timestamp=$(git log -1 --date=short --pretty=format:%cd) cat > private/version.json << EOF { "basic": "$ver", "complete": "$complete", "branch": "$branch", "commit": "$commit", "timestamp": "$timestamp" } EOF 

I agree with everything else in Cuba to answer the question of where to store the file and how to access it on the server.

+1
source share

I tried a different approach based on what I saw here, and just in case, someone needs to get a version from the client too, here's a Windows-based answer:

prefetch file

 #!/bin/sh node auto-version RETVAL=$? if [ $RETVAL -ne 0 ] then exit 1 fi exec git add ./pathTo/_version.js 

automatic version file

 var execSync = require("child_process").execSync; var path = require("path"); var fs = require("fs"); var outputFile = path.normalize(__dirname + "/pathTo/_version.js"); var currentVersion = JSON.parse(fs.readFileSync('./pathTo/_version.js', 'utf8').replace("myVar =" , "")); function parse(cmd) { var stdout = execSync(cmd, { encoding: "utf8" }); return stdout.replace("* ", "").replace("\n", ""); } try { console.log("vers",currentVersion); var myVar = JSON.stringify( { version: currentVersion.version+0.01, timestamp: new Date(), branch: parse('git branch | findstr "*"'), pre_commit: parse("git rev-parse HEAD") },null,2); fs.writeFileSync(outputFile, "myVar = " + myVar +"\n"); console.log("Succesfully updated " + outputFile); } catch(err) { console.log("Error updating " + outputFile); console.log(err); } 

initial file _version.js

 myVar = { "version": 0.00, } 

So, you just make a commit, launch the application, open the browser console and type myVar.version (of course, this is just a simple example)
Please note that _version.js will be marked as modified after the commit, but the version upgrade is actually done, so just ignore the marked file. You can complete this method using the post-commit method from Kuba Wyrobek to get the version of post-commit git (in my case, knowing the previous one is enough).

+1
source share

All Articles