83544a9ea8
following up on https://discord.com/channels/859816885297741824/1162726738774720574/1211715924613275681 several things here: - `docs/api/.*json` were out-of-date — seems like fetch-api-source should run automatically? shouldn't `build-api` also override this directory? in particular, tldraw.api.json still had a ton of references to the old @tldraw/tldraw package - the main problem was that `generateApiContent` was failing silently. we were relying on Promises and this broke silently because we never handled exceptions. i got rid of the Promise as it was unnecessary and made the exceptions bubble up - two things were broken in the docs and those are fixed, so now the missing entries will resurface ### Change Type - [x] `documentation` — Changes to the documentation only[^2] --------- Co-authored-by: Steve Ruiz <steveruizok@gmail.com>
73 lines
1.9 KiB
TypeScript
73 lines
1.9 KiB
TypeScript
import fs from 'fs'
|
|
import { Octokit } from 'octokit'
|
|
import path from 'path'
|
|
|
|
const octokit = new Octokit({
|
|
auth: process.env.ACCESS_TOKEN,
|
|
})
|
|
|
|
const { log: nicelog } = console
|
|
|
|
export async function fetchReleases() {
|
|
try {
|
|
const RELEASES_DIRECTORY = path.join(process.cwd(), 'content', 'releases')
|
|
|
|
if (fs.existsSync(RELEASES_DIRECTORY)) {
|
|
fs.rmSync(RELEASES_DIRECTORY, { recursive: true })
|
|
}
|
|
|
|
fs.mkdirSync(RELEASES_DIRECTORY)
|
|
|
|
const res = await octokit.rest.repos.listReleases({
|
|
owner: 'tldraw',
|
|
repo: 'tldraw',
|
|
})
|
|
|
|
if (res.status === 200) {
|
|
nicelog(`• Writing releases...`)
|
|
res.data
|
|
.filter((release) => !release.draft && release.tag_name.startsWith('v2.0.0'))
|
|
.forEach((release, i) => {
|
|
const date = (
|
|
release.published_at ? new Date(release.published_at) : new Date()
|
|
).toLocaleDateString('en-US', {
|
|
year: 'numeric',
|
|
month: 'numeric',
|
|
day: 'numeric',
|
|
})
|
|
|
|
let m = ''
|
|
|
|
m += `---\n`
|
|
m += `title: ${release.tag_name}\n`
|
|
m += `description: Examples\n`
|
|
m += `author: tldraw\n`
|
|
m += `date: ${date}\n`
|
|
m += `order: ${i}\n`
|
|
m += `status: published\n`
|
|
m += `---\n\n`
|
|
m += `[View on GitHub](${release.html_url})\n\n`
|
|
|
|
const body = (release.body ?? '')
|
|
.replaceAll(/### Release Notes\n/g, '')
|
|
.replaceAll(/\[([^\]]+)\]$/g, '$1')
|
|
.replace(/<image (.*)">/g, '<image $1" />')
|
|
.replace(/<([^>]+)\/?>(?=\s|$)/g, '`<$1>`')
|
|
.replace(/`<image(.*) \/>`/g, '<image$1 />')
|
|
.replace(/`<img(.*) \/>`/g, '<img$1 />')
|
|
.replace(/\/\/>/g, '/>')
|
|
|
|
m += body
|
|
|
|
const filePath = path.join(RELEASES_DIRECTORY, `${release.tag_name}.mdx`)
|
|
fs.writeFileSync(filePath, m)
|
|
})
|
|
} else {
|
|
throw Error(`x Could not get releases for tldraw.`)
|
|
}
|
|
} catch (error) {
|
|
nicelog(`x Could not generate release content.`)
|
|
|
|
throw error
|
|
}
|
|
}
|