Skip to content

Instantly share code, notes, and snippets.

Created September 10, 2014 17:30
What would you like to do?
npm install's all required packages in a file, using sed and xargs, --save-dev and --save optional
# npm install all required packages
# example usage
# ./ --save-dev
# ./ --save
# ./
# TODO: this matches require's that are commented out. Fix.
# TODO: doesn't match multiple requires on one line. But do you really want to ever write code like that?
sed -e "/\(.*\)require('\([-A-Za-z0-9]*\)')\(.*\)/!d" \
-e "s/\(.*\)require('\([-A-Za-z0-9]*\)')\(.*\)/\2/" $FILENAME \
| xargs -L1 npm install "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment