@@ -15,15 +15,39 @@ var gulp = require('gulp'),
15
15
distPath = './lib/dist' ,
16
16
fs = require ( 'fs' ) ,
17
17
chalk = require ( 'chalk' ) ,
18
+ extend = require ( 'node.extend' ) ,
18
19
configPath = util . env . config ? util . env . config . replace ( / \/ $ / , '' ) : null ,
19
20
outputPath = util . env . output ? util . env . output . replace ( / \/ $ / , '' ) : '' ,
20
21
sourcePath = util . env . source ? util . env . source . replace ( / \/ $ / , '' ) : '' ,
21
- config = configPath ? require ( configPath ) : { } ,
22
- socketIo = false ;
22
+ options = { } ;
23
+
24
+ function parseOptions ( ) {
25
+ var config = configPath ? require ( configPath ) : { } ;
26
+ // Resolve overviewPath in relation to config file location
27
+ if ( config . overviewPath ) {
28
+ config . overviewPath = path . resolve ( path . dirname ( configPath ) , config . overviewPath ) ;
29
+ }
30
+ if ( config . sassVariables ) {
31
+ config . sassVariables = path . resolve ( path . dirname ( configPath ) , config . sassVariables ) ;
32
+ }
33
+ options = extend ( {
34
+ sass : {
35
+ loadPath : neat . includePaths
36
+ } ,
37
+ socketIo : false
38
+ } , config ) ;
39
+ }
40
+
41
+ parseOptions ( ) ;
23
42
24
43
/* Tasks for development */
25
44
gulp . task ( 'serve' , function ( ) {
26
- var serverModule = require ( './lib/server' ) ( sourcePath , outputPath ) ,
45
+ // Since we are running our own server we can enable socketIO
46
+ options . socketIo = true ;
47
+ var serverModule = require ( './lib/server' ) ( {
48
+ rootPath : outputPath ,
49
+ sassVariables : options . sassVariables
50
+ } ) ,
27
51
app = serverModule . app ,
28
52
server = serverModule . server ;
29
53
@@ -52,20 +76,8 @@ gulp.task('styleguide', function() {
52
76
process . exit ( 1 )
53
77
return 1 ;
54
78
}
55
- // Resolve overviewPath in relation to config file location
56
- var overviewPath ;
57
- if ( config . overviewPath ) {
58
- overviewPath = path . resolve ( path . dirname ( configPath ) , config . overviewPath ) ;
59
- }
60
79
return gulp . src ( [ sourcePath + '/**/*.scss' ] )
61
- . pipe ( styleguide ( {
62
- extraHead : config . extraHead ,
63
- overviewPath : overviewPath ,
64
- socketIo : socketIo ,
65
- sass : {
66
- loadPath : neat . includePaths
67
- }
68
- } ) )
80
+ . pipe ( styleguide ( options ) )
69
81
. pipe ( gulp . dest ( outputPath ) ) ;
70
82
} ) ;
71
83
@@ -110,7 +122,10 @@ gulp.task('demo', function() {
110
122
configPath = __dirname + '/demo/source/styleguide_config.json' ;
111
123
outputPath = __dirname + '/demo/output' ;
112
124
sourcePath = __dirname + '/demo/source' ;
113
- return runSequence ( 'styleguide' , 'serve' ) ;
125
+ // We need to re-parse options since configPath has changed
126
+ parseOptions ( ) ;
127
+ // Run serve first so socketIO options is enabled when building styleguide
128
+ return runSequence ( 'serve' , 'styleguide' ) ;
114
129
} ) ;
115
130
116
131
gulp . task ( 'html' , function ( ) {
@@ -125,7 +140,6 @@ gulp.task('assets', function() {
125
140
126
141
gulp . task ( 'watch' , [ ] , function ( ) {
127
142
// Do intial full build and create styleguide
128
- socketIo = true ;
129
143
runSequence ( [ 'serve' , 'build' ] , 'styleguide' ) ;
130
144
131
145
gulp . watch ( 'lib/app/sass/**/*.scss' , function ( ) {
0 commit comments