I have a node.js project to run on browser, so I have a Makefile with a few tasks that bundle everything in a single file (with browserify) and then minify it (uglify-js). I decided to use a Makefile instead of Grunt or others because it's simple and solve my problem.
The generated files are mylib.js and mylib.min.js, but I want something like mylib.1.0.1.js, where the version comes from my package.json.
I need a npm command to tell me what version is described inside package.json, but I didn't found any on the docs. Anyone knows how to get it?
node -e 'console.log(require("./package").version)'
or
npm --loglevel error list mylib | head -1 | cut -d " " -f 1 | cut -d @ -f 2
If you want to grab the version of a dependency, the command:
npm list | grep 'mylib' | awk '{print $2}' | cut -d @ -f 2
will return the string "1.0.1"
EDIT based on Peter's answer, it seems that this would do also:
node -e 'console.log(require("./package.json").dependencies.mylib)'