From d1a18c6ff15e7a6220285c29af1cbc57b2e62a19 Mon Sep 17 00:00:00 2001 From: Dumitru Uzun Date: Mon, 20 Apr 2015 14:19:37 +0300 Subject: [PATCH 1/2] Added script to bump version. Eg: npm run verup -- 1.0 --- bower.json | 86 +++++++++++++++---------------- build/verup.js | 108 +++++++++++++++++++++++++++++++++++++++ component.json | 16 ++++-- package.json | 7 +-- ua-parser-js.jquery.json | 62 +++++++++++----------- 5 files changed, 198 insertions(+), 81 deletions(-) create mode 100644 build/verup.js diff --git a/bower.json b/bower.json index 4d9e500..7ecce78 100644 --- a/bower.json +++ b/bower.json @@ -1,45 +1,43 @@ { - "name": "ua-parser-js", - "version": "0.7.6", - "authors": [ - "Faisal Salman " - ], - "private": false, - "main": "src/ua-parser.js", - "ignore": [ - "build", - "node_modules", - "bower_components", - "test", - "tests" - ], - "contributors": [ - "Faisal Salman ", - "Benjamin Bertrand ", - "Carl C Von Lewin ", - "Christopher De Cairos ", - "Davit Barbakadze ", - "Dmitry Tyschenko ", - "Douglas Li ", - "Dumitru Uzun ", - "Erik Hesselink ", - "Fabian Becker ", - "Hendrik Helwich ", - "Jackpoll ", - "Jake Mc ", - "John Tantalo ", - "John Yanarella ", - "Jon Buckley ", - "Kendall Buchanan ", - "Lee Treveil ", - "Leonardo ", - "Max Maurer ", - "Michael Hess ", - "OtakuSiD ", - "Ross Noble ", - "Sandro Sonntag " - ], - "dependencies": { - - } -} + "name": "ua-parser-js", + "version": "0.7.6", + "authors": [ + "Faisal Salman " + ], + "private": false, + "main": "src/ua-parser.js", + "ignore": [ + "build", + "node_modules", + "bower_components", + "test", + "tests" + ], + "contributors": [ + "Faisal Salman ", + "Benjamin Bertrand ", + "Carl C Von Lewin ", + "Christopher De Cairos ", + "Davit Barbakadze ", + "Dmitry Tyschenko ", + "Douglas Li ", + "Dumitru Uzun ", + "Erik Hesselink ", + "Fabian Becker ", + "Hendrik Helwich ", + "Jackpoll ", + "Jake Mc ", + "John Tantalo ", + "John Yanarella ", + "Jon Buckley ", + "Kendall Buchanan ", + "Lee Treveil ", + "Leonardo ", + "Max Maurer ", + "Michael Hess ", + "OtakuSiD ", + "Ross Noble ", + "Sandro Sonntag " + ], + "dependencies": {} +} \ No newline at end of file diff --git a/build/verup.js b/build/verup.js new file mode 100644 index 0000000..f8f0140 --- /dev/null +++ b/build/verup.js @@ -0,0 +1,108 @@ +#!/usr/bin/env node +/** + * Increment and update version in all project files. + * + * Ussage: + * + * Increment revision by 1: + * node verup.js 1 + * + * Increment minor version by 1: + * node verup.js 1.0 + * + * Increment major version by 1: + * node verup.js 1.0.0 + * + * + * @author Dumitru Uzun (DUzun.Me) + * @version 1.0.0 + */ + +var path = require('path'); +var fs = require('fs'); + +var _root = path.join(__dirname, '..'); +var files = [ + 'ua-parser-js.jquery.json', + 'component.json', + 'bower.json', + 'package.js', + 'src/ua-parser.js' +]; + +var ver_reg = [ + /^((?:\$|@|(\s*(?:var|,)?\s+))(?:LIBVERSION|version)[\s\:='"]+)([0-9]+(?:\.[0-9]+){2,2})/ + , /^(\s?\*.*v)([0-9]+(?:\.[0-9]+){2,2})/ +]; + +var packFile = path.join(_root, 'package.json'); +var packo = require(packFile); + +if ( !packo ) { + console.error('Can\'t read package.json file'); + process.exit(1); +} + +var over = packo.version; + +/* + * bump should be 1 for revision, 1.0 for minor and 1.0.0 for major version + */ +var bump = (process.argv[2] || '1').split('.').reverse(); + +if ( over ) { + var nver = over.split('.').reverse(); + var b, l; + while(bump.length && !(b = parseInt(bump.pop()))); + l = bump.length; + +// console.log({b:b,nver:nver,over:over,l:l,bump:bump}) + nver[l] = +nver[l] + b; + bump.forEach(function (v,i) { nver[i] = v; }); + + nver = nver.reverse().join('.'); + packo.version = nver; + + console.log('Bumping version: ' + over + ' -> ' + nver); + + var buf = JSON.stringify(packo, null, 2); + + if ( buf && over != nver ) { + fs.writeFileSync(packFile, buf); + } + + files.forEach(function (f) { + var fn = path.join(_root, f); + var cnt = fs.readFileSync(fn, 'utf8'); + var ext = path.extname(f); + var buf; + + switch(ext) { + case '.json': { + var packo = JSON.parse(cnt); + packo.version = nver; + buf = JSON.stringify(packo, null, 2); + } break; + + default: { + buf = cnt + .split('\n') + .map(function (l) { + for(var i=ver_reg.length; i--;) { + if ( ver_reg[i].test(l) ) { + return l.replace(ver_reg[i], function ($0,$1) { return $1 + nver }) + } + } + return l; + }) + .join("\n") + ; + } + } + if ( buf && buf != cnt ) { + console.log("\t" + fn.replace(_root, '')); + fs.writeFileSync(fn, buf); + } + }); + +} diff --git a/component.json b/component.json index 4d0db35..93d25df 100644 --- a/component.json +++ b/component.json @@ -2,8 +2,18 @@ "name": "ua-parser-js", "version": "0.7.6", "description": "Lightweight JavaScript-based user-agent string parser", - "keywords": ["user-agent", "parser", "browser", "engine", "os", "device", "cpu"], - "scripts": ["src/ua-parser.js"], + "keywords": [ + "user-agent", + "parser", + "browser", + "engine", + "os", + "device", + "cpu" + ], + "scripts": [ + "src/ua-parser.js" + ], "main": "src/ua-parser.js", "license": "MIT", "development": { @@ -11,4 +21,4 @@ "visionmedia/mocha": "*", "mishoo/uglifyjs2": "*" } -} +} \ No newline at end of file diff --git a/package.json b/package.json index bbdce07..a70172e 100644 --- a/package.json +++ b/package.json @@ -42,14 +42,15 @@ ], "main": "src/ua-parser.js", "scripts": { - "test": "./build/build.sh" + "test": "./build/build.sh", + "verup": "node ./build/verup.js" }, "devDependencies": { "jshint": "~1.1.0", "mocha": "~1.8.0", "uglify-js": "~1.3.4" }, - "repository" : { + "repository": { "type": "git", "url": "https://github.com/faisalman/ua-parser-js.git" }, @@ -71,4 +72,4 @@ "src": "src", "test": "test" } -} +} \ No newline at end of file diff --git a/ua-parser-js.jquery.json b/ua-parser-js.jquery.json index b96ad54..608dd82 100644 --- a/ua-parser-js.jquery.json +++ b/ua-parser-js.jquery.json @@ -1,32 +1,32 @@ { - "title": "UAParser.js", - "name": "ua-parser-js", - "version": "0.7.6", - "description": "Lightweight JavaScript-based user-agent string parser", - "keywords": [ - "user-agent", - "parser", - "browser", - "engine", - "os", - "device", - "cpu" - ], - "homepage": "https://faisalman.github.com/ua-parser-js", - "author": { - "name": "Faisal Salman", - "email": "fyzlman@gmail.com" - }, - "dependencies": { - "jquery": ">=1.5" - }, - "licenses": [ - { - "type": "MIT", - "url": "http://www.opensource.org/licenses/mit-license.php" - } - ], - "bugs": "https://github.com/faisalman/ua-parser-js/issues", - "docs": "https://github.com/faisalman/ua-parser-js", - "download": "https://raw.github.com/faisalman/ua-parser-js/master/dist/ua-parser.min.js" -} + "title": "UAParser.js", + "name": "ua-parser-js", + "version": "0.7.6", + "description": "Lightweight JavaScript-based user-agent string parser", + "keywords": [ + "user-agent", + "parser", + "browser", + "engine", + "os", + "device", + "cpu" + ], + "homepage": "https://faisalman.github.com/ua-parser-js", + "author": { + "name": "Faisal Salman", + "email": "fyzlman@gmail.com" + }, + "dependencies": { + "jquery": ">=1.5" + }, + "licenses": [ + { + "type": "MIT", + "url": "http://www.opensource.org/licenses/mit-license.php" + } + ], + "bugs": "https://github.com/faisalman/ua-parser-js/issues", + "docs": "https://github.com/faisalman/ua-parser-js", + "download": "https://raw.github.com/faisalman/ua-parser-js/master/dist/ua-parser.min.js" +} \ No newline at end of file From 32db7bfb978d8a1d945d2938f37bbfee8c065008 Mon Sep 17 00:00:00 2001 From: Dumitru Uzun Date: Mon, 20 Apr 2015 14:24:20 +0300 Subject: [PATCH 2/2] verup adds \n at the end of JSON files --- bower.json | 2 +- build/verup.js | 6 +++++- component.json | 2 +- package.json | 2 +- ua-parser-js.jquery.json | 2 +- 5 files changed, 9 insertions(+), 5 deletions(-) diff --git a/bower.json b/bower.json index 7ecce78..cd26d07 100644 --- a/bower.json +++ b/bower.json @@ -40,4 +40,4 @@ "Sandro Sonntag " ], "dependencies": {} -} \ No newline at end of file +} diff --git a/build/verup.js b/build/verup.js index f8f0140..a2cd149 100644 --- a/build/verup.js +++ b/build/verup.js @@ -15,7 +15,7 @@ * * * @author Dumitru Uzun (DUzun.Me) - * @version 1.0.0 + * @version 1.1.0 */ var path = require('path'); @@ -68,6 +68,7 @@ if ( over ) { var buf = JSON.stringify(packo, null, 2); if ( buf && over != nver ) { + buf += "\n"; fs.writeFileSync(packFile, buf); } @@ -82,6 +83,9 @@ if ( over ) { var packo = JSON.parse(cnt); packo.version = nver; buf = JSON.stringify(packo, null, 2); + if ( buf ) { + buf += "\n"; + } } break; default: { diff --git a/component.json b/component.json index 93d25df..12ca093 100644 --- a/component.json +++ b/component.json @@ -21,4 +21,4 @@ "visionmedia/mocha": "*", "mishoo/uglifyjs2": "*" } -} \ No newline at end of file +} diff --git a/package.json b/package.json index a70172e..175f857 100644 --- a/package.json +++ b/package.json @@ -72,4 +72,4 @@ "src": "src", "test": "test" } -} \ No newline at end of file +} diff --git a/ua-parser-js.jquery.json b/ua-parser-js.jquery.json index 608dd82..eb105da 100644 --- a/ua-parser-js.jquery.json +++ b/ua-parser-js.jquery.json @@ -29,4 +29,4 @@ "bugs": "https://github.com/faisalman/ua-parser-js/issues", "docs": "https://github.com/faisalman/ua-parser-js", "download": "https://raw.github.com/faisalman/ua-parser-js/master/dist/ua-parser.min.js" -} \ No newline at end of file +}