@@ -6,8 +6,7 @@ var fs = require('fs-extra');
66var ae = require ( './annotation_exporter' ) ;
77var of = require ( './object_factory' ) ;
88var Pattern = of . Pattern ;
9- var pa = require ( './pattern_assembler' ) ;
10- var pattern_assembler = new pa ( ) ;
9+ var pattern_assembler = require ( './pattern_assembler' ) ( ) ;
1110var plutils = require ( './utilities' ) ;
1211var eol = require ( 'os' ) . EOL ;
1312var _ = require ( 'lodash' ) ;
@@ -54,20 +53,6 @@ var ui_builder = function () {
5453 }
5554 }
5655
57- /**
58- * Writes a file to disk, with an optional callback
59- * @param filePath - the path to write to with filename
60- * @param data - the file contents
61- * @param callback - an optional callback
62- */
63- function writeFile ( filePath , data , callback ) {
64- if ( callback ) {
65- fs . outputFileSync ( filePath , data , callback ) ;
66- } else {
67- fs . outputFileSync ( filePath , data ) ;
68- }
69- }
70-
7156 /**
7257 * Returns whether or not the pattern should be excluded from direct rendering or navigation on the front end
7358 * @param pattern - the pattern to test for inclusion/exclusion
@@ -468,7 +453,7 @@ var ui_builder = function () {
468453 //do not create a viewall page for flat patterns
469454 if ( patternType === patternSubtype ) {
470455 writeViewAllFile = false ;
471- return false ;
456+ return ;
472457 }
473458
474459 //render the footer needed for the viewall template
@@ -485,13 +470,12 @@ var ui_builder = function () {
485470 typePatterns = typePatterns . concat ( subtypePatterns ) ;
486471
487472 var viewAllHTML = buildViewAllHTML ( patternlab , subtypePatterns , patternPartial ) ;
488- writeFile ( paths . public . patterns + p . flatPatternPath + '/index.html' , mainPageHeadHtml + viewAllHTML + footerHTML ) ;
489- return true ; //stop yelling at us eslint we know we know
473+ fs . outputFileSync ( paths . public . patterns + p . flatPatternPath + '/index.html' , mainPageHeadHtml + viewAllHTML + footerHTML ) ;
490474 } ) ;
491475
492476 //do not create a viewall page for flat patterns
493477 if ( ! writeViewAllFile || ! p ) {
494- return false ;
478+ return ;
495479 }
496480
497481 //render the footer needed for the viewall template
@@ -507,7 +491,7 @@ var ui_builder = function () {
507491
508492 //render the viewall template for the type
509493 var viewAllHTML = buildViewAllHTML ( patternlab , typePatterns , patternType ) ;
510- writeFile ( paths . public . patterns + anyPatternOfType . patternType + '/index.html' , mainPageHeadHtml + viewAllHTML + footerHTML ) ;
494+ fs . outputFileSync ( paths . public . patterns + anyPatternOfType . patternType + '/index.html' , mainPageHeadHtml + viewAllHTML + footerHTML ) ;
511495
512496 //determine if we should omit this patterntype completely from the viewall page
513497 var omitPatternType = styleGuideExcludes && styleGuideExcludes . length
@@ -521,8 +505,6 @@ var ui_builder = function () {
521505 } else {
522506 patterns = patterns . concat ( typePatterns ) ;
523507 }
524-
525- return true ; //stop yelling at us eslint we know we know
526508 } ) ;
527509 return patterns ;
528510 }
@@ -561,12 +543,12 @@ var ui_builder = function () {
561543 output += 'var defaultPattern = "' + ( patternlab . config . defaultPattern ? patternlab . config . defaultPattern : 'all' ) + '";' + eol ;
562544
563545 //write all output to patternlab-data
564- writeFile ( path . resolve ( paths . public . data , 'patternlab-data.js' ) , output ) ;
546+ fs . outputFileSync ( path . resolve ( paths . public . data , 'patternlab-data.js' ) , output ) ;
565547
566548 //annotations
567549 var annotationsJSON = annotation_exporter . gather ( ) ;
568550 var annotations = 'var comments = { "comments" : ' + JSON . stringify ( annotationsJSON ) + '};' ;
569- writeFile ( path . resolve ( paths . public . annotations , 'annotations.js' ) , annotations ) ;
551+ fs . outputFileSync ( path . resolve ( paths . public . annotations , 'annotations.js' ) , annotations ) ;
570552 }
571553
572554 /**
@@ -626,7 +608,7 @@ var ui_builder = function () {
626608 patternSection : patternlab . patternSection ,
627609 patternSectionSubtype : patternlab . patternSectionSubType
628610 } ) ;
629- writeFile ( path . resolve ( paths . public . styleguide , 'html/styleguide.html' ) , headerHTML + styleguideHtml + footerHTML ) ;
611+ fs . outputFileSync ( path . resolve ( paths . public . styleguide , 'html/styleguide.html' ) , headerHTML + styleguideHtml + footerHTML ) ;
630612
631613 //move the index file from its asset location into public root
632614 var patternlabSiteHtml ;
@@ -637,7 +619,7 @@ var ui_builder = function () {
637619 console . log ( "\nERROR: Could not load one or more styleguidekit assets from" , paths . source . styleguide , '\n' ) ;
638620 process . exit ( 1 ) ;
639621 }
640- writeFile ( path . resolve ( paths . public . root , 'index.html' ) , patternlabSiteHtml ) ;
622+ fs . outputFileSync ( path . resolve ( paths . public . root , 'index.html' ) , patternlabSiteHtml ) ;
641623
642624 //write out patternlab.data object to be read by the client
643625 exportData ( patternlab ) ;
@@ -655,6 +637,9 @@ var ui_builder = function () {
655637 } ,
656638 resetUIBuilderState : function ( patternlab ) {
657639 resetUIBuilderState ( patternlab ) ;
640+ } ,
641+ buildViewAllPages : function ( mainPageHeadHtml , patternlab , styleguidePatterns ) {
642+ return buildViewAllPages ( mainPageHeadHtml , patternlab , styleguidePatterns ) ;
658643 }
659644 } ;
660645
0 commit comments