Last active
March 18, 2024 19:32
-
-
Save r17x/6eed7cedb700fd2ba910e0a103e52658 to your computer and use it in GitHub Desktop.
chmod +x <THISSCRIPT>
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
#!/bin/bash | |
# Function to display the postinstall field of package.json if exists | |
display_hook_install() { | |
if [ -f "$1" ]; then | |
postinstall=$(jq -r '.scripts.postinstall' "$1") | |
dir=$(dirname "$1") | |
packagename=$(jq -r '.name' "$1") | |
packageversion=$(jq -r '.version' "$1") | |
if [ "$postinstall" != "null" ]; then | |
printf "| \e[91m%-40s\e[0m | \e[91m%-40s\e[0m | %s \n" "$packagename@$packageversion" "$postinstall" "$dir" | |
fi | |
fi | |
} | |
# Print table header | |
echo "=============================================================" | |
echo "| Package | Postinstall Script | Dir |" | |
echo "=============================================================" | |
# Find all node_modules directories and display their postinstall field | |
find . -type f -name "package.json" | while read -r pkgjson; do | |
display_hook_install "$pkgjson" | |
done | |
# Print table footer | |
echo "=========================================" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment