Skip to content

Commit 48a50c0

Browse files
ensure installation has taken place before starting
1 parent 1f753b3 commit 48a50c0

File tree

1 file changed

+34
-22
lines changed

1 file changed

+34
-22
lines changed

bin/serve.js

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,43 +6,55 @@ var portfinder = require('portfinder')
66
, open = require('opener')
77
, path = require('path')
88
, http = require('http')
9+
, fs = require('fs')
910

1011
var compile = require('./compile.js')
12+
, install = require('./install.js')
1113

1214
var dir = path.join(__dirname, '..', 'output')
1315

1416
function main(ready) {
15-
var server = ecstatic({root: dir})
16-
, compiling = false
17-
, timeout
18-
19-
watchr.watch({
20-
path: path.join(__dirname, '..')
21-
, listener: recompile
22-
, ignoreHiddenFiles: true
17+
fs.exists(dir, function(exists) {
18+
exists ? setup(null) : install(setup)
2319
})
2420

25-
compile(function(err) {
21+
function setup(err) {
2622
if(err) {
2723
return ready(err)
2824
}
2925

30-
ready(null, http.createServer(server))
31-
})
26+
var server = ecstatic({root: dir, defaultExt: true})
27+
, compiling = false
28+
, timeout
3229

33-
function recompile() {
34-
if(compiling) {
35-
return
36-
}
30+
watchr.watch({
31+
path: path.join(__dirname, '..')
32+
, listener: recompile
33+
, ignoreHiddenFiles: true
34+
})
3735

38-
clearTimeout(timeout)
36+
compile(function(err) {
37+
if(err) {
38+
return ready(err)
39+
}
3940

40-
timeout = setTimeout(function iter() {
41-
compiling = true
42-
compile(function() {
43-
compiling = false
44-
})
45-
}, 500)
41+
ready(null, http.createServer(server))
42+
})
43+
44+
function recompile() {
45+
if(compiling) {
46+
return
47+
}
48+
49+
clearTimeout(timeout)
50+
51+
timeout = setTimeout(function iter() {
52+
compiling = true
53+
compile(function() {
54+
compiling = false
55+
})
56+
}, 500)
57+
}
4658
}
4759
}
4860

0 commit comments

Comments
 (0)