From f1793656f83f5b199032247a030ee51e1887a20d Mon Sep 17 00:00:00 2001 From: saravanakumardb1 Date: Tue, 24 Mar 2026 15:45:59 -0700 Subject: [PATCH] feat(scripts): make GITEA_NPM_HOST conditional on NETWORK MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - NETWORK=corp → GITEA_NPM_HOST=localhost (local Gitea Docker) - NETWORK=home → GITEA_NPM_HOST from ~/.gitea_vm_host (Azure VM) - Fallback: localhost if ~/.gitea_vm_host doesn't exist This enables all repo .npmrc files to use ${GITEA_NPM_HOST}:3300 instead of hardcoded localhost:3300, matching the existing .npmrc.docker pattern used during Docker builds. --- scripts/switch-network.sh | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/scripts/switch-network.sh b/scripts/switch-network.sh index e5a08e7b..4cad71b6 100755 --- a/scripts/switch-network.sh +++ b/scripts/switch-network.sh @@ -91,12 +91,35 @@ fi unset _CORP_PROXY _CORP_NPM_REGISTRY -# ── Gitea NPM token (always, regardless of NETWORK) ────────────── -# Local Gitea registry at localhost:3300 — token for publish access. -# Reads: public without auth. Writes: need GITEA_NPM_TOKEN. -# Store token in ~/.gitea_npm_token (one line, no newline). -# Create: curl -s -u admin:PASSWORD http://localhost:3300/api/v1/users/admin/tokens \ -# -H 'Content-Type: application/json' -d '{"name":"npm"}' | jq -r '.sha1 // .token' +# ── Gitea NPM registry (NETWORK-aware) ──────────────────────────── +# Repos use .npmrc with: @bytelyst:registry=http://${GITEA_NPM_HOST}:3300/... +# +# NETWORK=corp → Gitea runs locally on this machine (localhost) +# NETWORK=home → Gitea runs on the Azure VM (read host from ~/.gitea_vm_host) +# +# To configure the VM host (one-time): +# echo "bytelyst-vm.eastus.cloudapp.azure.com" > ~/.gitea_vm_host +# +# Token for publish access (reads are public, writes need auth): +# Store in ~/.gitea_npm_token (one line, no newline) +# Create: curl -s -u admin:PASSWORD http://:3300/api/v1/users/admin/tokens \ +# -H 'Content-Type: application/json' -d '{"name":"npm"}' | jq -r '.sha1 // .token' + +_GITEA_VM_HOST_FILE="$HOME/.gitea_vm_host" +if [ "${NETWORK:-home}" = "corp" ]; then + export GITEA_NPM_HOST="localhost" +else + if [ -f "$_GITEA_VM_HOST_FILE" ]; then + export GITEA_NPM_HOST + GITEA_NPM_HOST="$(cat "$_GITEA_VM_HOST_FILE")" + else + # Fallback: assume Gitea on localhost (e.g., local Docker or SSH tunnel) + export GITEA_NPM_HOST="localhost" + fi +fi +unset _GITEA_VM_HOST_FILE + +# Token: load from file if not already set _GITEA_TOKEN_FILE="$HOME/.gitea_npm_token" if [ -z "${GITEA_NPM_TOKEN:-}" ] && [ -f "$_GITEA_TOKEN_FILE" ]; then export GITEA_NPM_TOKEN