#!/usr/bin/env bash # ───────────────────────────────────────────────────────────────────────────── # Peach — Chrome Web Store Release Setup # Run this once to configure Chrome publishing. # After setup, use: npm run release # ───────────────────────────────────────────────────────────────────────────── set -e BOLD="\033[1m" DIM="\033[2m" ACCENT="\033[38;5;208m" GREEN="\033[32m" RED="\033[31m" RESET="\033[0m" header() { echo "" echo -e "${ACCENT}${BOLD}$1${RESET}" echo -e "${DIM}$2${RESET}" echo "" } success() { echo -e "${GREEN}✓ $1${RESET}"; } fail() { echo -e "${RED}✗ $1${RESET}"; exit 1; } clear echo "" echo -e "${ACCENT}${BOLD} ░░ peach chrome release setup ░░${RESET}" echo "" echo -e "${DIM}This sets up one-command Chrome Web Store publishing.${RESET}" echo -e "${DIM}Run this once. After that: npm run release${RESET}" echo "" read -rp "Press Enter to begin…" # ─── Step 1: Check dependencies ─────────────────────────────────────────────── header "Step 1 / 4 — Checking dependencies" "" if ! command -v node &>/dev/null; then fail "Node.js not found." fi success "Node.js $(node --version)" # Install chrome-webstore-upload-cli echo "Installing chrome-webstore-upload-cli…" npm install -D chrome-webstore-upload-cli 2>/dev/null || \ npm install -g chrome-webstore-upload-cli success "chrome-webstore-upload-cli ready" # ─── Step 2: OAuth setup ────────────────────────────────────────────────────── header "Step 2 / 4 — Google OAuth setup" \ "This is the only annoying part. Follow the steps carefully." echo -e "${BOLD}You need to:${RESET}" echo " 1. Go to: ${ACCENT}https://console.cloud.google.com/apis/credentials${RESET}" echo " 2. Create a new project called 'Peach CWS' (top-left dropdown → New Project)" echo " 3. Enable the Chrome Web Store API:" echo " ${ACCENT}https://console.cloud.google.com/apis/library/chromewebstore.googleapis.com${RESET}" echo " 4. Go to Credentials → Create Credentials → OAuth 2.0 Client ID" echo " 5. Application type: Desktop app" echo " 6. Name: Peach Release" echo " 7. Download the JSON — copy the client_id and client_secret" echo "" echo -e "${DIM}Once you have those, come back here.${RESET}" echo "" read -rp "Press Enter when you have your client_id and client_secret…" echo "" echo -e "${BOLD}Paste your client_id:${RESET}" read -r CWS_CLIENT_ID echo -e "${BOLD}Paste your client_secret (hidden):${RESET}" read -rs CWS_CLIENT_SECRET echo "" if [ -z "$CWS_CLIENT_ID" ] || [ -z "$CWS_CLIENT_SECRET" ]; then fail "Client ID and secret are required." fi # ─── Step 3: Get refresh token ──────────────────────────────────────────────── header "Step 3 / 4 — Get refresh token" \ "Open the URL below in your browser, authorize, then paste the code." AUTH_URL="https://accounts.google.com/o/oauth2/auth?client_id=${CWS_CLIENT_ID}&redirect_uri=urn:ietf:wg:oauth:2.0:oob&response_type=code&scope=https://www.googleapis.com/auth/chromewebstore" echo -e "${BOLD}Open this URL in your browser:${RESET}" echo "" echo -e " ${ACCENT}${AUTH_URL}${RESET}" echo "" # Try to open browser automatically if command -v open &>/dev/null; then open "$AUTH_URL" 2>/dev/null || true elif command -v xdg-open &>/dev/null; then xdg-open "$AUTH_URL" 2>/dev/null || true fi echo -e "${DIM}(Browser may have opened automatically)${RESET}" echo "" echo -e "${BOLD}Paste the authorization code Google gives you:${RESET}" read -r AUTH_CODE if [ -z "$AUTH_CODE" ]; then fail "Authorization code is required." fi # Exchange code for refresh token echo "" echo "Exchanging code for refresh token…" TOKEN_RESPONSE=$(curl -s -X POST https://oauth2.googleapis.com/token \ -d "client_id=${CWS_CLIENT_ID}" \ -d "client_secret=${CWS_CLIENT_SECRET}" \ -d "code=${AUTH_CODE}" \ -d "grant_type=authorization_code" \ -d "redirect_uri=urn:ietf:wg:oauth:2.0:oob") CWS_REFRESH_TOKEN=$(echo "$TOKEN_RESPONSE" | grep -o '"refresh_token":"[^"]*"' | cut -d'"' -f4) if [ -z "$CWS_REFRESH_TOKEN" ]; then echo "Token response: $TOKEN_RESPONSE" fail "Failed to get refresh token. Check your client ID, secret, and auth code." fi success "Got refresh token" # ─── Step 4: Extension ID ───────────────────────────────────────────────────── header "Step 4 / 4 — Extension ID" \ "Found in the Chrome Web Store Developer Dashboard." echo -e "${BOLD}Your Chrome extension ID${RESET}" echo -e "${DIM}Go to: https://chrome.google.com/webstore/devconsole${RESET}" echo -e "${DIM}Click your extension — the ID is in the URL or the item details.${RESET}" echo -e "${DIM}Looks like: abcdefghijklmnopqrstuvwxyz123456${RESET}" echo "" echo -e "${BOLD}Paste your extension ID:${RESET}" read -r CWS_EXTENSION_ID if [ -z "$CWS_EXTENSION_ID" ]; then fail "Extension ID is required." fi # ─── Write to shell profile ─────────────────────────────────────────────────── SHELL_PROFILE="$HOME/.zshrc" if [ -f "$HOME/.bashrc" ] && [ ! -f "$HOME/.zshrc" ]; then SHELL_PROFILE="$HOME/.bashrc" fi echo "" >> "$SHELL_PROFILE" echo "# Peach Chrome Web Store release credentials" >> "$SHELL_PROFILE" echo "export CWS_CLIENT_ID=\"${CWS_CLIENT_ID}\"" >> "$SHELL_PROFILE" echo "export CWS_CLIENT_SECRET=\"${CWS_CLIENT_SECRET}\"" >> "$SHELL_PROFILE" echo "export CWS_REFRESH_TOKEN=\"${CWS_REFRESH_TOKEN}\"" >> "$SHELL_PROFILE" echo "export CWS_EXTENSION_ID=\"${CWS_EXTENSION_ID}\"" >> "$SHELL_PROFILE" # Clear from memory unset CWS_CLIENT_SECRET unset CWS_REFRESH_TOKEN success "Credentials saved to $SHELL_PROFILE" # ─── Done ───────────────────────────────────────────────────────────────────── echo "" echo -e "${ACCENT}${BOLD}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${RESET}" echo -e "${ACCENT}${BOLD} Chrome release configured.${RESET}" echo -e "${ACCENT}${BOLD}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${RESET}" echo "" echo "Reload your shell:" echo "" echo -e " ${ACCENT}source ${SHELL_PROFILE}${RESET}" echo "" echo "Then to release to both stores:" echo "" echo -e " ${ACCENT}npm run release${RESET}" echo ""