Phase 3 expand machine catalogs
This commit is contained in:
+44
-9
@@ -1,5 +1,5 @@
|
||||
import AdmZip from 'adm-zip'
|
||||
import { mkdir, readFile, rm, writeFile } from 'node:fs/promises'
|
||||
import { mkdir, readFile, rm, stat, writeFile } from 'node:fs/promises'
|
||||
import path from 'node:path'
|
||||
import {
|
||||
cleanUsfmText,
|
||||
@@ -110,50 +110,85 @@ await writeFile(
|
||||
'utf8',
|
||||
)
|
||||
|
||||
const versesPackage = await packageFile(outputDir, 'verses.jsonl')
|
||||
const strongsPackage = await packageFile(outputDir, 'strongs-links.jsonl')
|
||||
|
||||
const catalog = {
|
||||
schema_version: 'librebible.resource-catalog.v1',
|
||||
project: manifest.project_name ?? 'LibreBible',
|
||||
id: manifest.id,
|
||||
resource_type: manifest.resource_type,
|
||||
title: manifest.title,
|
||||
short_title: manifest.short_title,
|
||||
abbreviation: manifest.abbreviation,
|
||||
alternate_ids: manifest.alternate_ids ?? [],
|
||||
language: manifest.language,
|
||||
script: manifest.script,
|
||||
canon: manifest.canon,
|
||||
translation: manifest.translation,
|
||||
contributors: manifest.contributors ?? [],
|
||||
features: manifest.features,
|
||||
attachments: manifest.attachments,
|
||||
source: manifest.source,
|
||||
license: manifest.license,
|
||||
catalog_display: manifest.catalog_display,
|
||||
importer: manifest.importer,
|
||||
generated_at: new Date().toISOString(),
|
||||
source_sha256: archiveSha,
|
||||
checks: manifest.checks,
|
||||
counts: {
|
||||
books: new Set(verses.map((verse) => verse.book_id)).size,
|
||||
verses: verses.length,
|
||||
strongs_links: strongsLinks.length,
|
||||
},
|
||||
files: {
|
||||
verses_jsonl: {
|
||||
path: 'verses.jsonl',
|
||||
sha256: await sha256File(path.join(outputDir, 'verses.jsonl')),
|
||||
},
|
||||
strongs_jsonl: {
|
||||
path: 'strongs-links.jsonl',
|
||||
sha256: await sha256File(path.join(outputDir, 'strongs-links.jsonl')),
|
||||
},
|
||||
verses_jsonl: versesPackage,
|
||||
strongs_jsonl: strongsPackage,
|
||||
},
|
||||
}
|
||||
|
||||
await writeJson(path.join(outputDir, 'catalog.json'), catalog)
|
||||
await writeJson(path.join(root, 'packages', 'json', 'catalog.json'), {
|
||||
schema_version: 'librebible.index-catalog.v1',
|
||||
project: manifest.project_name ?? 'LibreBible',
|
||||
generated_at: catalog.generated_at,
|
||||
resources: [
|
||||
{
|
||||
id: catalog.id,
|
||||
resource_type: catalog.resource_type,
|
||||
title: catalog.title,
|
||||
short_title: catalog.short_title,
|
||||
abbreviation: catalog.abbreviation,
|
||||
alternate_ids: catalog.alternate_ids,
|
||||
language: catalog.language,
|
||||
script: catalog.script,
|
||||
canon: catalog.canon,
|
||||
translation: catalog.translation,
|
||||
contributors: catalog.contributors,
|
||||
features: catalog.features,
|
||||
attachments: catalog.attachments,
|
||||
source: catalog.source,
|
||||
license: catalog.license,
|
||||
catalog_display: catalog.catalog_display,
|
||||
package_path: `packages/json/${catalog.id}/catalog.json`,
|
||||
source_manifest_path: `sources/${path.basename(manifestPath)}`,
|
||||
detail_doc_path: `docs/resources/${catalog.id}.md`,
|
||||
counts: catalog.counts,
|
||||
files: catalog.files,
|
||||
checks: catalog.checks,
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
console.log(`${manifest.id}: imported ${catalog.counts.verses} verses`)
|
||||
console.log(`${manifest.id}: imported ${catalog.counts.strongs_links} Strong's links`)
|
||||
|
||||
async function packageFile(outputDir, fileName) {
|
||||
const filePath = path.join(outputDir, fileName)
|
||||
const fileStat = await stat(filePath)
|
||||
return {
|
||||
path: fileName,
|
||||
bytes: fileStat.size,
|
||||
sha256: await sha256File(filePath),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user