2024-01-15 12:33:15 +00:00
|
|
|
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')
|
2024-03-18 15:59:29 +00:00
|
|
|
const REPO_ROOT = path.normalize(path.join(process.cwd(), '../../'))
|
2024-01-15 12:33:15 +00:00
|
|
|
|
|
|
|
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) {
|
2024-03-18 15:59:29 +00:00
|
|
|
const fromPath = path.join(REPO_ROOT, 'packages', folderName, 'api', 'api.json')
|
|
|
|
const toPath = path.join(API_DIRECTORY, folderName + '.api.json')
|
|
|
|
fs.copyFileSync(fromPath, toPath)
|
2024-01-15 12:33:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nicelog('✔ Complete!')
|
|
|
|
} catch (error) {
|
|
|
|
nicelog(`x Could not generate site content.`)
|
|
|
|
|
|
|
|
throw error
|
|
|
|
}
|
|
|
|
}
|