|
1 |
| -import createSpinner from 'ora'; |
2 |
| -import DatabaseIndex from '../utilities/DatabaseIndex.js'; |
3 |
| -import readNDJSON from '../utilities/readNDJSON.js'; |
4 |
| -import { Transducer } from 'hfstol'; |
5 |
| -import writeNDJSON from '../utilities/writeNDJSON.js'; |
| 1 | +import createSpinner from 'ora'; |
| 2 | +import { createWriteStream } from 'fs'; |
| 3 | +import DatabaseIndex from '../utilities/DatabaseIndex.js'; |
| 4 | +import readNDJSON from '../utilities/readNDJSON.js'; |
| 5 | +import { Transducer } from 'hfstol'; |
| 6 | +import writeNDJSON from '../utilities/writeNDJSON.js'; |
6 | 7 |
|
7 | 8 | function getPos(str) {
|
8 | 9 | if (!str) return ``;
|
@@ -32,8 +33,11 @@ function updateEntry(dbEntry, mdEntry) {
|
32 | 33 | * Imports the MD entries into the ALTLab database.
|
33 | 34 | * @param {String} mdPath
|
34 | 35 | * @param {String} dbPath
|
| 36 | + * @param {String} [fstPath] |
| 37 | + * @param {Object} [options={}] |
| 38 | + * @param {String} [report] The path where you would like the report generated. |
35 | 39 | */
|
36 |
| -export default async function importMD(mdPath, dbPath, fstPath) { |
| 40 | +export default async function importMD(mdPath, dbPath, fstPath, { report } = {}) { |
37 | 41 |
|
38 | 42 | const readDatabaseSpinner = createSpinner(`Reading databases.`).start();
|
39 | 43 |
|
@@ -141,4 +145,20 @@ export default async function importMD(mdPath, dbPath, fstPath) {
|
141 | 145 | 'Entries without a match:': unmatched.length,
|
142 | 146 | });
|
143 | 147 |
|
| 148 | + if (report) { |
| 149 | + |
| 150 | + const reportSpinner = createSpinner(`Generating report of unmatched entries.`).start(); |
| 151 | + const writeStream = createWriteStream(report); |
| 152 | + |
| 153 | + writeStream.write(`head\tPOS\toriginal\t\n`); |
| 154 | + |
| 155 | + for (const { head, original, pos } of unmatched) { |
| 156 | + writeStream.write(`${ head.md }\t${ pos }\t${ original }`); |
| 157 | + } |
| 158 | + |
| 159 | + writeStream.end(); |
| 160 | + reportSpinner.succeed(); |
| 161 | + |
| 162 | + } |
| 163 | + |
144 | 164 | }
|
0 commit comments