Skip to content

Instantly share code, notes, and snippets.

@rbalicki2
Created September 10, 2014 17:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rbalicki2/d084813b00aec21150b9 to your computer and use it in GitHub Desktop.
Save rbalicki2/d084813b00aec21150b9 to your computer and use it in GitHub Desktop.
npm install's all required packages in a file, using sed and xargs, --save-dev and --save optional
#!/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