tldraw/apps/docs/scripts/functions/fetchApiSource.ts
David Sheldrick 9f90fa230b
fix docs build (#3201)
- always refresh docs content when building on CI
- use local api.json files now since we don't want to use SOURCE_SHA
- @steveruizok it feels kinda problematic that we check in a bunch of
derived files that the docs build requires. Things can get out of sync
easily, and whose responsibility is it to update them? In the future I
reckon we should explore ways to remove these files from the git index
as much as possible.

closes #3200 

### Change Type

<!--  Please select a 'Scope' label ️ -->

- [ ] `sdk` — Changes the tldraw SDK
- [ ] `dotcom` — Changes the tldraw.com web app
- [x] `docs` — Changes to the documentation, examples, or templates.
- [ ] `vs code` — Changes to the vscode plugin
- [ ] `internal` — Does not affect user-facing stuff

<!--  Please select a 'Type' label ️ -->

- [x] `bugfix` — Bug fix
- [ ] `feature` — New feature
- [ ] `improvement` — Improving existing features
- [ ] `chore` — Updating dependencies, other boring stuff
- [ ] `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.
2.

- [ ] Unit Tests
- [ ] End to end tests

### Release Notes

- Add a brief release note for your PR here.
2024-03-18 15:59:29 +00:00

30 lines
820 B
TypeScript

import fs from 'fs'
import path from 'path'
import { TLDRAW_PACKAGES_TO_INCLUDE_IN_DOCS } from './package-list'
const { log: nicelog } = console
export async function fetchApiSource() {
try {
const API_DIRECTORY = path.join(process.cwd(), 'api')
const REPO_ROOT = path.normalize(path.join(process.cwd(), '../../'))
if (fs.existsSync(API_DIRECTORY)) {
fs.rmSync(API_DIRECTORY, { recursive: true })
}
fs.mkdirSync(API_DIRECTORY)
for (const folderName of TLDRAW_PACKAGES_TO_INCLUDE_IN_DOCS) {
const fromPath = path.join(REPO_ROOT, 'packages', folderName, 'api', 'api.json')
const toPath = path.join(API_DIRECTORY, folderName + '.api.json')
fs.copyFileSync(fromPath, toPath)
}
nicelog('✔ Complete!')
} catch (error) {
nicelog(`x Could not generate site content.`)
throw error
}
}