4a3d9d407d
This PR replaces the extendable TLServer class with an instantiatable wrapper for the TLSyncRoom called TLSocketRoom. The goal is to provide an API where you pretty much just 1. create a room from some (optional) snapshot 2. pass websockets into it when they connect And then lifecycle stuff and persistence stuff is left to the consumer, since that all seems to be much more context dependent. One thing remaining here is to work on observability. We had a slightly messy situation regarding logging and error handling and analytics and I want to clean that all up. ### Change Type <!-- ❗ Please select a 'Scope' label ❗️ --> - [ ] `sdk` — Changes the tldraw SDK - [ ] `dotcom` — Changes the tldraw.com web app - [ ] `docs` — Changes to the documentation, examples, or templates. - [ ] `vs code` — Changes to the vscode plugin - [x] `internal` — Does not affect user-facing stuff <!-- ❗ Please select a 'Type' label ❗️ --> - [ ] `bugfix` — Bug fix - [ ] `feature` — New feature - [ ] `improvement` — Improving existing features - [ ] `chore` — Updating dependencies, other boring stuff - [x] `galaxy brain` — Architectural changes - [ ] `tests` — Changes to any test code - [ ] `tools` — Changes to infrastructure, CI, internal scripts, debugging tools, etc. - [ ] `dunno` — I don't know ### Test Plan 1. Add a step-by-step description of how to test your PR here. 4. - [ ] Unit Tests - [ ] End to end tests ### Release Notes - Add a brief release note for your PR here.
70 lines
2.1 KiB
TypeScript
70 lines
2.1 KiB
TypeScript
import { Octokit } from '@octokit/rest'
|
|
import { existsSync, readFileSync, writeFileSync } from 'fs'
|
|
import { join } from 'path'
|
|
import { REPO_ROOT } from './lib/file'
|
|
import { formatLabelOptionsForPRTemplate, getLabelNames } from './lib/labels'
|
|
|
|
const prTemplatePath = join(REPO_ROOT, '.github', 'pull_request_template.md')
|
|
|
|
const octo = process.env.GH_TOKEN ? new Octokit({ auth: process.env.GH_TOKEN }) : new Octokit()
|
|
|
|
async function updatePRTemplate(check: boolean) {
|
|
if (!existsSync(prTemplatePath)) {
|
|
console.error('❌ Could not find PR template at', prTemplatePath)
|
|
process.exit(1)
|
|
}
|
|
|
|
const prTemplate = readFileSync(prTemplatePath).toString()
|
|
const labelsPart = prTemplate.match(/(### Change Type(.|\s)*?\n)###/)?.[1]
|
|
if (!labelsPart) {
|
|
console.error(
|
|
'❌ Could not find the labels section of the pull request template! It should start with "### Change Type"'
|
|
)
|
|
process.exit(1)
|
|
}
|
|
const updated = prTemplate.replace(
|
|
labelsPart,
|
|
`### Change Type\n\n${formatLabelOptionsForPRTemplate()}\n\n`
|
|
)
|
|
if (check && updated !== prTemplate) {
|
|
console.error(
|
|
'❌ PR template labels section is out of date. Run `yarn update-pr-template` to fix it.'
|
|
)
|
|
console.error(
|
|
'💡 Were you trying to change the labels section manually? Update scripts/lib/labels.ts instead.'
|
|
)
|
|
process.exit(1)
|
|
}
|
|
|
|
// make sure all labels exist
|
|
const repoLabels = new Set(
|
|
(
|
|
await octo.issues.listLabelsForRepo({
|
|
owner: 'tldraw',
|
|
repo: 'tldraw',
|
|
per_page: 100,
|
|
})
|
|
).data.map((x) => x.name)
|
|
)
|
|
|
|
const missingLabels = getLabelNames().filter((x) => !repoLabels.has(x))
|
|
if (missingLabels.length > 0) {
|
|
console.error(
|
|
'❌ The following labels do not exist in the tldraw repo:',
|
|
missingLabels.map((l) => JSON.stringify(l)).join(', ')
|
|
)
|
|
console.error(
|
|
`Add them yourself or update scripts/lib/labels.ts and re-run \`yarn update-pr-template\` to remove them.`
|
|
)
|
|
process.exit(1)
|
|
}
|
|
|
|
if (!check) {
|
|
console.log('Writing template to', prTemplatePath)
|
|
writeFileSync(prTemplatePath, updated)
|
|
} else {
|
|
console.log('All good!')
|
|
}
|
|
}
|
|
|
|
updatePRTemplate(process.argv.includes('--check'))
|