-
Notifications
You must be signed in to change notification settings - Fork 3
/
watch.js
43 lines (37 loc) · 860 Bytes
/
watch.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
var fs = require('fs')
var sane = require('sane')
var jade = require('jade')
var marked = require('marked')
var highlight = require('highlight.js')
marked.setOptions({
highlight: function (code) {
return highlight.highlightAuto(code).value
}
})
var dirs = [
'index',
'api',
'guide',
'faq',
]
var fns = dirs.map(function (dir) {
return function() {
var filename = process.cwd() + '/' + dir + '/index.jade'
var html = jade.render(fs.readFileSync(filename, 'utf8'), {
filename: filename
})
fs.writeFileSync(process.cwd() + '/' + dir + '.html', html)
}
})
fns.forEach(function (fn) {
fn()
})
sane(process.cwd(), ['*.jade'].concat(dirs.map(function (dir) {
return dir + '/*'
})))
.on('change', function (filepath) {
console.log('%s changed, rebuilding', filepath)
fns.forEach(function (fn) {
fn()
})
})