-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
48 lines (40 loc) · 1.39 KB
/
Copy pathindex.js
File metadata and controls
48 lines (40 loc) · 1.39 KB
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
var path = require('path')
var fsPath = require('fs-path')
var Xvfb = require('xvfb')
var serve = require('./serve.js')
var render = require('./render.js')
var xvfb = new Xvfb()
function StaticSiteGenerator (outputPath, routes, elementToWaitFor) {
this.outputPath = outputPath
this.routes = routes
this.elementToWaitFor = elementToWaitFor || 'body'
}
StaticSiteGenerator.prototype.apply = function (compiler) {
var self = this
compiler.plugin('after-emit', function (compilation, done) {
if (process.platform === 'linux'){
xvfb.startSync()
}
var server = serve(self.outputPath)
var port = server.address().port
var outputFiles = render(port, self.routes, self.elementToWaitFor)
outputFiles.then(files => {
for (var i = 0; i < files.length; i++) {
var outputFilePath = path.join(self.outputPath, self.routes[i])
var outputFileName = path.join(outputFilePath, 'index.html')
fsPath.writeFile(outputFileName, files[i])
}
server.close(function () {
xvfb.stopSync()
done()
})
}).catch(err => {
setTimeout(function () {throw err})
server.close(function () {
xvfb.stopSync()
done()
})
})
})
}
module.exports = StaticSiteGenerator