Skip to content

Instantly share code, notes, and snippets.

@commenthol
Created June 24, 2017 11:30
Show Gist options
  • Save commenthol/3a0ea984b770de8eb8d0f5b5d453e784 to your computer and use it in GitHub Desktop.
Save commenthol/3a0ea984b770de8eb8d0f5b5d453e784 to your computer and use it in GitHub Desktop.
find all required packages in a directory
#!/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