#!/usr/bin/env bash # lib/render.sh — envsubst-based template rendering # render_templates REPO_DIR # Finds all *.tpl files under REPO_DIR and renders them (output: same path without .tpl) render_templates() { local repo_dir="$1" step "Rendering templates" # Ensure gettext (envsubst) is available if ! has_cmd envsubst; then if is_macos; then warn "envsubst not found — installing gettext via Homebrew..." brew install gettext export PATH="/opt/homebrew/opt/gettext/bin:$PATH" else sudo apt-get install -y gettext-base 2>/dev/null fi fi local count=0 while IFS= read -r tpl; do local out="${tpl%.tpl}" envsubst < "$tpl" > "$out" success "Rendered $(basename "$out")" ((count++)) done < <(find "$repo_dir" -name "*.tpl" -not -path "*/.git/*") info "$count template(s) rendered." }