58 lines
1.7 KiB
TypeScript
58 lines
1.7 KiB
TypeScript
import { readFile } from 'node:fs/promises'
|
|
import { fileURLToPath } from 'node:url'
|
|
import { join } from 'node:path'
|
|
import {
|
|
buildEquineDraft,
|
|
EQUINE_SOURCE_PATHS,
|
|
HEAD_VIEW_ID,
|
|
importEquineLegacy,
|
|
parseViewBox,
|
|
readEquineCuration,
|
|
readEquineSources,
|
|
type DraftResult,
|
|
type EquineLegacyInput,
|
|
type ImportResult,
|
|
} from '../src'
|
|
import type { LegacyCatalog } from '../src/legacy/catalog'
|
|
|
|
/** Tests run on the real legacy sources, never on copies. */
|
|
export const REPO_ROOT = fileURLToPath(new URL('../../../', import.meta.url))
|
|
|
|
export function loadInput(): Promise<EquineLegacyInput> {
|
|
return readEquineSources(REPO_ROOT)
|
|
}
|
|
|
|
export async function runImport(): Promise<ImportResult> {
|
|
return importEquineLegacy(await loadInput())
|
|
}
|
|
|
|
export async function loadCatalog(): Promise<LegacyCatalog> {
|
|
const text = await readFile(
|
|
join(REPO_ROOT, EQUINE_SOURCE_PATHS.catalog),
|
|
'utf8',
|
|
)
|
|
return JSON.parse(text) as LegacyCatalog
|
|
}
|
|
|
|
export async function legacyAnnoIds(path: string): Promise<string[]> {
|
|
const text = await readFile(join(REPO_ROOT, path), 'utf8')
|
|
const ids = [...text.matchAll(/data-anno-id="([^"]+)"/g)].map((m) => m[1]!)
|
|
return [...new Set(ids)]
|
|
}
|
|
|
|
/** Legacy import + committed curation files → the working draft. */
|
|
export async function runDraft(): Promise<{
|
|
result: ImportResult
|
|
draft: DraftResult
|
|
}> {
|
|
const input = await loadInput()
|
|
const result = importEquineLegacy(input)
|
|
const draft = buildEquineDraft({
|
|
importResult: result,
|
|
legacyMainSvgBytes: input.mainSvg.bytes,
|
|
headViewBox: parseViewBox(result.viewBoxes[HEAD_VIEW_ID] ?? null),
|
|
...(await readEquineCuration(REPO_ROOT)),
|
|
})
|
|
return { result, draft }
|
|
}
|