Created
June 24, 2017 11:30
-
-
Save commenthol/3a0ea984b770de8eb8d0f5b5d453e784 to your computer and use it in GitHub Desktop.
find all required packages in a directory
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 | |
# find all required packages in a directory | |
# usage | |
# findrequire src | |
# findrequire src | xargs npm i -S | |
# findrequire test | xargs npm i -D | |
find $1 -iname "*.js" |\ | |
xargs egrep -h "require\(['][^.]" |\ | |
sed "s/.*require('\([^'']*\)').*/\1/g" |\ | |
egrep -v "^(assert|child|cluster|events|dgram|dns|domain|fs|http|https|inspector|net|os|path|punnycode|querystring|readline|stream|string_decoder|tls|tty|udp4|url|util|v8|vm|zlib)$" |\ | |
sort -u |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment