Skip to content

Commit

Permalink
Break out convertConfig into modular functions for SAB / DAB (#719)
Browse files Browse the repository at this point in the history
* Initial setup and comments made for collaboration

Wrapped almost all parsing functions

Wrapped parseBookCollections, removed some usages
of global variable 'data' (to be continued)

Continued converting functions.
Stopped at parsedLayouts

Completed calls for parsing functions

Added conditional logic for data type

Finished breaking out functions, applied feedback,
Added conditional logic for calls

Fixed typing issues with convertBooks

Fixed wrapping issue for layouts and book
collections

Resolved data type issues in convertConfig

Resolved issues in convertBooks, Plans, Contents

* Resolved issues with json config file

* Fixed various issues in config

* Fixed plan parsing when plans is empty

* Fixed lint failure
  • Loading branch information
EthanFennell authored Nov 14, 2024
1 parent 383bfac commit 7db575c
Show file tree
Hide file tree
Showing 4 changed files with 474 additions and 269 deletions.
25 changes: 14 additions & 11 deletions convert/convertBooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ function transformCatalogEntry(entry: any, quizzes: any, htmlBooks: any): any {

type ConvertBookContext = {
dataDir: string;
configData: ScriptureConfig;
scriptureConfig: ScriptureConfig;
verbose: number;
lang: string;
docSet: string;
Expand All @@ -202,11 +202,11 @@ type ConvertBookContext = {
const unsupportedBookTypes = ['story', 'songs', 'audio-only', 'bloom-player', 'quiz', 'undefined'];
export async function convertBooks(
dataDir: string,
configData: ConfigTaskOutput,
scriptureConfig: ScriptureConfig,
verbose: number
): Promise<BooksTaskOutput> {
/**book collections from config*/
const collections = configData.data.bookCollections;
const collections = scriptureConfig.bookCollections;
/**map of docSets and frozen archives*/
const freezer = new Map<string, any>();
/**array of catalog query promises*/
Expand Down Expand Up @@ -237,7 +237,7 @@ export async function convertBooks(
const pk = new SABProskomma();
const context: ConvertBookContext = {
dataDir,
configData: configData.data,
scriptureConfig,
verbose,
lang: collection.languageCode,
docSet: collection.languageCode + '_' + collection.id,
Expand All @@ -263,7 +263,7 @@ export async function convertBooks(
//loop through books in collection
const ignoredBooks = [];
// If the collection has a glossary, load it
if (configData.data.traits['has-glossary']) {
if (scriptureConfig.traits['has-glossary']) {
bcGlossary = loadGlossary(collection, dataDir);
}
//add empty array of quizzes for book collection
Expand Down Expand Up @@ -577,10 +577,10 @@ function convertScriptureBook(
//process.stdout.write(`processBookContent: bookId:${book.id}, error:${err}\n`);
if (err) throw err;
content = applyFilters(content, usfmFilterFunctions, context.bcId, book.id);
if (context.configData.traits['has-glossary']) {
if (context.scriptureConfig.traits['has-glossary']) {
content = verifyGlossaryEntries(content, bcGlossary);
}
if (context.configData.mainFeatures['hide-empty-verses'] === true) {
if (context.scriptureConfig.mainFeatures['hide-empty-verses'] === true) {
content = removeMissingVerses(content, context.bcId, book.id);
}
//query Proskomma with a mutation to add a document
Expand Down Expand Up @@ -683,7 +683,9 @@ export interface BooksTaskOutput extends TaskOutput {
*/
export class ConvertBooks extends Task {
public triggerFiles: string[] = ['books', 'quiz', 'songs', 'appdef.xml'];
public static lastBookCollections: ConfigTaskOutput['data']['bookCollections'];

public static lastBookCollections: ScriptureConfig['bookCollections'];

constructor(dataDir: string) {
super(dataDir);
}
Expand All @@ -693,12 +695,13 @@ export class ConvertBooks extends Task {
modifiedPaths: string[]
): Promisable<BooksTaskOutput> {
const config = outputs.get('ConvertConfig') as ConfigTaskOutput;
const scriptureConfig = config.data as ScriptureConfig;
// runs step only if necessary, as the step is fairly expensive
if (
!modifiedPaths.some((p) => p.startsWith('books')) &&
deepCompareObjects(
ConvertBooks.lastBookCollections,
config.data.bookCollections,
scriptureConfig.bookCollections,
new Set(['id', 'books', 'languageCode'])
)
) {
Expand All @@ -708,8 +711,8 @@ export class ConvertBooks extends Task {
};
}

const ret = convertBooks(this.dataDir, config, verbose);
ConvertBooks.lastBookCollections = config.data.bookCollections;
const ret = convertBooks(this.dataDir, scriptureConfig, verbose);
ConvertBooks.lastBookCollections = scriptureConfig.bookCollections;
return ret;
}
}
Expand Down
Loading

0 comments on commit 7db575c

Please sign in to comment.