"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const promise_1 = __importDefault(require("../utils/promise")); const timing_1 = __importDefault(require("../utils/timing")); const book_1 = __importDefault(require("../models/book")); const parseIgnore_1 = __importDefault(require("./parseIgnore")); const parseConfig_1 = __importDefault(require("./parseConfig")); const parseGlossary_1 = __importDefault(require("./parseGlossary")); const parseSummary_1 = __importDefault(require("./parseSummary")); const parseReadme_1 = __importDefault(require("./parseReadme")); const parseLanguages_1 = __importDefault(require("./parseLanguages")); /** Parse content of a book @param {Book} book @return {Promise} */ function parseBookContent(book) { return (0, promise_1.default)(book).then(parseReadme_1.default).then(parseSummary_1.default).then(parseGlossary_1.default); } /** Parse a multilingual book @param {Book} book @return {Promise} */ function parseMultilingualBook(book) { const languages = book.getLanguages(); const langList = languages.getList(); return promise_1.default.reduce(langList, (currentBook, lang) => { const langID = lang.getID(); const child = book_1.default.createFromParent(currentBook, langID); let ignore = currentBook.getIgnore(); return (0, promise_1.default)(child) .then(parseConfig_1.default) .then(parseBookContent) .then((result) => { // Ignore content of this book when generating parent book ignore = ignore.add(`${langID}/**`); currentBook = currentBook.set("ignore", ignore); return currentBook.addLanguageBook(langID, result); }); }, book); } /** Parse a whole book from a filesystem @param {Book} book @return {Promise} */ function parseBook(book) { return timing_1.default.measure("parse.book", (0, promise_1.default)(book) .then(parseIgnore_1.default) .then(parseConfig_1.default) .then(parseLanguages_1.default) .then((resultBook) => { if (resultBook.isMultilingual()) { return parseMultilingualBook(resultBook); } else { return parseBookContent(resultBook); } })); } exports.default = parseBook;