Browse files

report correct, current carto version via package.json - closes #205

  • Loading branch information...
1 parent 5978135 commit 410f47b5ce4de3ba8f2be31bcbf51a2adbb24ae9 @springmeyer springmeyer committed Oct 24, 2012
Showing with 31 additions and 1 deletion.
  1. +14 −1 lib/carto/index.js
  2. +17 −0 test/version.test.js
View
15 lib/carto/index.js
@@ -1,6 +1,19 @@
var util = require('util');
+var fs = require('fs');
+var path = require('path');
+
+function getVersion() {
+ if (parseInt(process.version.split('.')[1]) > 4) {
+ return require('../../package.json').version.split('.');
+ } else {
+ // older node
+ var package_json = JSON.parse(fs.readFileSync(path.join(__dirname,'../../package.json')))
+ return package_json.version.split('.');
+ }
+}
+
var carto = {
- version: [0, 4, 7],
+ version: getVersion(),
Parser: require('./parser').Parser,
Renderer: require('./renderer').Renderer,
tree: require('./tree'),
View
17 test/version.test.js
@@ -0,0 +1,17 @@
+var carto = require('../lib/carto');
+var fs = require('fs');
+var path = require('path');
+var assert = require('assert');
+
+
+describe('Version check', function() {
+ it('test version matches package.json version and changelog', function() {
+ if (parseInt(process.version.split('.')[1]) > 4) {
+ var info = require('../package.json');
+ assert.deepEqual(info.version.split('.'), carto.version);
+ } else {
+ var info = JSON.parse(require('fs').readFileSync(path.join(__dirname,'../package.json')));
+ assert.deepEqual(info.version.split('.'), carto.version);
+ }
+ });
+});

0 comments on commit 410f47b

Please sign in to comment.