Skip to content

Commit 9222c42

Browse files
committed
Added import notes with errors command
1 parent 1903ad8 commit 9222c42

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getImportedNotesErrors, getImportedNotesStatus, importNotes } from './src/notes_importer.js'
1+
import { getImportedWithErrorsNotes, getImportedNotesStatus, importNotes } from './src/notes_importer.js'
22
import { cleanDb } from './src/db.js'
33

44
await main()
@@ -14,6 +14,9 @@ async function main() {
1414
case '--import':
1515
await importNotes(args[1])
1616
return
17+
case '--import-with-errors':
18+
await importNotes(args[1], true)
19+
return
1720
case '--status':
1821
await printStatus(args[1])
1922
return
@@ -43,7 +46,7 @@ async function printStatus(notesDir) {
4346
}
4447

4548
async function showErrors() {
46-
(await getImportedNotesErrors()).forEach((noteStatus, index) => {
49+
(await getImportedWithErrorsNotes()).forEach((noteStatus, index) => {
4750
console.log(`${index + 1}. "${noteStatus.filePath}":`)
4851
console.log(`${noteStatus.error?.message || noteStatus.error}\n`)
4952
})

src/notes_importer.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,18 @@ import { addImportStatus, loadImportStatuses } from './db.js'
66

77
const importedNotes = {}
88

9-
export async function importNotes(notesDir) {
9+
export async function importNotes(notesDir, onlyWithErrors = false) {
1010
const importedNoteList = await loadImportStatuses()
1111
importedNoteList.forEach(noteInfo => importedNotes[noteInfo.filePath] = noteInfo)
1212
console.info(`\nLoaded already imported ${importedNoteList.length} notes`)
1313

1414
// noinspection JSValidateTypes
15-
const { files } = getNotesFiles(notesDir)
15+
let files
16+
if (onlyWithErrors) {
17+
files = importedNoteList.filter(it => it.error).map(it => it.filePath)
18+
} else {
19+
files = getNotesFiles(notesDir).files
20+
}
1621

1722
let fileIndex = 0
1823
for (const relFilePath of files) {
@@ -111,6 +116,6 @@ export async function getImportedNotesStatus(notesDir) {
111116
}
112117
}
113118

114-
export async function getImportedNotesErrors() {
119+
export async function getImportedWithErrorsNotes() {
115120
return (await loadImportStatuses()).filter(it => it.error)
116121
}

0 commit comments

Comments
 (0)