forked from digabi/koe-ohje
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
50 lines (43 loc) · 1.03 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
const fs = require("fs-extra")
const { formatLatex, replaceInPath } = require("./common")
const contentPath = "./content/"
const buildPath = "./build/"
const indexHtml = "index.html"
const readFromPath = path => {
return fs
.readFile(contentPath + path)
.then(file => {
return formatLatex(file)
})
.then(output => {
return fs.writeFile(buildPath + path, output)
})
.then(() => {
console.log("Done with " + path)
})
}
const replaceTaulukkoWithBuild = file => {
return fs.readFile(file).then(data => {
var path = replaceInPath(data.toString())
return fs.writeFile(file, path, "utf8")
})
}
const getFilesFromDir = path => {
return fs.readdir(path)
}
const build = () => {
return fs
.ensureDir(buildPath)
.then(() => replaceTaulukkoWithBuild(indexHtml))
.then(() => getFilesFromDir(contentPath))
.then(files => {
return Promise.all(files.map(readFromPath))
})
}
build()
.then(() => {
console.log("Finished")
})
.catch(err => {
console.error(err)
})