fix(grunt): cache version number

caching the version number speeds up the build and preserves resources.

this also fixed EMFILE error that now occurs on some macs.
This commit is contained in:
Igor Minar 2013-07-13 23:41:47 -07:00 committed by Brian Ford
parent 64e447354e
commit edef295b11

View file

@ -2,6 +2,7 @@ var fs = require('fs');
var shell = require('shelljs');
var grunt = require('grunt');
var spawn = require('child_process').spawn;
var version;
module.exports = {
@ -11,13 +12,18 @@ module.exports = {
getVersion: function(){
if (version) return version;
var package = JSON.parse(fs.readFileSync('package.json', 'UTF-8'));
var match = package.version.match(/^([^\-]*)(-snapshot)?$/);
var semver = match[1].split('.');
var hash = shell.exec('git rev-parse --short HEAD', {silent: true}).output.replace('\n', '');
var version = {
full: (match[1] + (match[2] ? '-' + hash : '')),
var fullVersion = (match[1] + (match[2] ? '-' + hash : ''));
var numVersion = semver[0] + '.' + semver[1] + '.' + semver[2];
version = {
number: numVersion,
full: fullVersion,
major: semver[0],
minor: semver[1],
dot: semver[2],