-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
64 lines (54 loc) · 1.31 KB
/
server.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
53
54
55
56
57
58
59
60
61
62
63
64
// Load Asciidoctor.js and the reveal.js converter
const asciidoctor = require('@asciidoctor/core')()
const asciidoctorRevealjs = require('@asciidoctor/reveal.js')
asciidoctorRevealjs.register()
const browserSync = require('browser-sync')
const bs = browserSync.create()
let adocFile = process.argv[2]
if (!adocFile) {
adocFile = 'index.adoc'
}
if (!adocFile.endsWith('.adoc')) {
console.error(
'You must specify an asciidoctor file to be previewed! Example:\n',
'node server.js README.adoc'
)
return
}
convertFile(adocFile)
/**
* Convert the document 'presentation.adoc'
* using the reveal.js converter
* @param {string} file
*/
function convertFile (file) {
console.log(`Convert file: '${file}'`)
asciidoctor.convertFile(file, { safe: 'unsafe', backend: 'revealjs' })
}
/**
* I'm watching you. 👀
* @param {string} filename
*/
function watchCallback (filename) {
// skip hidden files
if (filename.startsWith('.')) {
return
}
console.log(`File '${filename}' was changed`)
convertFile(adocFile)
if (adocFile !== filename && filename.endsWith('.adoc')) {
convertFile(filename)
}
bs.reload()
}
bs.watch(
'.',
{
ignored: ['**.html'],
ignoreInitial: true,
}
).on('change', watchCallback)
bs.init({
server: true,
startPath: adocFile.replace('.adoc', '.html')
})