Permalink
Browse files

Ensure consistent library version across different files.

  • Loading branch information...
1 parent aac913c commit 3933dfdf8db615a8c185ab8cc60966d8a740663d @ariya committed Nov 13, 2013
Showing with 59 additions and 2 deletions.
  1. +1 −1 esprima.js
  2. +1 −1 package.json
  3. +57 −0 tools/check-version.js
View
@@ -3814,7 +3814,7 @@ parseStatement: true, parseSourceElement: true */
return program;
}
- // Sync with package.json and component.json.
+ // Sync with *.json manifests.
exports.version = '1.1.0-dev';
exports.tokenize = tokenize;
View
@@ -42,7 +42,7 @@
"generate-regex": "node tools/generate-identifier-regex.js",
"test": "npm run-script lint && node test/run.js && npm run-script coverage && npm run-script complexity",
- "lint": "node_modules/jslint/bin/jslint.js esprima.js",
+ "lint": "node tools/check-version.js && node_modules/jslint/bin/jslint.js esprima.js",
"coverage": "npm run-script analyze-coverage && npm run-script check-coverage",
"analyze-coverage": "node node_modules/istanbul/lib/cli.js cover test/runner.js",
"check-coverage": "node node_modules/istanbul/lib/cli.js check-coverage --statement -8 --branch -19 --function 100",
View
@@ -0,0 +1,57 @@
+#!/usr/bin/env node
+
+'use strict';
+
+var fs = require('fs');
+
+function findCanonicalVersion() {
+ var matcher, lines, version;
+
+ matcher = /exports\.version\s+=\s+\'([0-9\.\-a-zA-Z]+)\'/;
+ lines = fs.readFileSync('esprima.js', 'utf-8').split('\n');
+ lines.forEach(function (line) {
+ if (matcher.test(line)) {
+ version = matcher.exec(line)[1];
+ }
+ });
+
+ return version;
+}
+
+function ensureVersion(manifestFile, expectedVersion) {
+ var matcher, lines, version;
+
+ console.log('Checking', manifestFile, '...');
+ matcher = /"version"\s*\:\s*"([0-9\.\-a-zA-Z]+)"/;
+ lines = fs.readFileSync(manifestFile, 'utf-8').split('\n');
+ lines.forEach(function (line) {
+ if (matcher.test(line)) {
+ version = matcher.exec(line)[1];
+ }
+ });
+ if (expectedVersion !== version) {
+ console.log('ERROR: Wrong version for', manifestFile);
+ console.log('Expected:', expectedVersion);
+ console.log(' Actual:', version);
+ process.exit(1);
+ }
+}
+
+function checkVersion() {
+ var version;
+
+ console.log('Getting the canonical library version...');
+ version = findCanonicalVersion();
+ if (typeof version !== 'string') {
+ console.log('ERROR: Can not get version number!', typeof version);
+ process.exit(1);
+ }
+ console.log('Library version is', version);
+
+ ensureVersion('package.json', version);
+ ensureVersion('bower.json', version);
+ ensureVersion('component.json', version);
+}
+
+
+checkVersion();

0 comments on commit 3933dfd

Please sign in to comment.