Skip to content

Commit 1f5dd3e

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 1f5dd3e

2 files changed

Lines changed: 23 additions & 14 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: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,17 @@ export async function uploadSocialPreviewViaBrowser(
132132
// Look for and click save button
133133
const buttons = await page.$$('button[type="submit"], button')
134134
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
135+
try {
136+
const text = await button.evaluate(
137+
el => el.textContent?.toLowerCase() || ''
138+
)
139+
if (text.includes('save') || text.includes('update')) {
140+
await button.click()
141+
await delay(2000)
142+
break
143+
}
144+
} catch {
145+
// Skip buttons that aren't clickable
142146
}
143147
}
144148

@@ -256,13 +260,17 @@ export async function uploadAllViaBrowser(
256260
// Look for and click save button
257261
const buttons = await page.$$('button[type="submit"], button')
258262
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
263+
try {
264+
const text = await button.evaluate(
265+
el => el.textContent?.toLowerCase() || ''
266+
)
267+
if (text.includes('save') || text.includes('update')) {
268+
await button.click()
269+
await delay(2000)
270+
break
271+
}
272+
} catch {
273+
// Skip buttons that aren't clickable
266274
}
267275
}
268276

0 commit comments

Comments
 (0)