openpencil/tools/generate/authoring-reference/src/artifacts.ts
Danila Poyarkov 1aa10a4fed
build(tools): group tools by role and gate them like the rest of the repo (#791)
Tools live under tools/<role>/<domain> (checks, generate, release, ci, dev), every tool is a workspace named @open-pencil/<domain>-tools, a shared tools/tsconfig.json backs the new check:tools gate that fixed 55 latent type errors, test:tools runs through bun --filter, the placement check is its own checks/test-homes package, and every tool resolves the repository through resolveWorkspaceRoot. Bun, Node, and mdast types live in a tools-root workspace so they never reach the app program.
2026-09-30 05:00:31 +04:00

33 lines
1.2 KiB
TypeScript

import { mkdir, readFile, writeFile } from 'node:fs/promises'
import { dirname, join } from 'node:path'
import { JSX_REFERENCE } from '@open-pencil/core/design-jsx'
const HEADER =
'<!-- Generated from Core design-jsx/reference and renderer metadata. Do not edit; run bun run generate:authoring-reference. -->\n\n'
export const AUTHORING_REFERENCE_ARTIFACTS = {
'skills/open-pencil/references/design-authoring.md': HEADER + JSX_REFERENCE,
'packages/docs/reference/design-authoring.md': HEADER + JSX_REFERENCE
}
export async function writeReferences(root: string): Promise<void> {
for (const [path, content] of Object.entries(AUTHORING_REFERENCE_ARTIFACTS)) {
const target = join(root, path)
await mkdir(dirname(target), { recursive: true })
await writeFile(target, content)
}
}
export async function staleReferences(root: string): Promise<string[]> {
const stale: string[] = []
for (const [path, expected] of Object.entries(AUTHORING_REFERENCE_ARTIFACTS)) {
const actual = await readFile(join(root, path), 'utf8').catch((error: unknown) => {
if (error instanceof Error && 'code' in error && error.code === 'ENOENT') return null
throw error
})
if (actual !== expected) stale.push(path)
}
return stale
}