tldraw/scripts/docs-gen.js
2021-06-27 14:53:06 +01:00

44 lines
1 KiB
JavaScript

// @ts-check
/*
This script will generate content for the code editor's markdown docs. To change
the docs, edit the file at `state/code/docs.md`.
*/
const fs = require('fs/promises')
const root = process.cwd()
async function inlineFileContents(path) {
console.log(`📄 Inlining contents of ${path}`)
const text = await fs.readFile(`${root}${path}`, 'utf-8')
return text.replaceAll('`', '\\`')
}
async function copyDocsToDocsContentFile() {
console.log('⚙️ Generating docs-content.ts')
const content =
`
/* eslint-disable */
// HEY! DO NOT MODIFY THIS FILE. THE CONTENTS OF THIS FILE
// ARE AUTO-GENERATED BY A SCRIPT AT: /scripts/docs-gen.js
// ANY CHANGES WILL BE LOST WHEN THE SCRIPT RUNS AGAIN!
export default {` +
`
name: "docs-content.ts",
content: \`
${await inlineFileContents('/state/code/docs.md')}
\`}`
await fs.writeFile(
__dirname + '/../components/code-panel/docs-content.ts',
content
)
console.log('✅ Process complete')
}
// Kickoff
copyDocsToDocsContentFile()