npm install's all required packages in a file, using sed and xargs, --save-dev and --save optional
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# npm install all required packages | |
# example usage | |
# | |
# ./install-required-packages.sh gulpfile.sh --save-dev | |
# ./install-required-packages.sh gulpfile.sh --save | |
# ./install-required-packages.sh gulpfile.sh | |
# | |
# 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? | |
FILENAME=$1 | |
shift | |
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