groupDataFiles.forEach((chapterFileName) => { const chapterPath = path.join(pathToWordAlignmentData, chapterFileName); try { groupsObject[path.parse(chapterFileName).name] = fs.readJsonSync( chapterPath); } catch (e) { console.error(`Failed to read alignment data from ${chapterPath}. This will be fixed by #4884`, e); } });
files.forEach(file => { const parts = path.parse(file); if (parts.ext === '.txt') { const filePath = path.join(chapterPath, file); let text = fs.readFileSync(filePath).toString(); switch (parts.name) { case 'title': text = "\\toc1 " + text; break; case 'reference': text = "\\cd " + text; break; } if (text) { header += text + '\n'; } } });
export const isProjectMissingVerses = (projectDir, bookId, resourceDir) => { try { let languageId = 'en'; const resourcePath = Path.join(resourceDir, languageId, 'bibles', 'ult'); const versionPath = ResourceAPI.getLatestVersion(resourcePath) || resourcePath; const indexLocation = Path.join(versionPath, 'index.json'); const expectedVerses = fs.readJSONSync(indexLocation); const actualVersesObject = {}; const currentFolderChapters = fs.readdirSync(Path.join(projectDir, bookId)); let chapterLength = 0; for (let currentChapterFile of currentFolderChapters) { let currentChapter = Path.parse(currentChapterFile).name; if (!parseInt(currentChapter)) continue; chapterLength++; let verseLength = 0; try { let currentChapterObject = fs.readJSONSync( Path.join(projectDir, bookId, currentChapterFile) ); for (let verseIndex in currentChapterObject) { let verse = currentChapterObject[verseIndex]; if (verse && verseIndex > 0) verseLength++; } } catch (e) { console.warn(e); } actualVersesObject[currentChapter] = verseLength; } actualVersesObject.chapters = chapterLength; let currentExpectedVerese = expectedVerses[bookId]; return ( JSON.stringify(currentExpectedVerese) !== JSON.stringify(actualVersesObject) ); } catch (e) { console.warn( 'ult index file not found missing verse detection is invalid. Please delete ~/translationCore/resources folder' ); return false; } };
/** * add front matter for chapter * @param chapterPath * @param file * @param chapterData * @param bookData * @param chapterNumber */ function addChapterFrontMatter(chapterPath, file, chapterData, bookData, chapterNumber) { const parts = path.parse(file); if (parts.ext === '.txt') { if (!chapterData['front']) { chapterData['front'] = ''; bookData[parseInt(chapterNumber)] = chapterData; } const chunkPath = path.join(chapterPath, file); let text = fs.readFileSync(chunkPath).toString(); switch (parts.name) { case 'title': text = "\\cl " + text; break; case 'reference': text = "\\cd " + text; break; } if (text) { chapterData['front'] += text + '\n'; } } }
let groupDataFileName = fs.readdirSync(pathToWordAlignmentData).find(file => { // filter out .DS_Store //This will break if we change the wordAlignment tool naming //convention of chapter a like chapter_1.json... return path.parse(file).name === chapterNum; });