feat(scripts): add .npmrc template + sync/drift-check scripts (DRY)

Single source of truth: scripts/npmrc.template
- sync-npmrc.sh: copies template to all 13 product repos
- check-npmrc-drift.sh: detects drift (exit 1 if any repo drifted)

Also synced 4 drifted repos: MindLyst, NoteLett, ActionTrail, Talk2Obs.
Prevents future gitea.bytelyst.com hardcoding issues.
This commit is contained in:
saravanakumardb1 2026-04-14 11:48:55 -07:00
parent acace0cdc5
commit 01cc5b35a4
3 changed files with 156 additions and 0 deletions

View File

@ -0,0 +1,75 @@
#!/usr/bin/env bash
# check-npmrc-drift.sh — Detect .npmrc drift across ByteLyst repos.
#
# Returns exit code 1 if any repo's .npmrc differs from the canonical template.
# Use in CI or as a periodic audit:
# bash scripts/check-npmrc-drift.sh
#
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
TEMPLATE="$SCRIPT_DIR/npmrc.template"
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
PARENT_DIR="$(dirname "$REPO_ROOT")"
if [ ! -f "$TEMPLATE" ]; then
echo "❌ Template not found: $TEMPLATE" >&2
exit 1
fi
REPOS=(
learning_ai_common_plat
learning_voice_ai_agent
learning_multimodal_memory_agents
learning_ai_clock
learning_ai_efforise
learning_ai_fastgap
learning_ai_flowmonk
learning_ai_jarvis_jr
learning_ai_local_llms
learning_ai_local_memory_gpt
learning_ai_notes
learning_ai_peakpulse
learning_ai_trails
learning_ai_talk2obsidian
)
drifted=0
missing=0
ok=0
for repo in "${REPOS[@]}"; do
target="$PARENT_DIR/$repo/.npmrc"
if [ ! -d "$PARENT_DIR/$repo" ]; then
continue
fi
if [ ! -f "$target" ]; then
echo "⚠️ $repo — .npmrc missing"
((missing++)) || true
continue
fi
if diff -q "$TEMPLATE" "$target" >/dev/null 2>&1; then
((ok++)) || true
else
echo "$repo — .npmrc drifted from template"
diff --color=auto "$TEMPLATE" "$target" 2>/dev/null | head -10 || true
echo ""
((drifted++)) || true
fi
done
echo "────────────────────────────────"
echo "$ok repos match template"
[ "$missing" -gt 0 ] && echo "⚠️ $missing repos missing .npmrc"
[ "$drifted" -gt 0 ] && echo "$drifted repos drifted"
echo ""
if [ "$drifted" -gt 0 ] || [ "$missing" -gt 0 ]; then
echo "Fix: bash scripts/sync-npmrc.sh"
exit 1
fi
echo "All repos in sync ✅"

5
scripts/npmrc.template Normal file
View File

@ -0,0 +1,5 @@
@bytelyst:registry=http://${GITEA_NPM_HOST:-localhost}:3300/api/packages/ByteLyst/npm/
//localhost:3300/api/packages/ByteLyst/npm/:_authToken=${GITEA_NPM_TOKEN}
strict-ssl=false
link-workspace-packages=true
prefer-workspace-packages=true

76
scripts/sync-npmrc.sh Normal file
View File

@ -0,0 +1,76 @@
#!/usr/bin/env bash
# sync-npmrc.sh — Copy canonical .npmrc to all ByteLyst product repos.
#
# Single source of truth: scripts/npmrc.template
# Run from learning_ai_common_plat root:
# bash scripts/sync-npmrc.sh # apply to all repos
# bash scripts/sync-npmrc.sh --dry-run # show what would change
#
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
TEMPLATE="$SCRIPT_DIR/npmrc.template"
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
PARENT_DIR="$(dirname "$REPO_ROOT")"
if [ ! -f "$TEMPLATE" ]; then
echo "❌ Template not found: $TEMPLATE" >&2
exit 1
fi
DRY_RUN=false
[ "${1:-}" = "--dry-run" ] && DRY_RUN=true
# All product repos that need .npmrc (sibling directories)
REPOS=(
learning_voice_ai_agent
learning_multimodal_memory_agents
learning_ai_clock
learning_ai_efforise
learning_ai_fastgap
learning_ai_flowmonk
learning_ai_jarvis_jr
learning_ai_local_llms
learning_ai_local_memory_gpt
learning_ai_notes
learning_ai_peakpulse
learning_ai_trails
learning_ai_talk2obsidian
)
changed=0
skipped=0
up_to_date=0
shopt -s nullglob
for repo in "${REPOS[@]}"; do
target="$PARENT_DIR/$repo/.npmrc"
if [ ! -d "$PARENT_DIR/$repo" ]; then
echo "$repo — not found, skipping"
((skipped++)) || true
continue
fi
if [ -f "$target" ] && diff -q "$TEMPLATE" "$target" >/dev/null 2>&1; then
echo "$repo — up to date"
((up_to_date++)) || true
continue
fi
if $DRY_RUN; then
echo "🔄 $repo — would update"
if [ -f "$target" ]; then
diff --color=auto "$target" "$TEMPLATE" || true
fi
else
cp "$TEMPLATE" "$target"
echo "🔄 $repo — updated"
fi
((changed++)) || true
done
echo ""
echo "Summary: $changed changed, $up_to_date up-to-date, $skipped skipped"
$DRY_RUN && echo "(dry run — no files modified)"