Last active
September 18, 2015 01:03
Revisions
-
adalinesimonian revised this gist
Sep 18, 2015 . 1 changed file with 0 additions and 4 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -13,10 +13,6 @@ dependencies="$(grep -Pzo "(?s)(?<=\"dependencies\": {)[^}]+" package.json | gre devDependencies="$(grep -Pzo "(?s)(?<=\"devDependencies\": {)[^}]+" package.json | grep -ohP "(?<=\")[^\"]+(?=\":)")" nativeModules="$(node -e "console.log(Object.keys(process.binding('natives')).filter(function (el) {return !/^_|^internal/.test(el) && ['freelist', 'sys'].indexOf(el) === -1;}).join('\\n'))")" if [ "$1" = "-d" ]; then printf '%s\n' "$requires" | while IFS= read -r line do -
adalinesimonian revised this gist
Sep 18, 2015 . 1 changed file with 48 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,50 @@ #!/bin/sh # Requires ag - The Silver Searcher (https://github.com/ggreer/the_silver_searcher) # (no options) - checks if dependencies are in use # -d - checks if all requires have a matching dependency entry # One-liner that checks for in-use dependencies # grep -Pzo "(?s)(?<=\"dependencies\": {)[^}]+" package.json | grep -ohP "(?<=\")[^\"]+(?=\":)" | xargs -L1 --replace sh -c "if ! ag \"require[\\( ]'{}'\" > /dev/null 2> /dev/null; then printf '\\033[1;31mREQUIRE NOT FOUND:\\t%s\033[m\\n' {}; else printf 'Require found:\\t\\t%s\\n' {}; fi" requires="$(ag "require(\(| )('|\")[^'\"]+" | grep -ohP "(?<=require[\( ]('|\"))[^'\"/]+(?=('|\"))" | sort -u)" dependencies="$(grep -Pzo "(?s)(?<=\"dependencies\": {)[^}]+" package.json | grep -ohP "(?<=\")[^\"]+(?=\":)")" devDependencies="$(grep -Pzo "(?s)(?<=\"devDependencies\": {)[^}]+" package.json | grep -ohP "(?<=\")[^\"]+(?=\":)")" nativeModules="$(node -e "console.log(Object.keys(process.binding('natives')).filter(function (el) {return !/^_|^internal/.test(el) && ['freelist', 'sys'].indexOf(el) === -1;}).join('\\n'))")" echo $dependencies if [ "$1" = "-d" ]; then printf '%s\n' "$requires" | while IFS= read -r line do if [ ! -z "$(echo "$dependencies" | grep -Pzo "^$line$")" ]; then printf 'Dependency found:\t%s\n' $line elif [ ! -z "$(echo "$devDependencies" | grep -Pzo "^$line$")" ]; then printf 'Dev dependency found:\t%s\n' $line elif [ ! -z "$(echo "$nativeModules" | grep -Pzo "^$line$")" ]; then printf 'Native module found:\t%s\n' $line else printf '\033[1;31mDEPENDENCY NOT FOUND:\t%s\033[m\n' $line fi done else printf '%s\n' "$dependencies" | while IFS= read -r line do if [ ! -z "$(echo "$requires" | grep -Pzo "^$line$")" ]; then printf 'Require found:\t\t%s\n' $line else printf '\033[1;31mREQUIRE NOT FOUND:\t%s\033[m\n' $line fi done printf '%s\n' "$devDependencies" | while IFS= read -r line do if [ ! -z "$(echo "$requires" | grep -Pzo "^$line$")" ]; then printf 'Require found:\t\t%s\n' $line else printf '\033[1;31mREQUIRE NOT FOUND:\t%s\033[m\n' $line fi done fi -
adalinesimonian created this gist
Sep 17, 2015 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,4 @@ # One-liner # Requires ag - The Silver Searcher (https://github.com/ggreer/the_silver_searcher) grep -Pzo "(?s)(?<=\"dependencies\": {)[^}]+" package.json | grep -ohP "(?<=\")[^\"]+(?=\":)" | xargs -L1 --replace sh -c "if ! ag \"require[\\( ]'{}'\" > /dev/null 2> /dev/null; then printf '\\033[1;31mREQUIRE NOT FOUND:\\t%s\033[m\\n' {}; else printf 'Require found:\\t\\t%s\\n' {}; fi"