Skip to content

Commit

Permalink
Ensure consistent library version across different files.
Browse files Browse the repository at this point in the history
  • Loading branch information
ariya committed Nov 13, 2013
1 parent aac913c commit 3933dfd
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 2 deletions.
2 changes: 1 addition & 1 deletion esprima.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
57 changes: 57 additions & 0 deletions tools/check-version.js
Original file line number Diff line number Diff line change
@@ -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.