(db: Db, jsonDbDir: string, collectionPrefix = '')
| 120 | } |
| 121 | |
| 122 | const uploadTablesFromFolder = async (db: Db, jsonDbDir: string, collectionPrefix = '') => { |
| 123 | const collectionIndexEntries: IndexEntry[] = []; |
| 124 | let files = []; |
| 125 | |
| 126 | try { |
| 127 | files = readdirSync(jsonDbDir); |
| 128 | } catch (e) { |
| 129 | console.error(e); |
| 130 | process.exit(1); |
| 131 | } |
| 132 | |
| 133 | if (files.length === 0) { |
| 134 | console.error(`no JSON data found in ${jsonDbDir}/`); |
| 135 | process.exit(1); |
| 136 | } |
| 137 | |
| 138 | for (const filename of files) { |
| 139 | if (!filename.includes(SRD_PREFIX) || !filename.endsWith('.json')) { |
| 140 | continue; |
| 141 | } |
| 142 | |
| 143 | const filepath = `${jsonDbDir}/${filename}`; |
| 144 | const indexName = await _processFileForRefresh(db, filepath, collectionPrefix); |
| 145 | if (indexName !== null) { |
| 146 | collectionIndexEntries.push({ index: indexName }); |
| 147 | } else { |
| 148 | console.warn(`Critical error processing ${filepath}, it will not be included in the index.`); |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | await _refreshIndexCollection(db, collectionPrefix, collectionIndexEntries); |
| 153 | }; |
| 154 | |
| 155 | function _processLangDir(lang: string, langDir: string, enDir: string): TranslationDocument[] { |
| 156 | const docs: TranslationDocument[] = []; |
no test coverage detected