From b13a81baac70983be16e10be2d59530c979f261a Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Tue, 12 Jan 2016 10:44:20 -0800 Subject: [PATCH] [BUGFIX release] Use correct version number when used as an addon. --- lib/calculate-version.js | 16 ++++++++++++++++ lib/version-replace.js | 5 ++--- lib/version.js | 11 ++--------- package.json | 3 ++- 4 files changed, 22 insertions(+), 13 deletions(-) create mode 100644 lib/calculate-version.js diff --git a/lib/calculate-version.js b/lib/calculate-version.js new file mode 100644 index 00000000000..75b7af2c185 --- /dev/null +++ b/lib/calculate-version.js @@ -0,0 +1,16 @@ +var path = require('path'); +var existsSync = require('exists-sync'); +var gitRepoInfo = require('git-repo-info'); + +module.exports = function() { + var gitPath = path.join(__dirname, '..', '.git'); + var packageVersion = require('../package.json').version; + + if (existsSync(gitPath)) { + var info = gitRepoInfo(gitPath); + + return packageVersion + '+' + info.sha.slice(0, 10); + } else { + return packageVersion; + } +}; diff --git a/lib/version-replace.js b/lib/version-replace.js index 92fc17cb86d..bb443549a22 100644 --- a/lib/version-replace.js +++ b/lib/version-replace.js @@ -1,4 +1,4 @@ -var VERSION = require('git-repo-version')(10); +var calculateVersion = require('./calculate-version'); var replace = require('broccoli-string-replace'); module.exports = function configFiles(tree) { @@ -6,8 +6,7 @@ module.exports = function configFiles(tree) { files: ['*.{json,js}'], pattern: { match: /VERSION_STRING_PLACEHOLDER/g, - replacement: VERSION + replacement: calculateVersion() } }); }; - diff --git a/lib/version.js b/lib/version.js index c76390fb201..dd80c315bd2 100644 --- a/lib/version.js +++ b/lib/version.js @@ -1,13 +1,6 @@ +var calculateVersion = require('./calculate-version'); var createFile = require('broccoli-file-creator'); -var version; - -try { - version = require('git-repo-version')(10); -} catch (e) { - version = require('../package').version; -} - module.exports = function() { - return createFile('version.js', 'export default "' + version + '";'); + return createFile('version.js', 'export default "' + calculateVersion() + '";'); }; diff --git a/package.json b/package.json index 2d6d087db57..943664f3d05 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,8 @@ "ember-cli-test-info": "^1.0.0", "ember-cli-version-checker": "^1.1.4", "ember-inflector": "^1.9.4", + "exists-sync": "0.0.3", + "git-repo-info": "^1.1.2", "inflection": "^1.8.0", "semver": "^5.1.0", "silent-error": "^1.0.0" @@ -67,7 +69,6 @@ "ember-publisher": "0.0.7", "ember-try": "0.0.6", "ember-watson": "^0.7.0", - "git-repo-version": "^0.3.0", "github": "^0.2.4", "glob": "^5.0.13", "lodash.assign": "^3.2.0",