-
-
Save chernjie/46983c4bc7c07b77014a5ae60065ca1a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env bash | |
# Like `npm`, but executes the command in nested sub-directories within | |
# your current git repository | |
# | |
# @author CJ <[email protected]> | |
# Example: | |
# | |
# $ npmr ls lodash # List installed packages in nested node packages | |
# | |
# $ npmr i # install node modules recursively | |
for-each-args () { | |
local _command=$1 | |
shift | |
for i in $@ | |
do | |
npm $_command $i & | |
done | |
wait | |
} | |
for-each-package() { | |
for i in $(git ls-files --recurse-submodules | grep package.json | xargs -n1 dirname) | |
do | |
cd $i > /dev/null | |
npm $@ & | |
cd - > /dev/null | |
done | |
wait | |
} | |
case $1 in | |
info) for-each-args $@ ;; | |
*) for-each-package $@ ;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment