Back to Documentation
4-code-version.sh
Source Code / Script
Modified: 1/3/2026
Size: 5.1 KB
#!/bin/bash
# This script performs a comprehensive dependency health check across the entire AudivaMax monorepo. It scans all configured application and package directories to identify outdated NPM packages, generating a detailed, color-coded status report to assist developers in maintaining up-to-date and secure software libraries.
# ANSI Color Codes
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
RED='\033[0;31m'
NC='\033[0m' # No Color
# --- REPO ROOT ---
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
ROOT_DIR="$(cd -- "$SCRIPT_DIR/.." && pwd)"
cd "$ROOT_DIR" || exit 1
# --- REQUIREMENTS ---
for cmd in pnpm jq; do
if ! command -v "$cmd" >/dev/null 2>&1; then
echo -e "${RED}Error: required command not found: $cmd${NC}"
exit 1
fi
done
# --- HEADER ---
echo "=================================================="
echo "AudivaMax.com - Dependency Version Report (PNPM)"
echo "=================================================="
echo -e "[INFO] Generated: $(date '+%Y-%m-%d %H:%M:%S')\n"
# --- CONFIGURATION ---
# List of directories to check based on monorepo structure
DIRECTORIES=(
"."
"apps/admin"
"apps/api"
"apps/web"
"packages/client"
"packages/config"
"packages/contracts"
"packages/db"
)
# --- REPORTING FUNCTIONS ---
function process_directory() {
local dir_path=$1
local display_name
if [[ "$dir_path" == "." ]]; then
display_name="ROOT"
else
display_name="${dir_path#./}"
fi
echo -e "\nš¦ $display_name ($dir_path)\n"
if [ ! -d "$dir_path" ]; then
echo -e "${RED}Directory not found: $dir_path${NC}"
return
fi
if [ ! -f "$dir_path/package.json" ]; then
echo "No package.json found in $dir_path"
return
fi
pushd "$dir_path" > /dev/null || return
# Get installed versions
# pnpm list --json returns an array of objects (usually just one for the current package)
local list_json
if ! list_json=$(pnpm list --json --depth=0 2>/dev/null); then
echo -e "${YELLOW}[WARN] pnpm list failed in $dir_path; installed versions may be unavailable.${NC}"
list_json="[]"
fi
# Get outdated info
# pnpm outdated --json returns an object where keys are package names
local outdated_json
if ! outdated_json=$(pnpm outdated --json 2>/dev/null); then
echo -e "${YELLOW}[WARN] pnpm outdated failed in $dir_path; latest/wanted versions may be unavailable (offline?).${NC}"
outdated_json="{}"
fi
if [ -z "$outdated_json" ] || [ "$outdated_json" == "null" ]; then
outdated_json="{}"
fi
# Extract dependencies from package.json directly to ensure we catch everything
# (pnpm list might exclude some if not installed, but usually valid)
local deps=$(jq -r '(.dependencies // {} | keys) + (.devDependencies // {} | keys) | unique | .[]' package.json 2>/dev/null)
if [ -z "$deps" ]; then
echo "No dependencies found."
popd > /dev/null
return
fi
for dep in $deps;
do
# Get installed version from pnpm list output
# pnpm list json structure: [ { "dependencies": { "dep": { "version": "..." } }, "devDependencies": ... } ]
local installed=$(echo "$list_json" | jq -r --arg d "$dep" '.[0].dependencies[$d].version // .[0].devDependencies[$d].version // ""')
# Get latest/wanted from pnpm outdated
# pnpm outdated json structure: { "dep": { "current": "...", "latest": "...", "wanted": "..." } }
local latest=$(echo "$outdated_json" | jq -r --arg d "$dep" '.[$d].latest // ""')
local wanted=$(echo "$outdated_json" | jq -r --arg d "$dep" '.[$d].wanted // ""')
if [ -n "$latest" ] && [ "$latest" != "null" ]; then
# It is outdated
echo -e "ā ļø ${YELLOW}$dep${NC}: Current: $installed ā Wanted: $wanted ā Latest: ${RED}$latest${NC}"
((OUTDATED_COUNT++))
else
if [ -z "$installed" ]; then
echo -e "ā ${CYAN}$dep${NC}: (not installed or local link)"
else
echo -e "ā
${CYAN}$dep${NC}: $installed"
((UPTODATE_COUNT++))
fi
fi
((TOTAL_COUNT++))
done
popd > /dev/null
}
# --- MAIN LOGIC ---
UPTODATE_COUNT=0
OUTDATED_COUNT=0
TOTAL_COUNT=0
for dir in "${DIRECTORIES[@]}"; do
process_directory "$dir"
done
# --- SUMMARY ---
echo -e "\n=================================================="
echo -e "š SUMMARY STATISTICS"
echo -e "=================================================="
echo -e "ā
Up-to-date packages: $UPTODATE_COUNT"
echo -e "ā ļø Outdated packages: $OUTDATED_COUNT"
echo -e "š¦ Total packages: $TOTAL_COUNT"
if (( TOTAL_COUNT > 0 )); then
COVERAGE=$(( UPTODATE_COUNT * 100 / TOTAL_COUNT ))
echo -e "š Health Score: $COVERAGE%"
fi
echo -e "\n=================================================="
echo -e "š UPGRADE INSTRUCTIONS"
echo -e "=================================================="
if (( OUTDATED_COUNT > 0 )); then
echo -e "To upgrade all packages to their latest versions across the monorepo, run:"
echo -e "\n ${GREEN}pnpm update -r --latest${NC}\n"
echo -e "To upgrade only to the 'wanted' versions (respecting semver ranges), run:"
echo -e "\n ${GREEN}pnpm update -r${NC}\n"
else
echo -e "Everything looks up to date! No action needed."
fi
This is a read-only view of 4-code-version.sh. Changes must be made in the source repository.