From 0a1b30385316232698c71e8c6f891d01b944e676 Mon Sep 17 00:00:00 2001 From: jjrv Date: Wed, 31 Oct 2018 22:19:57 +0200 Subject: [PATCH] Add checkver tool. --- README.md | 9 +++++++++ checkver | 32 ++++++++++++++++++++++++++++++++ package.json | 5 +++++ 3 files changed, 46 insertions(+) create mode 100755 checkver diff --git a/README.md b/README.md index 677eaa2..0fd57cc 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,15 @@ Any more complicated setup should use a traditional rollup config file with plug [rollup-plugin-commonjs](https://github.com/rollup/rollup-plugin-commonjs). This package is for avoiding build system bloat in simpler cases. +For testing packages with old Node.js versions (lack of modern JavaScript features can resemble old mobile browsers), +it can be helpful to run `rollup` conditionally in package scripts using the included `checkver` tool: + +```json +{ + "prepublish": "(checkver ge 5.0.0 && rollup -c)" +} +``` + # License [The MIT License](https://raw.githubusercontent.com/charto/autoroll/master/LICENSE) diff --git a/checkver b/checkver new file mode 100755 index 0000000..1bccd07 --- /dev/null +++ b/checkver @@ -0,0 +1,32 @@ +#!/usr/bin/env node + +var op = process.argv[2].match(/^([gl])([te])$/); +var wanted = (process.argv[3] || '').split('.'); +var version = process.versions.node.split('.'); + +if(!op || wanted.length != 3) { + console.log([ + 'usage:', + process.argv[0].replace(/.*\//, ''), + process.argv[1].replace(/.*\//, ''), + 'op', + 'x.y.z' + ].join(' ')); + + console.log('\nCompare Node.js version.'); + console.log('Following op codes determine whether it must be:\n'); + + console.log('\tgt\tGreater than x.y.z.'); + console.log('\tge\tGreater than or equal to x.y.z.'); + console.log('\tlt\tLess than x.y.z.'); + console.log('\tle\tLess than or equal to x.y.z.'); + + process.exit(1); +} + +for(var i = 0; i < 3; ++i) { + if(+version[i] > +wanted[i]) process.exit(+(op[1] != 'g')); + if(+version[i] < +wanted[i]) process.exit(+(op[1] == 'g')); +} + +process.exit(+(op[2] != 'e')); diff --git a/package.json b/package.json index d988918..0cb71b7 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,9 @@ "version": "0.1.0", "description": "Rollup autoconfigurator", "main": "index.js", + "bin": { + "checkver": "checkver" + }, "author": "Juha Järvi", "license": "MIT", "repository": { @@ -14,6 +17,8 @@ }, "homepage": "https://github.com/charto/autoroll#readme", "keywords": [ + "loader", + "module", "package", "rollup" ]