-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
52 lines (46 loc) · 1.38 KB
/
index.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
require('dotenv').load()
require('es6-promise').polyfill()
require('isomorphic-fetch')
const chalk = require('chalk')
const fs = require('fs')
const fetchChild = require('./src/fetchChild')
const fetchPage = require('./src/fetchPage')
const handleImg = require('./src/handleImg')
const handleStyle = require('./src/handleStyle')
const handleX = require('./src/handleX')
const insertCatalog = require('./src/insertCatalog')
require('figlet').text('Confluence2K', (e, data) => console.log(e || data))
const id = process.argv[2]
const name = process.argv[3]
fetchChild(id).then((tree) => {
tree.map(l => {
getPage(l.id, tree)
l.children.map(f => {
getPage(f.id, tree)
})
})
})
function getPage (child, tree) {
if (!fs.existsSync(`./build/${child}`)) {
fs.mkdirSync(`./build/${child}`)
}
fetchPage(child, (page) => {
this.title = page.title
this.page = page.body
fs.writeFile(`./build/${child}/_tmp.html`, this.page, (err) => {})
}).then(() => {
insertCatalog.call(this, tree, this.title, name)
handleX.call(this, child)
handleStyle.call(this, child)
}).then(() => {
new Promise((resolve) => {
handleImg.call(this, child)
resolve()
})
.catch(() => {})
}).then(() => {
fs.writeFile(`./build/${child}/index.html`, this.page, (err) => {
console.log(err || `${chalk.cyan(`- got ${child}!`)}`)
})
}).catch(() => {})
}