Skip to content

Commit

Permalink
Add checkver tool.
Browse files Browse the repository at this point in the history
  • Loading branch information
jjrv committed Nov 1, 2018
1 parent 42a81c0 commit 0a1b303
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
32 changes: 32 additions & 0 deletions checkver
Original file line number Diff line number Diff line change
@@ -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'));
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"version": "0.1.0",
"description": "Rollup autoconfigurator",
"main": "index.js",
"bin": {
"checkver": "checkver"
},
"author": "Juha Järvi",
"license": "MIT",
"repository": {
Expand All @@ -14,6 +17,8 @@
},
"homepage": "https://github.com/charto/autoroll#readme",
"keywords": [
"loader",
"module",
"package",
"rollup"
]
Expand Down

0 comments on commit 0a1b303

Please sign in to comment.