← back to Consulting Designerwallcoverings Com

scripts/weekly-refresh.sh

59 lines

#!/bin/bash
# ---------------------------------------------------------------------------
# DW consulting portal — weekly snapshot auto-refresh (collector + build + commit)
#
# DTD verdict A (2026-07-26, 5/5 unanimous — Claude+Codex+Qwen+Grok+Kimi):
# refresh the ENTIRE committed snapshot in one coherent pass so nothing drifts.
# Both generators are READ-ONLY SELECTs against the Mac2-LOCAL dw_unified mirror
# (host=/tmp socket) — NOT a Kamatera-canonical write — and everything they emit
# is captured behind a single git commit, so this whole run is reversible/local.
#
# Runs three read-only steps, then commits:
#   1. scripts/collect-dw.mjs  -> data/dw-analysis.json     (snapshot source)
#   2. build.mjs               -> rendered site from the snapshot
#   3. scripts/build-work-orders.mjs -> data/work-orders/*.csv + SUMMARY.md + media.json
#
# NO DEPLOY. This script never rsyncs, never touches pm2, never writes to any DW
# system. Shipping the refreshed snapshot to prod stays a separate, Steve-gated
# /deploy step. Intended to be driven weekly by launchd com.steve.dw-consult-refresh
# (Sunday 03:00) — that plist install is GATED and drafted to pending-approval;
# this script is also safe to run by hand any time.
# ---------------------------------------------------------------------------
set -euo pipefail

cd "$(dirname "$0")/.."
ROOT="$(pwd)"

# Prefer homebrew node when run headless under launchd (minimal PATH).
export PATH="/opt/homebrew/bin:/usr/local/bin:$PATH"

log(){ echo "[weekly-refresh $(date '+%Y-%m-%d %H:%M:%S')] $*"; }

# Log growth is negligible (~a handful of lines once/week to the gitignored launchd
# .out/.err logs) — no in-job rotation, which would risk a sparse-file/offset quirk
# by truncating the fd launchd is actively redirecting into.

log "start — $ROOT"

# 1 + 2 — the /api/refresh flow: read-only collector then the site build.
log "collect  -> data/dw-analysis.json"
node scripts/collect-dw.mjs >/dev/null

log "build    -> rendered site"
node build.mjs >/dev/null

# 3 — work-orders deliverable (same mirror, read-only) so the whole snapshot is coherent.
log "work-orders -> data/work-orders/*"
node scripts/build-work-orders.mjs >/dev/null

# --- commit anything the refresh touched (snapshot data + rebuilt public assets) ----
if [ -n "$(git status --porcelain)" ]; then
  git add -A
  git commit -q -m "weekly snapshot refresh: dw-analysis + build + work-orders ($(date '+%Y-%m-%d'))"
  log "committed $(git rev-parse --short HEAD)"
else
  log "no changes — snapshot already current, nothing to commit"
fi

log "done — NO deploy (shipping to prod stays a separate gated /deploy step)"