Reputation: 2951
I like to display my project version (from package.json), the git commit hash and working-copy status in the footer of my Ember app built using ember-cli and broccoli.
I can grab the version prefix easily enough by adding to my config/environment.js:
ENV.APP.version = require('../package.json').version
I was using grunt-git-describe previously to grab the revision hash and dirty/clean status. How can I do something similar in ember-cli?
Simply shelling out to git describe
is problematic since child_process does not have a synchronous method of executing a shell command.
It there a way I can return a promise from somewhere and prevent config/environment.js from resolving until my async git describe
completes?
The npm packages exec-sync and execSync don't seem to work well for me on Windows.
Upvotes: 2
Views: 2002
Reputation: 2951
ember-git-version is an ember-cli addon that provides the current revision hash.
After installing the node package, the config/environment hash will have a property currentRevision
. See initializers/print-git-info.js for how to access it from your app.
Upvotes: 3
Reputation: 567
You can use the exec-sync
package and then add something like this to Brocfile.js:
var execSync = require('exec-sync'),
gitVersion = execSync('git describe');
fs.writeFileSync('app/version.js', 'App.version = "' + gitVersion + '";';
You'll then need to import that somewhere.
Upvotes: 1