From 4a341cb427b25334a85af6cbe3161bc5f6c792f6 Mon Sep 17 00:00:00 2001 From: "Calvin A. Allen" Date: Fri, 9 Jan 2026 15:35:41 -0500 Subject: [PATCH] feat(cli): add start script and fix browser upload errors Add npm start script that generates and uploads social previews for all CodingWithCalvin repos using gh CLI for authentication. Also suppress spurious error messages when iterating through non-clickable buttons during browser upload. --- .eslintrc.json | 1 + package.json | 1 + src/browser.ts | 41 ++++++++++++++++++++++++++--------------- 3 files changed, 28 insertions(+), 15 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 135a2c5..04d4583 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -29,6 +29,7 @@ "plugin:jest/recommended" ], "rules": { + "no-extra-semi": "off", "camelcase": "off", "no-console": "off", "no-unused-vars": "off", diff --git a/package.json b/package.json index 62d49e4..218fc42 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ }, "scripts": { "build": "tsc", + "start": "powershell -Command \"node dist/index.js generate-all CodingWithCalvin --upload --token $(gh auth token)\"", "format:write": "npx prettier --write .", "format:check": "npx prettier --check .", "lint": "npx eslint src --ext .ts,.tsx", diff --git a/src/browser.ts b/src/browser.ts index 3c584bb..44adae9 100644 --- a/src/browser.ts +++ b/src/browser.ts @@ -90,7 +90,10 @@ export async function uploadSocialPreviewViaBrowser( const editClicked = await page.evaluate(() => { const summaries = document.querySelectorAll('summary, button') for (const el of summaries) { - if (el.textContent?.includes('Edit') && el.closest('[class*="social"]')) { + if ( + el.textContent?.includes('Edit') && + el.closest('[class*="social"]') + ) { ;(el as HTMLElement).click() return true } @@ -132,13 +135,17 @@ export async function uploadSocialPreviewViaBrowser( // Look for and click save button const buttons = await page.$$('button[type="submit"], button') for (const button of buttons) { - const text = await button.evaluate( - el => el.textContent?.toLowerCase() || '' - ) - if (text.includes('save') || text.includes('update')) { - await button.click() - await delay(2000) - break + try { + const text = await button.evaluate( + el => el.textContent?.toLowerCase() || '' + ) + if (text.includes('save') || text.includes('update')) { + await button.click() + await delay(2000) + break + } + } catch { + // Skip buttons that aren't clickable } } @@ -256,13 +263,17 @@ export async function uploadAllViaBrowser( // Look for and click save button const buttons = await page.$$('button[type="submit"], button') for (const button of buttons) { - const text = await button.evaluate( - el => el.textContent?.toLowerCase() || '' - ) - if (text.includes('save') || text.includes('update')) { - await button.click() - await delay(2000) - break + try { + const text = await button.evaluate( + el => el.textContent?.toLowerCase() || '' + ) + if (text.includes('save') || text.includes('update')) { + await button.click() + await delay(2000) + break + } + } catch { + // Skip buttons that aren't clickable } }