From 01cc5b35a41534d5947179d6910723bd1ee0cb3c Mon Sep 17 00:00:00 2001 From: saravanakumardb1 Date: Tue, 14 Apr 2026 11:48:55 -0700 Subject: [PATCH] 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. --- scripts/check-npmrc-drift.sh | 75 +++++++++++++++++++++++++++++++++++ scripts/npmrc.template | 5 +++ scripts/sync-npmrc.sh | 76 ++++++++++++++++++++++++++++++++++++ 3 files changed, 156 insertions(+) create mode 100644 scripts/check-npmrc-drift.sh create mode 100644 scripts/npmrc.template create mode 100644 scripts/sync-npmrc.sh diff --git a/scripts/check-npmrc-drift.sh b/scripts/check-npmrc-drift.sh new file mode 100644 index 00000000..88894cf9 --- /dev/null +++ b/scripts/check-npmrc-drift.sh @@ -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 ✅" diff --git a/scripts/npmrc.template b/scripts/npmrc.template new file mode 100644 index 00000000..4f51e760 --- /dev/null +++ b/scripts/npmrc.template @@ -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 diff --git a/scripts/sync-npmrc.sh b/scripts/sync-npmrc.sh new file mode 100644 index 00000000..7742eea5 --- /dev/null +++ b/scripts/sync-npmrc.sh @@ -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)"