Skip to content

Instantly share code, notes, and snippets.

@r17x
Last active March 18, 2024 19:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save r17x/6eed7cedb700fd2ba910e0a103e52658 to your computer and use it in GitHub Desktop.
Save r17x/6eed7cedb700fd2ba910e0a103e52658 to your computer and use it in GitHub Desktop.
chmod +x <THISSCRIPT>
#!/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