From 8420c0975aaf70dbcea89509f249b8fbab4c3efd Mon Sep 17 00:00:00 2001 From: Chris Arter Date: Fri, 8 May 2026 11:51:32 -0400 Subject: [PATCH] feat(import): full conversion check in dry-run Wire preprocessMdx + markdownToLexical into the orchestrator so that every file is converted in dry-run mode. Reports errors=0 and persists caches. Also gitignores .import-cache/ directory. Co-Authored-By: Claude Sonnet 4.6 --- .gitignore | 5 ++++- scripts/import-from-astro.ts | 30 +++++++++++++++++++++++++++--- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index c012149..dde83d6 100644 --- a/.gitignore +++ b/.gitignore @@ -51,4 +51,7 @@ node_modules/ # OpenNext .open-next -.wrangler \ No newline at end of file +.wrangler + +# Import cache +.import-cache/ \ No newline at end of file diff --git a/scripts/import-from-astro.ts b/scripts/import-from-astro.ts index 7796269..7495c09 100644 --- a/scripts/import-from-astro.ts +++ b/scripts/import-from-astro.ts @@ -3,6 +3,10 @@ import { fileURLToPath } from 'node:url' import { discoverAll } from './import/discover' import { collectUniqueTags, upsertTags } from './import/tags' import { scanImageRefs } from './import/scan-image-refs' +import { preprocessMdx } from './import/preprocess-mdx' +import { markdownToLexical } from './import/markdown-to-lexical' +import { loadImageCache, persistImageCache } from './import/images' +import { loadOgCache, persistOgCache, fetchOg } from './import/og-fetch' const args = new Map( process.argv.slice(2).map((a) => { @@ -31,10 +35,30 @@ async function main() { } console.log(`[import] unique image refs: ${allRefs.size}`) - if (dryRun) { - console.log('[import] --dry-run: skipping all writes') - return + const imageCache = await loadImageCache() + const ogCache = await loadOgCache() + + const ctx = { + imageMap: new Map(Object.entries(imageCache)), + fetchOg: (url: string) => fetchOg(url, ogCache), + } + + let errors = 0 + for (const file of [...posts, ...projects, ...pages]) { + try { + const pre = file.isMdx ? preprocessMdx(file.body) : file.body + await markdownToLexical(pre, ctx) + } catch (err) { + errors += 1 + console.error(`[convert] ${file.filePath}: ${(err as Error).message}`) + } } + console.log(`[import] conversion check: ${errors} errors`) + await persistImageCache(imageCache) + await persistOgCache(ogCache) + + if (errors > 0) process.exit(1) + if (dryRun) return const { getPayload } = await import('payload') const { default: config } = await import('@/payload.config') -- 2.51.2