Skip to content

Commit baa6e54

Browse files
committed
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.
1 parent bde3c5e commit baa6e54

2 files changed

Lines changed: 27 additions & 15 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
},
1111
"scripts": {
1212
"build": "tsc",
13+
"start": "powershell -Command \"node dist/index.js generate-all CodingWithCalvin --upload --token $(gh auth token)\"",
1314
"format:write": "npx prettier --write .",
1415
"format:check": "npx prettier --check .",
1516
"lint": "npx eslint src --ext .ts,.tsx",

src/browser.ts

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,10 @@ export async function uploadSocialPreviewViaBrowser(
9090
const editClicked = await page.evaluate(() => {
9191
const summaries = document.querySelectorAll('summary, button')
9292
for (const el of summaries) {
93-
if (el.textContent?.includes('Edit') && el.closest('[class*="social"]')) {
93+
if (
94+
el.textContent?.includes('Edit') &&
95+
el.closest('[class*="social"]')
96+
) {
9497
;(el as HTMLElement).click()
9598
return true
9699
}
@@ -132,13 +135,17 @@ export async function uploadSocialPreviewViaBrowser(
132135
// Look for and click save button
133136
const buttons = await page.$$('button[type="submit"], button')
134137
for (const button of buttons) {
135-
const text = await button.evaluate(
136-
el => el.textContent?.toLowerCase() || ''
137-
)
138-
if (text.includes('save') || text.includes('update')) {
139-
await button.click()
140-
await delay(2000)
141-
break
138+
try {
139+
const text = await button.evaluate(
140+
el => el.textContent?.toLowerCase() || ''
141+
)
142+
if (text.includes('save') || text.includes('update')) {
143+
await button.click()
144+
await delay(2000)
145+
break
146+
}
147+
} catch {
148+
// Skip buttons that aren't clickable
142149
}
143150
}
144151

@@ -256,13 +263,17 @@ export async function uploadAllViaBrowser(
256263
// Look for and click save button
257264
const buttons = await page.$$('button[type="submit"], button')
258265
for (const button of buttons) {
259-
const text = await button.evaluate(
260-
el => el.textContent?.toLowerCase() || ''
261-
)
262-
if (text.includes('save') || text.includes('update')) {
263-
await button.click()
264-
await delay(2000)
265-
break
266+
try {
267+
const text = await button.evaluate(
268+
el => el.textContent?.toLowerCase() || ''
269+
)
270+
if (text.includes('save') || text.includes('update')) {
271+
await button.click()
272+
await delay(2000)
273+
break
274+
}
275+
} catch {
276+
// Skip buttons that aren't clickable
266277
}
267278
}
268279

0 commit comments

Comments
 (0)