zsh: get npm version of package
I needed to show the current package version when I was in a npm package folder.
get_npm_package_version() {
local JSON=''
if [[ -f 'package.json' ]]; then
echo $(node -e "var pkg = require('./package.json').version; if (pkg) console.log('(npm:'+pkg+')')")
fi
}
Usage: $(get_npm_package_version)
Written by S.Lacy
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Shell
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#