@@ -502,53 +502,26 @@ const patternlab_engine = function (config) {
502
502
return PatternGraph . loadFromFile ( patternlab ) ;
503
503
}
504
504
505
- function buildPatterns ( deletePatternDir ) {
506
-
507
- if ( patternlab . config . debug ) {
508
- console . log (
509
- chalk . bold ( '\n====[ Pattern Lab / Node' ) ,
510
- `- v${ packageInfo . version } ` ,
511
- chalk . bold ( ']====\n' )
512
- ) ;
513
- }
514
-
515
- patternlab . events . emit ( 'patternlab-build-pattern-start' , patternlab ) ;
516
-
517
- const graph = patternlab . graph = loadPatternGraph ( deletePatternDir ) ;
518
-
519
- const graphNeedsUpgrade = ! PatternGraph . checkVersion ( graph ) ;
520
-
521
- if ( graphNeedsUpgrade ) {
522
- plutils . log . info ( "Due to an upgrade, a complete rebuild is required and the public/patterns directory was deleted. " +
523
- "Incremental build is available again on the next successful run." ) ;
524
-
525
- // Ensure that the freshly built graph has the latest version again.
526
- patternlab . graph . upgradeVersion ( ) ;
527
- }
528
-
529
- // Flags
530
- const incrementalBuildsEnabled = ! ( deletePatternDir || graphNeedsUpgrade ) ;
531
-
532
- if ( incrementalBuildsEnabled ) {
533
- plutils . log . info ( "Incremental builds enabled." ) ;
534
- } else {
535
- // needs to be done BEFORE processing patterns
536
- fs . removeSync ( paths . public . patterns ) ;
537
- fs . emptyDirSync ( paths . public . patterns ) ;
538
- }
505
+ function buildGlobalData ( ) {
506
+ //
507
+ // COLLECT GLOBAL LIBRARY DATA
508
+ //
539
509
510
+ // data.json
540
511
try {
541
512
patternlab . data = buildPatternData ( paths . source . data , fs ) ;
542
513
} catch ( ex ) {
543
514
plutils . error ( 'missing or malformed' + paths . source . data + 'data.json Pattern Lab may not work without this file.' ) ;
544
515
patternlab . data = { } ;
545
516
}
517
+ // listitems.json
546
518
try {
547
519
patternlab . listitems = fs . readJSONSync ( path . resolve ( paths . source . data , 'listitems.json' ) ) ;
548
520
} catch ( ex ) {
549
521
plutils . warning ( 'WARNING: missing or malformed ' + paths . source . data + 'listitems.json file. Pattern Lab may not work without this file.' ) ;
550
522
patternlab . listitems = { } ;
551
523
}
524
+ // load up all the necessary files from pattern lab that apply to every template
552
525
try {
553
526
patternlab . header = fs . readFileSync ( path . resolve ( paths . source . patternlabFiles [ 'general-header' ] ) , 'utf8' ) ;
554
527
patternlab . footer = fs . readFileSync ( path . resolve ( paths . source . patternlabFiles [ 'general-footer' ] ) , 'utf8' ) ;
@@ -560,6 +533,12 @@ const patternlab_engine = function (config) {
560
533
plutils . error ( '\nERROR: missing an essential file from ' + paths . source . patternlabFiles + '. Pattern Lab won\'t work without this file.\n' ) ;
561
534
process . exit ( 1 ) ;
562
535
}
536
+
537
+
538
+ //
539
+ // INITIALIZE EMPTY GLOBAL DATA STRUCTURES
540
+ //
541
+
563
542
patternlab . patterns = [ ] ;
564
543
patternlab . subtypePatterns = { } ;
565
544
patternlab . partials = { } ;
@@ -570,6 +549,51 @@ const patternlab_engine = function (config) {
570
549
pattern_assembler . combine_listItems ( patternlab ) ;
571
550
572
551
patternlab . events . emit ( 'patternlab-build-global-data-end' , patternlab ) ;
552
+ }
553
+
554
+
555
+ function cleanBuildDirectory ( incrementalBuildsEnabled ) {
556
+ if ( incrementalBuildsEnabled ) {
557
+ plutils . log . info ( "Incremental builds enabled." ) ;
558
+ } else {
559
+ // needs to be done BEFORE processing patterns
560
+ fs . removeSync ( paths . public . patterns ) ;
561
+ fs . emptyDirSync ( paths . public . patterns ) ;
562
+ }
563
+ }
564
+
565
+ function buildPatterns ( deletePatternDir ) {
566
+
567
+ if ( patternlab . config . debug ) {
568
+ console . log (
569
+ chalk . bold ( '\n====[ Pattern Lab / Node' ) ,
570
+ `- v${ packageInfo . version } ` ,
571
+ chalk . bold ( ']====\n' )
572
+ ) ;
573
+ }
574
+
575
+ patternlab . events . emit ( 'patternlab-build-pattern-start' , patternlab ) ;
576
+
577
+ //
578
+ // CHECK INCREMENTAL BUILD GRAPH
579
+ //
580
+ const graph = patternlab . graph = loadPatternGraph ( deletePatternDir ) ;
581
+ const graphNeedsUpgrade = ! PatternGraph . checkVersion ( graph ) ;
582
+ if ( graphNeedsUpgrade ) {
583
+ plutils . log . info ( "Due to an upgrade, a complete rebuild is required and the public/patterns directory was deleted. " +
584
+ "Incremental build is available again on the next successful run." ) ;
585
+
586
+ // Ensure that the freshly built graph has the latest version again.
587
+ patternlab . graph . upgradeVersion ( ) ;
588
+ }
589
+ // Flags
590
+ const incrementalBuildsEnabled = ! ( deletePatternDir || graphNeedsUpgrade ) ;
591
+
592
+ //
593
+ // CLEAN BUILD DIRECTORY, maybe
594
+ //
595
+ cleanBuildDirectory ( incrementalBuildsEnabled ) ;
596
+ buildGlobalData ( ) ;
573
597
574
598
// diveSync once to perform iterative populating of patternlab object
575
599
return processAllPatternsIterative ( paths . source . patterns , patternlab ) . then ( ( ) => {
0 commit comments