Skip to content

Commit 20d3731

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 20d3731

2 files changed

Lines changed: 31 additions & 19 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: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,11 @@ 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"]')) {
94-
;(el as HTMLElement).click()
93+
if (
94+
el.textContent?.includes('Edit') &&
95+
el.closest('[class*="social"]')
96+
) {
97+
(el as HTMLElement).click()
9598
return true
9699
}
97100
}
@@ -102,7 +105,7 @@ export async function uploadSocialPreviewViaBrowser(
102105
const parent = label.closest('div')
103106
const btn = parent?.querySelector('summary, button')
104107
if (btn) {
105-
;(btn as HTMLElement).click()
108+
(btn as HTMLElement).click()
106109
return true
107110
}
108111
}
@@ -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

@@ -215,7 +222,7 @@ export async function uploadAllViaBrowser(
215222
el.textContent?.includes('Edit') &&
216223
el.closest('[class*="social"]')
217224
) {
218-
;(el as HTMLElement).click()
225+
(el as HTMLElement).click()
219226
return true
220227
}
221228
}
@@ -226,7 +233,7 @@ export async function uploadAllViaBrowser(
226233
const parent = label.closest('div')
227234
const btn = parent?.querySelector('summary, button')
228235
if (btn) {
229-
;(btn as HTMLElement).click()
236+
(btn as HTMLElement).click()
230237
return true
231238
}
232239
}
@@ -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)