Last active
August 5, 2025 05:33
-
-
Save isurfer21/3a8b51d2b00314ff1d409bd5bf3f3697 to your computer and use it in GitHub Desktop.
A CLI tool which calculates the age of the node_modules directory in days.
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 | |
| # Define the path to the node_modules directory | |
| NODE_MODULES_DIR="node_modules" | |
| # Check if node_modules directory exists | |
| if [ ! -d "$NODE_MODULES_DIR" ]; then | |
| echo "node_modules directory does not exist." | |
| else | |
| # Get the last modified time of the most recently modified file in node_modules | |
| LAST_MODIFIED=$(find "$NODE_MODULES_DIR" -type f -exec stat -f %m {} + | sort -n | tail -1) | |
| # Get the current time | |
| CURRENT_TIME=$(date +%s) | |
| # Calculate the age of node_modules in days | |
| AGE_DAYS=$(( (CURRENT_TIME - LAST_MODIFIED) / 86400 )) | |
| # Define the threshold for "old enough" (e.g., 7 days) | |
| THRESHOLD_DAYS=7 | |
| if [ "$AGE_DAYS" -ge "$THRESHOLD_DAYS" ]; then | |
| echo "node_modules is $AGE_DAYS days old." | |
| else | |
| echo "node_modules is up to date." | |
| fi | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment