assert-version
Check if version mentions match the one from package.json
Install
npm install -g assert-version
How matches work
Version could be extracted with regular expression or, if you use
assert-version
as Node.js module, with user-defined function.
In case of regular expression, version should present in first capture.
There are two default regular expressions. If your file has .json
extension,
/"version":\s*"([^"]+)/
expression is used. Otherwise,
/\/\*\![\s\S]+(v?\d+\.\d+\.\d+)/
expression is used. I understand that these
expressions are not great, they just seem to work for my cases. Feel free to
send improvements.
Extracted version should be valid semver version.
Use as Node.js module
assertVersion = ; var error = ; // `error` will have error message in case of error, `undefined` otherwise.
Optionally, you can pass path to package.json
with reference version as
second argument of assertVersion()
. It is package.json
from current
working directory by default.
Use as command line tool
Same to previous example (except for function extractor):
assert-version -f bower.json -f mylib.js -f other.js='version=([^,]+)' -f other3.js=matcher1 -f other3.js=matcher2
Example (Gulp task)
Example from https://github.com/hoho/conkitty-route/blob/master/gulpfile.js.
gulp;
Example (Grunt task)
Example from https://github.com/hoho/concat.js/blob/master/Gruntfile.js.
grunt;