-
Notifications
You must be signed in to change notification settings - Fork 24
/
generateCheatSheets.js
38 lines (31 loc) · 1.27 KB
/
generateCheatSheets.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const fs = require('fs')
const path = require('path')
const generateHTMLCheatSheet = require('./generateHTMLCheatSheet')
const generatePdfCheatSheet = require('./generatePdfCheatSheet')
const getSectionFileContent = (pageName, sectionObject) => {
const contentPath = `./data/${pageName}/sections/${sectionObject.name}.txt`
const content = fs.readFileSync(path.resolve(__dirname, contentPath), 'utf8')
return content
}
const addSectionFileContentToSections = cheatSheetData => {
const sections = cheatSheetData.sections.map(sectionObject => {
const content = getSectionFileContent(cheatSheetData.file, sectionObject)
return {
...sectionObject,
content,
}
})
return { ...cheatSheetData, sections }
}
const getCompleteCheatSheetData = pageName => {
const cheatSheetData = require(`./data/${pageName}/${pageName}`)
const completeCheatSheetData = addSectionFileContentToSections(cheatSheetData)
return completeCheatSheetData
}
const generatePage = pageName => {
const cheatSheetData = getCompleteCheatSheetData(pageName)
generateHTMLCheatSheet(cheatSheetData)
generatePdfCheatSheet(cheatSheetData)
}
const cheatSheetPages = ['react', 'react-router', 'es6', 'redux'];
cheatSheetPages.forEach(generatePage)