Tofu/scripts/import-recipes/cli/previewOdtFiles.js
2026-09-18 01:41:02 +02:00

20 lines
815 B
JavaScript

import { join } from 'node:path'
import { readOdtParagraphs } from '#import-recipes/odt/readOdtParagraphs.js'
// What --dry-run does: read every document and show what came out of it. No API
// call, nothing written - this is the cheap way to check that the .odt files are
// readable before spending anything.
export function previewOdtFiles({ sourceDir, fileNames }) {
const failures = []
for (const fileName of fileNames) {
const reading = readOdtParagraphs(join(sourceDir, fileName))
if (!reading.ok) {
failures.push({ fileName, reason: reading.reason })
console.log(`${fileName} - FAILED: ${reading.reason}`)
continue
}
const { paragraphs } = reading
console.log(`${fileName} - ${paragraphs.length} lines, starts with "${paragraphs[0]}"`)
}
return { failures }
}