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
parent 724819e3cf
commit b53c945bf5

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,6 +12,8 @@ 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('.');
@ -18,7 +21,7 @@ module.exports = {
var fullVersion = (match[1] + (match[2] ? '-' + hash : ''));
var numVersion = semver[0] + '.' + semver[1] + '.' + semver[2];
var version = {
version = {
number: numVersion,
full: fullVersion,
major: semver[0],