File tree Expand file tree Collapse file tree 1 file changed +34
-22
lines changed Expand file tree Collapse file tree 1 file changed +34
-22
lines changed Original file line number Diff line number Diff line change @@ -6,43 +6,55 @@ var portfinder = require('portfinder')
6
6
, open = require ( 'opener' )
7
7
, path = require ( 'path' )
8
8
, http = require ( 'http' )
9
+ , fs = require ( 'fs' )
9
10
10
11
var compile = require ( './compile.js' )
12
+ , install = require ( './install.js' )
11
13
12
14
var dir = path . join ( __dirname , '..' , 'output' )
13
15
14
16
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 )
23
19
} )
24
20
25
- compile ( function ( err ) {
21
+ function setup ( err ) {
26
22
if ( err ) {
27
23
return ready ( err )
28
24
}
29
25
30
- ready ( null , http . createServer ( server ) )
31
- } )
26
+ var server = ecstatic ( { root : dir , defaultExt : true } )
27
+ , compiling = false
28
+ , timeout
32
29
33
- function recompile ( ) {
34
- if ( compiling ) {
35
- return
36
- }
30
+ watchr . watch ( {
31
+ path : path . join ( __dirname , '..' )
32
+ , listener : recompile
33
+ , ignoreHiddenFiles : true
34
+ } )
37
35
38
- clearTimeout ( timeout )
36
+ compile ( function ( err ) {
37
+ if ( err ) {
38
+ return ready ( err )
39
+ }
39
40
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
+ }
46
58
}
47
59
}
48
60
You can’t perform that action at this time.
0 commit comments