const fs = require('fs'); const mdHtml = new (require('showdown').Converter)(); const path = require('path'); const langsToBuild = process.argv[2] && process.argv[2].split(',').map((s) => s.trim()) || ['ru', 'en']; const targets = (process.argv[3] && process.argv[3].split(',') || ['html', 'pdf', 'epub'] ).reduce((targets, arg) => { targets[arg.trim()] = true; return targets; }, {}); const l10n = { en: { title: 'The API', author: 'Sergey Konstantinov', chapter: 'Chapter', toc: 'Table of Contents', frontPage: 'Front Page' }, ru: { title: 'API', author: 'Сергей Константинов', chapter: 'Глава', toc: 'Содержание', frontPage: 'Титульный лист' } }; const css = fs.readFileSync('src/style.css', 'utf-8'); const builders = require('./builders'); buildDocs(langsToBuild, targets, l10n).then(() => { console.log('Done!'); process.exit(0); }, (e) => { console.error(e); process.exit(255); }); function buildDocs (langsToBuild, targets, l10n) { console.log(`Building in following languages: ${ langsToBuild.join(', ') }, targets: ${ Object.keys(targets).join(', ') }`); return Promise.all( langsToBuild.map((lang) => buildDoc(lang, targets, l10n[lang])) ); } function buildDoc (lang, targets, l10n) { const structure = getStructure({ path: `./src/${lang}/clean-copy/`, l10n, pageBreak:'
' }); const htmlContent = [ structure.frontPage, ...structure.sections .map((section) => section.chapters.reduce((content, chapter) => { if (chapter.title) { content.push(`