fix(ci): tolerate empty inline blogPosts array in scaffold script (#883)

The release blog scaffold's index.ts regex required a literal newline
before the closing bracket of the blogPosts array. A fresh website
repo bootstraps the array as an empty inline literal (= []), which
broke the script the first time it ran for v0.67.0.

The closing capture now matches whitespace-then-bracket so both empty
inline and multi-line shapes work, and the rebuild always emits a
clean newline-comma-newline-bracket regardless of input shape.

Verified via dry-run against the current website state.
This commit is contained in:
Anso
2026-05-02 15:57:07 -04:00
committed by GitHub
parent 577acc056b
commit 87abfc2ec0
+6 -4
View File
@@ -284,16 +284,18 @@ function updateIndex(websiteRoot, exportName, fileBase) {
lines.splice(lastImportIdx + 1, 0, importLine)
const joined = lines.join('\n')
const arrayRegex = /(export const blogPosts: BlogPost\[\] = \[)([\s\S]*?)(\n\])/
// The closing capture tolerates both multi-line (`,\n]`) and empty inline
// (`[]`) array shapes. Empty inline is the bootstrap state of a fresh
// sencho-website repo before any release post has been written.
const arrayRegex = /(export const blogPosts: BlogPost\[\] = \[)([\s\S]*?)(\s*\])/
const m = joined.match(arrayRegex)
if (!m) throw new Error('Could not locate blogPosts array in index.ts')
const before = joined.slice(0, m.index)
const arrOpen = m[1]
const arrBody = m[2]
const arrClose = m[3]
const after = joined.slice(m.index + m[0].length)
const newBody = `${arrBody.replace(/\s*$/u, '')}\n ${exportName},`
return `${before}${arrOpen}${newBody}${arrClose}${after}`
const trimmedBody = arrBody.replace(/\s*$/u, '')
return `${before}${arrOpen}${trimmedBody}\n ${exportName},\n]${after}`
}
function updateMeta(websiteRoot, slug, title, description, date) {