@@ -12,8 +12,7 @@ export async function importNotes(notesDir) {
12
12
console . info ( `\nLoaded already imported ${ importedNoteList . length } notes` )
13
13
14
14
// noinspection JSValidateTypes
15
- const files = readdirSync ( notesDir , { recursive : true } )
16
- . filter ( it => lstatSync ( `${ notesDir } /${ it } ` ) . isFile ( ) )
15
+ const files = getNotesFiles ( notesDir )
17
16
18
17
let fileIndex = 0
19
18
for ( const relFilePath of files ) {
@@ -41,7 +40,7 @@ export async function importNotes(notesDir) {
41
40
await saveNoteToNotion ( noteInfo )
42
41
}
43
42
44
- console . info ( '\nDONE' )
43
+ console . info ( '\nDONE. ' )
45
44
}
46
45
47
46
async function createParentNotes ( relFilePath ) {
@@ -63,6 +62,12 @@ async function createParentNotes(relFilePath) {
63
62
return parentId
64
63
}
65
64
65
+ function getNotesFiles ( notesDir ) {
66
+ // noinspection JSValidateTypes
67
+ return readdirSync ( notesDir , { recursive : true } )
68
+ . filter ( it => lstatSync ( `${ notesDir } /${ it } ` ) . isFile ( ) )
69
+ }
70
+
66
71
async function saveNoteToNotion ( noteInfo ) {
67
72
if ( importedNotes . hasOwnProperty ( noteInfo . filePath ) ) {
68
73
console . info ( ` - Note "${ noteInfo . filePath } " already exists` )
@@ -88,3 +93,19 @@ async function saveNoteToNotion(noteInfo) {
88
93
await addImportStatus ( noteInfo )
89
94
return noteInfo
90
95
}
96
+
97
+ export async function getImportNotesStatus ( notesDir ) {
98
+ const notesCount = getNotesFiles ( notesDir ) . length
99
+ const importedNotes = await loadImportStatuses ( )
100
+ const importedCount = importedNotes . length
101
+ const importedWithErrorsCount = importedNotes . filter ( it => ! it . imported ) . length
102
+ const importedWithoutErrorsCount = importedCount - importedWithErrorsCount
103
+
104
+ return {
105
+ notesCount : notesCount ,
106
+ importedCount,
107
+ importedWithErrorsCount,
108
+ importedWithoutErrorsCount,
109
+ progress : Math . round ( importedCount / notesCount * 100 )
110
+ }
111
+ }
0 commit comments