@@ -160,10 +160,17 @@ const patternlab_module = function(config) {
160
160
function cleanBuildDirectory ( incrementalBuildsEnabled ) {
161
161
if ( incrementalBuildsEnabled ) {
162
162
logger . info ( 'Incremental builds enabled.' ) ;
163
+ return Promise . resolve ( ) ;
163
164
} else {
164
165
// needs to be done BEFORE processing patterns
165
- fs . removeSync ( paths . public . patterns ) ;
166
- fs . emptyDirSync ( paths . public . patterns ) ;
166
+ return fs
167
+ . emptyDir ( paths . public . patterns )
168
+ . then ( ( ) => {
169
+ return Promise . resolve ( ) ;
170
+ } )
171
+ . catch ( reason => {
172
+ logger . error ( reason ) ;
173
+ } ) ;
167
174
}
168
175
}
169
176
@@ -193,129 +200,134 @@ const patternlab_module = function(config) {
193
200
//
194
201
// CLEAN BUILD DIRECTORY, maybe
195
202
//
196
- cleanBuildDirectory ( patternlab . incrementalBuildsEnabled ) ;
197
-
198
- patternlab . buildGlobalData ( additionalData ) ;
199
-
200
- return patternlab
201
- . processAllPatternsIterative ( paths . source . patterns )
202
- . then ( ( ) => {
203
- patternlab . events . emit ( 'patternlab-pattern-iteration-end' , patternlab ) ;
204
-
205
- //now that all the main patterns are known, look for any links that might be within data and expand them
206
- //we need to do this before expanding patterns & partials into extendedTemplates, otherwise we could lose the data -> partial reference
207
- parseAllLinks ( patternlab ) ;
208
-
209
- //dive again to recursively include partials, filling out the
210
- //extendedTemplate property of the patternlab.patterns elements
211
-
212
- return patternlab
213
- . processAllPatternsRecursive ( paths . source . patterns )
214
- . then ( ( ) => {
215
- //take the user defined head and foot and process any data and patterns that apply
216
- const headPatternPromise = processMetaPattern (
217
- `_00-head.${ patternlab . config . patternExtension } ` ,
218
- 'userHead' ,
219
- patternlab
220
- ) ;
221
- const footPatternPromise = processMetaPattern (
222
- `_01-foot.${ patternlab . config . patternExtension } ` ,
223
- 'userFoot' ,
224
- patternlab
225
- ) ;
226
-
227
- return Promise . all ( [ headPatternPromise , footPatternPromise ] )
228
- . then ( ( ) => {
229
- //cascade any patternStates
230
- lineage_hunter . cascade_pattern_states ( patternlab ) ;
231
-
232
- //set the pattern-specific header by compiling the general-header with data, and then adding it to the meta header
233
- return render (
234
- Pattern . createEmpty ( { extendedTemplate : patternlab . header } ) ,
235
- {
236
- cacheBuster : patternlab . cacheBuster ,
237
- }
238
- )
239
- . then ( results => {
240
- patternlab . data . patternLabHead = results ;
241
-
242
- // If deletePatternDir == true or graph needs to be updated
243
- // rebuild all patterns
244
- let patternsToBuild = null ;
245
-
246
- // If deletePatternDir == true or graph needs to be updated
247
- // rebuild all patterns
248
- patternsToBuild = null ;
249
-
250
- if ( patternlab . incrementalBuildsEnabled ) {
251
- // When the graph was loaded from file, some patterns might have been moved/deleted between runs
252
- // so the graph data become out of sync
253
- patternlab . graph . sync ( ) . forEach ( n => {
254
- logger . info ( '[Deleted/Moved] ' + n ) ;
255
- } ) ;
256
-
257
- // TODO Find created or deleted files
258
- const now = new Date ( ) . getTime ( ) ;
259
- markModifiedPatterns ( now , patternlab ) ;
260
- patternsToBuild = patternlab . graph . compileOrder ( ) ;
261
- } else {
262
- // build all patterns, mark all to be rebuilt
263
- patternsToBuild = patternlab . patterns ;
264
- for ( const p of patternsToBuild ) {
265
- p . compileState = CompileState . NEEDS_REBUILD ;
266
- }
203
+ return cleanBuildDirectory ( patternlab . incrementalBuildsEnabled ) . then ( ( ) => {
204
+ patternlab . buildGlobalData ( additionalData ) ;
205
+
206
+ return patternlab
207
+ . processAllPatternsIterative ( paths . source . patterns )
208
+ . then ( ( ) => {
209
+ patternlab . events . emit (
210
+ 'patternlab-pattern-iteration-end' ,
211
+ patternlab
212
+ ) ;
213
+
214
+ //now that all the main patterns are known, look for any links that might be within data and expand them
215
+ //we need to do this before expanding patterns & partials into extendedTemplates, otherwise we could lose the data -> partial reference
216
+ parseAllLinks ( patternlab ) ;
217
+
218
+ //dive again to recursively include partials, filling out the
219
+ //extendedTemplate property of the patternlab.patterns elements
220
+
221
+ return patternlab
222
+ . processAllPatternsRecursive ( paths . source . patterns )
223
+ . then ( ( ) => {
224
+ //take the user defined head and foot and process any data and patterns that apply
225
+ const headPatternPromise = processMetaPattern (
226
+ `_00-head.${ patternlab . config . patternExtension } ` ,
227
+ 'userHead' ,
228
+ patternlab
229
+ ) ;
230
+ const footPatternPromise = processMetaPattern (
231
+ `_01-foot.${ patternlab . config . patternExtension } ` ,
232
+ 'userFoot' ,
233
+ patternlab
234
+ ) ;
235
+
236
+ return Promise . all ( [ headPatternPromise , footPatternPromise ] )
237
+ . then ( ( ) => {
238
+ //cascade any patternStates
239
+ lineage_hunter . cascade_pattern_states ( patternlab ) ;
240
+
241
+ //set the pattern-specific header by compiling the general-header with data, and then adding it to the meta header
242
+ return render (
243
+ Pattern . createEmpty ( {
244
+ extendedTemplate : patternlab . header ,
245
+ } ) ,
246
+ {
247
+ cacheBuster : patternlab . cacheBuster ,
267
248
}
249
+ )
250
+ . then ( results => {
251
+ patternlab . data . patternLabHead = results ;
252
+
253
+ // If deletePatternDir == true or graph needs to be updated
254
+ // rebuild all patterns
255
+ let patternsToBuild = null ;
256
+
257
+ // If deletePatternDir == true or graph needs to be updated
258
+ // rebuild all patterns
259
+ patternsToBuild = null ;
260
+
261
+ if ( patternlab . incrementalBuildsEnabled ) {
262
+ // When the graph was loaded from file, some patterns might have been moved/deleted between runs
263
+ // so the graph data become out of sync
264
+ patternlab . graph . sync ( ) . forEach ( n => {
265
+ logger . info ( '[Deleted/Moved] ' + n ) ;
266
+ } ) ;
267
+
268
+ // TODO Find created or deleted files
269
+ const now = new Date ( ) . getTime ( ) ;
270
+ markModifiedPatterns ( now , patternlab ) ;
271
+ patternsToBuild = patternlab . graph . compileOrder ( ) ;
272
+ } else {
273
+ // build all patterns, mark all to be rebuilt
274
+ patternsToBuild = patternlab . patterns ;
275
+ for ( const p of patternsToBuild ) {
276
+ p . compileState = CompileState . NEEDS_REBUILD ;
277
+ }
278
+ }
268
279
269
- //render all patterns last, so lineageR works
270
- return patternsToBuild
271
- . reduce ( ( previousPromise , pattern ) => {
272
- return previousPromise . then ( ( ) =>
273
- patternlab . renderSinglePattern ( pattern )
274
- ) ;
275
- } , Promise . resolve ( ) )
276
- . then ( ( ) => {
277
- // Saves the pattern graph when all files have been compiled
278
- PatternGraph . storeToFile ( patternlab ) ;
279
- if ( patternlab . config . exportToGraphViz ) {
280
- PatternGraph . exportToDot (
281
- patternlab ,
282
- 'dependencyGraph.dot'
280
+ //render all patterns last, so lineageR works
281
+ return patternsToBuild
282
+ . reduce ( ( previousPromise , pattern ) => {
283
+ return previousPromise . then ( ( ) =>
284
+ patternlab . renderSinglePattern ( pattern )
283
285
) ;
284
- logger . info (
285
- `Exported pattern graph to ${ path . join (
286
- config . paths . public . root ,
286
+ } , Promise . resolve ( ) )
287
+ . then ( ( ) => {
288
+ // Saves the pattern graph when all files have been compiled
289
+ PatternGraph . storeToFile ( patternlab ) ;
290
+ if ( patternlab . config . exportToGraphViz ) {
291
+ PatternGraph . exportToDot (
292
+ patternlab ,
287
293
'dependencyGraph.dot'
288
- ) } `
289
- ) ;
290
- }
291
-
292
- //export patterns if necessary
293
- pattern_exporter . export_patterns ( patternlab ) ;
294
- } )
295
- . catch ( reason => {
296
- console . log ( reason ) ;
297
- logger . error ( 'Error rendering patterns' ) ;
298
- } ) ;
299
- } )
300
- . catch ( reason => {
301
- console . log ( reason ) ;
302
- logger . error ( 'Error rendering pattern lab header' ) ;
303
- } ) ;
304
- } )
305
- . catch ( reason => {
306
- console . log ( reason ) ;
307
- logger . error ( 'Error processing meta patterns' ) ;
308
- } ) ;
309
- } )
310
- . catch ( reason => {
311
- console . log ( reason ) ;
312
- logger . error ( 'Error processing patterns recursively' ) ;
313
- } ) ;
314
- } )
315
- . catch ( reason => {
316
- console . log ( reason ) ;
317
- logger . error ( 'Error in buildPatterns()' ) ;
318
- } ) ;
294
+ ) ;
295
+ logger . info (
296
+ `Exported pattern graph to ${ path . join (
297
+ config . paths . public . root ,
298
+ 'dependencyGraph.dot'
299
+ ) } `
300
+ ) ;
301
+ }
302
+
303
+ //export patterns if necessary
304
+ pattern_exporter . export_patterns ( patternlab ) ;
305
+ } )
306
+ . catch ( reason => {
307
+ console . log ( reason ) ;
308
+ logger . error ( 'Error rendering patterns' ) ;
309
+ } ) ;
310
+ } )
311
+ . catch ( reason => {
312
+ console . log ( reason ) ;
313
+ logger . error ( 'Error rendering pattern lab header' ) ;
314
+ } ) ;
315
+ } )
316
+ . catch ( reason => {
317
+ console . log ( reason ) ;
318
+ logger . error ( 'Error processing meta patterns' ) ;
319
+ } ) ;
320
+ } )
321
+ . catch ( reason => {
322
+ console . log ( reason ) ;
323
+ logger . error ( 'Error processing patterns recursively' ) ;
324
+ } ) ;
325
+ } )
326
+ . catch ( reason => {
327
+ console . log ( reason ) ;
328
+ logger . error ( 'Error in buildPatterns()' ) ;
329
+ } ) ;
330
+ } ) ;
319
331
}
320
332
321
333
return {
0 commit comments