12345678set -e910BOLD="\033[1m"11DIM="\033[2m"12ACCENT="\033[38;5;208m"13GREEN="\033[32m"14RED="\033[31m"15RESET="\033[0m"1617header() {18 echo ""19 echo -e "${ACCENT}${BOLD}$1${RESET}"20 echo -e "${DIM}$2${RESET}"21 echo ""22}2324success() { echo -e "${GREEN}✓ $1${RESET}"; }25fail() { echo -e "${RED}✗ $1${RESET}"; exit 1; }2627clear28echo ""29echo -e "${ACCENT}${BOLD} ░░ peach chrome release setup ░░${RESET}"30echo ""31echo -e "${DIM}This sets up one-command Chrome Web Store publishing.${RESET}"32echo -e "${DIM}Run this once. After that: npm run release${RESET}"33echo ""34read -rp "Press Enter to begin…"35363738header "Step 1 / 4 — Checking dependencies" ""3940if ! command -v node &>/dev/null; then41 fail "Node.js not found."42fi43success "Node.js $(node --version)"444546echo "Installing chrome-webstore-upload-cli…"47npm install -D chrome-webstore-upload-cli 2>/dev/null || \48 npm install -g chrome-webstore-upload-cli49success "chrome-webstore-upload-cli ready"50515253header "Step 2 / 4 — Google OAuth setup" \54 "This is the only annoying part. Follow the steps carefully."5556echo -e "${BOLD}You need to:${RESET}"57echo " 1. Go to: ${ACCENT}https://console.cloud.google.com/apis/credentials${RESET}"58echo " 2. Create a new project called 'Peach CWS' (top-left dropdown → New Project)"59echo " 3. Enable the Chrome Web Store API:"60echo " ${ACCENT}https://console.cloud.google.com/apis/library/chromewebstore.googleapis.com${RESET}"61echo " 4. Go to Credentials → Create Credentials → OAuth 2.0 Client ID"62echo " 5. Application type: Desktop app"63echo " 6. Name: Peach Release"64echo " 7. Download the JSON — copy the client_id and client_secret"65echo ""66echo -e "${DIM}Once you have those, come back here.${RESET}"67echo ""68read -rp "Press Enter when you have your client_id and client_secret…"6970echo ""71echo -e "${BOLD}Paste your client_id:${RESET}"72read -r CWS_CLIENT_ID7374echo -e "${BOLD}Paste your client_secret (hidden):${RESET}"75read -rs CWS_CLIENT_SECRET76echo ""7778if [ -z "$CWS_CLIENT_ID" ] || [ -z "$CWS_CLIENT_SECRET" ]; then79 fail "Client ID and secret are required."80fi81828384header "Step 3 / 4 — Get refresh token" \85 "Open the URL below in your browser, authorize, then paste the code."8687AUTH_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"8889echo -e "${BOLD}Open this URL in your browser:${RESET}"90echo ""91echo -e " ${ACCENT}${AUTH_URL}${RESET}"92echo ""939495if command -v open &>/dev/null; then96 open "$AUTH_URL" 2>/dev/null || true97elif command -v xdg-open &>/dev/null; then98 xdg-open "$AUTH_URL" 2>/dev/null || true99fi100101echo -e "${DIM}(Browser may have opened automatically)${RESET}"102echo ""103echo -e "${BOLD}Paste the authorization code Google gives you:${RESET}"104read -r AUTH_CODE105106if [ -z "$AUTH_CODE" ]; then107 fail "Authorization code is required."108fi109110111echo ""112echo "Exchanging code for refresh token…"113114TOKEN_RESPONSE=$(curl -s -X POST https://oauth2.googleapis.com/token \115 -d "client_id=${CWS_CLIENT_ID}" \116 -d "client_secret=${CWS_CLIENT_SECRET}" \117 -d "code=${AUTH_CODE}" \118 -d "grant_type=authorization_code" \119 -d "redirect_uri=urn:ietf:wg:oauth:2.0:oob")120121CWS_REFRESH_TOKEN=$(echo "$TOKEN_RESPONSE" | grep -o '"refresh_token":"[^"]*"' | cut -d'"' -f4)122123if [ -z "$CWS_REFRESH_TOKEN" ]; then124 echo "Token response: $TOKEN_RESPONSE"125 fail "Failed to get refresh token. Check your client ID, secret, and auth code."126fi127128success "Got refresh token"129130131132header "Step 4 / 4 — Extension ID" \133 "Found in the Chrome Web Store Developer Dashboard."134135echo -e "${BOLD}Your Chrome extension ID${RESET}"136echo -e "${DIM}Go to: https://chrome.google.com/webstore/devconsole${RESET}"137echo -e "${DIM}Click your extension — the ID is in the URL or the item details.${RESET}"138echo -e "${DIM}Looks like: abcdefghijklmnopqrstuvwxyz123456${RESET}"139echo ""140echo -e "${BOLD}Paste your extension ID:${RESET}"141read -r CWS_EXTENSION_ID142143if [ -z "$CWS_EXTENSION_ID" ]; then144 fail "Extension ID is required."145fi146147148149SHELL_PROFILE="$HOME/.zshrc"150if [ -f "$HOME/.bashrc" ] && [ ! -f "$HOME/.zshrc" ]; then151 SHELL_PROFILE="$HOME/.bashrc"152fi153154echo "" >> "$SHELL_PROFILE"155echo "# Peach Chrome Web Store release credentials" >> "$SHELL_PROFILE"156echo "export CWS_CLIENT_ID=\"${CWS_CLIENT_ID}\"" >> "$SHELL_PROFILE"157echo "export CWS_CLIENT_SECRET=\"${CWS_CLIENT_SECRET}\"" >> "$SHELL_PROFILE"158echo "export CWS_REFRESH_TOKEN=\"${CWS_REFRESH_TOKEN}\"" >> "$SHELL_PROFILE"159echo "export CWS_EXTENSION_ID=\"${CWS_EXTENSION_ID}\"" >> "$SHELL_PROFILE"160161162unset CWS_CLIENT_SECRET163unset CWS_REFRESH_TOKEN164165success "Credentials saved to $SHELL_PROFILE"166167168169echo ""170echo -e "${ACCENT}${BOLD}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${RESET}"171echo -e "${ACCENT}${BOLD} Chrome release configured.${RESET}"172echo -e "${ACCENT}${BOLD}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${RESET}"173echo ""174echo "Reload your shell:"175echo ""176echo -e " ${ACCENT}source ${SHELL_PROFILE}${RESET}"177echo ""178echo "Then to release to both stores:"179echo ""180echo -e " ${ACCENT}npm run release${RESET}"181echo ""