@@ -94,7 +94,7 @@ function livingcss(source, dest, options) {
9494 tags [ tag ] = options . tags [ tag ] ;
9595 }
9696
97- Promise . all ( [
97+ return Promise . all ( [
9898 // read the handlebars template
9999 new Promise ( function ( resolve , reject ) {
100100 fs . readFile ( options . template , 'utf8' , function ( err , data ) {
@@ -129,7 +129,11 @@ function livingcss(source, dest, options) {
129129
130130 context . allSections = context . sections ;
131131
132- if ( context . pages . length > 1 ) {
132+ if ( context . pages . length === 0 ) {
133+ console . warn ( 'Warning: no pages generated from source files.' ) ;
134+ }
135+
136+ else if ( context . pages . length > 1 ) {
133137 context . navbar = context . pages . map ( function ( page ) {
134138 return {
135139 name : page . name ,
@@ -138,6 +142,8 @@ function livingcss(source, dest, options) {
138142 } ) ;
139143 }
140144
145+ var promises = [ ] ;
146+
141147 context . pages . forEach ( function ( page , index ) {
142148 // deep copy context for each page
143149 var pageContext = JSON . parse ( JSON . stringify ( context ) ) ;
@@ -151,8 +157,14 @@ function livingcss(source, dest, options) {
151157 }
152158
153159 // values[0] = handlebars template
154- generate ( path . join ( dest , page . id + '.html' ) , values [ 0 ] , pageContext , options ) ;
160+ promises . push (
161+ generate ( path . join ( dest , page . id + '.html' ) , values [ 0 ] , pageContext , options )
162+ ) ;
155163 } ) ;
164+
165+ // wait until all promises have returned (either rejected or resolved) before
166+ // returning the last promise
167+ return Promise . all ( promises ) ;
156168 } )
157169 . catch ( function ( err ) {
158170 console . error ( err . stack ) ;
0 commit comments