-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
41 lines (33 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
const nodePandoc = require('node-pandoc')
const path = require('path')
const fs = require('fs')
const inboundFolder = path.join(__dirname, 'inbound')
const outboundFolder = path.join(__dirname, 'outbound')
CreateWorkingDirectory()
fs.readdir(inboundFolder, function (err, files) {
if (err) {
return console.log('Unable to scan directory: ' + err)
}
files.forEach(function (file) {
console.log(`Converting ${file}`)
convertFile(file)
})
})
function CreateWorkingDirectory () {
if (!fs.existsSync(inboundFolder)) {
fs.mkdirSync(inboundFolder)
}
if (!fs.existsSync(outboundFolder)) {
fs.mkdirSync(outboundFolder)
}
}
function convertFile (file) {
const filePath = path.join(inboundFolder, file)
const name = `${path.basename(file, '.docx')}_${new Date().getTime()}`
const args = `-f docx -t markdown -o ./outbound/${name}.md`
const callback = (err, result) => {
if (err) { console.error(err) }
return result
}
nodePandoc(filePath, args, callback)
}