MCPcopy Create free account
hub / github.com/5e-bits/5e-database / uploadTablesFromFolder

Function uploadTablesFromFolder

scripts/dbRefresh.ts:122–153  ·  view source on GitHub ↗
(db: Db, jsonDbDir: string, collectionPrefix = '')

Source from the content-addressed store, hash-verified

120}
121
122const 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
155function _processLangDir(lang: string, langDir: string, enDir: string): TranslationDocument[] {
156 const docs: TranslationDocument[] = [];

Callers 1

mainFunction · 0.85

Calls 2

_processFileForRefreshFunction · 0.85
_refreshIndexCollectionFunction · 0.85

Tested by

no test coverage detected