diff --git a/lib/carto/index.js b/lib/carto/index.js index 13de4b8..326b591 100644 --- a/lib/carto/index.js +++ b/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'), diff --git a/test/version.test.js b/test/version.test.js new file mode 100644 index 0000000..3684a44 --- /dev/null +++ b/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); + } + }); +});