@@ -5,7 +5,7 @@ const jsonCopy = require('./json_copy');
55const ae = require ( './annotation_exporter' ) ;
66const of = require ( './object_factory' ) ;
77const Pattern = of . Pattern ;
8- const plutils = require ( './utilities ' ) ;
8+ const logger = require ( './log ' ) ;
99const eol = require ( 'os' ) . EOL ;
1010const _ = require ( 'lodash' ) ;
1111
@@ -67,37 +67,29 @@ const ui_builder = function () {
6767 // skip underscore-prefixed files
6868 isOmitted = pattern . isPattern && pattern . fileName . charAt ( 0 ) === '_' ;
6969 if ( isOmitted ) {
70- if ( patternlab . config . debug ) {
71- console . log ( 'Omitting ' + pattern . patternPartial + " from styleguide patterns because it has an underscore suffix." ) ;
72- }
70+ logger . debug ( `Omitting ${ pattern . patternPartial } from styleguide patterns because it has an underscore suffix.` ) ;
7371 return true ;
7472 }
7573
7674 //this is meant to be a homepage that is not present anywhere else
7775 isOmitted = pattern . patternPartial === patternlab . config . defaultPattern ;
7876 if ( isOmitted ) {
79- if ( patternlab . config . debug ) {
80- console . log ( 'Omitting ' + pattern . patternPartial + ' from styleguide patterns because it is defined as a defaultPattern.' ) ;
81- }
77+ logger . debug ( `Omitting ${ pattern . patternPartial } from styleguide patterns because it is defined as a defaultPattern.` ) ;
8278 patternlab . defaultPattern = pattern ;
8379 return true ;
8480 }
8581
8682 //this pattern is contained with a directory prefixed with an underscore (a handy way to hide whole directories from the nav
8783 isOmitted = pattern . relPath . charAt ( 0 ) === '_' || pattern . relPath . indexOf ( path . sep + '_' ) > - 1 ;
8884 if ( isOmitted ) {
89- if ( patternlab . config . debug ) {
90- console . log ( 'Omitting ' + pattern . patternPartial + ' from styleguide patterns because its contained within an underscored directory.' ) ;
91- }
85+ logger . debug ( `Omitting ${ pattern . patternPartial } from styleguide patterns because its contained within an underscored directory.` ) ;
9286 return true ;
9387 }
9488
9589 //this pattern is a head or foot pattern
9690 isOmitted = pattern . isMetaPattern ;
9791 if ( isOmitted ) {
98- if ( patternlab . config . debug ) {
99- console . log ( 'Omitting ' + pattern . patternPartial + ' from styleguide patterns because its a meta pattern.' ) ;
100- }
92+ logger . debug ( `Omitting ${ pattern . patternPartial } from styleguide patterns because its a meta pattern.` ) ;
10193 return true ;
10294 }
10395
@@ -169,9 +161,7 @@ const ui_builder = function () {
169161 const patternType = _ . find ( patternlab . patternTypes , [ 'patternType' , pattern . patternType ] ) ;
170162
171163 if ( ! patternType ) {
172- plutils . error ( 'Could not find patternType' + pattern . patternType + '. This is a critical error.' ) ;
173- console . trace ( ) ;
174- process . exit ( 1 ) ;
164+ logger . error ( `Could not find patternType ${ pattern . patternType } . This is a critical error.` ) ;
175165 }
176166
177167 return patternType ;
@@ -188,9 +178,7 @@ const ui_builder = function () {
188178 const patternSubType = _ . find ( patternType . patternTypeItems , [ 'patternSubtype' , pattern . patternSubType ] ) ;
189179
190180 if ( ! patternSubType ) {
191- plutils . error ( 'Could not find patternType ' + pattern . patternType + '-' + pattern . patternType + '. This is a critical error.' ) ;
192- console . trace ( ) ;
193- process . exit ( 1 ) ;
181+ logger . error ( `Could not find patternType ${ pattern . patternType } -${ pattern . patternType } . This is a critical error.` ) ;
194182 }
195183
196184 return patternSubType ;
@@ -276,9 +264,7 @@ const ui_builder = function () {
276264 function addPatternItem ( patternlab , pattern , isViewAllVariant ) {
277265 const patternType = getPatternType ( patternlab , pattern ) ;
278266 if ( ! patternType ) {
279- plutils . error ( 'Could not find patternType' + pattern . patternType + '. This is a critical error.' ) ;
280- console . trace ( ) ;
281- process . exit ( 1 ) ;
267+ logger . error ( `Could not find patternType ${ pattern . patternType } . This is a critical error.` ) ;
282268 }
283269
284270 if ( ! patternType . patternItems ) {
@@ -439,8 +425,8 @@ const ui_builder = function () {
439425 try {
440426 allFooterData = jsonCopy ( patternlab . data , 'config.paths.source.data plus patterns data' ) ;
441427 } catch ( err ) {
442- console . log ( 'There was an error parsing JSON for patternlab.data' ) ;
443- console . log ( err ) ;
428+ logger . warning ( 'There was an error parsing JSON for patternlab.data' ) ;
429+ logger . warning ( err ) ;
444430 }
445431 allFooterData . patternLabFoot = footerPartial ;
446432
@@ -517,9 +503,7 @@ const ui_builder = function () {
517503 return exclude === patternType + '/' + patternSubtype ;
518504 } ) ;
519505 if ( omitPatternType ) {
520- if ( patternlab . config . debug ) {
521- console . log ( 'Omitting ' + patternType + '/' + patternSubtype + ' from building a viewall page because its patternSubGroup is specified in styleguideExcludes.' ) ;
522- }
506+ logger . debug ( `Omitting ${ patternType } /${ patternSubtype } from building a viewall page because its patternSubGroup is specified in styleguideExcludes.` ) ;
523507 } else {
524508 styleguideTypePatterns = styleguideTypePatterns . concat ( subtypePatterns ) ;
525509 }
@@ -556,9 +540,7 @@ const ui_builder = function () {
556540 return exclude === patternType ;
557541 } ) ;
558542 if ( omitPatternType ) {
559- if ( patternlab . config . debug ) {
560- console . log ( 'Omitting ' + patternType + ' from building a viewall page because its patternGroup is specified in styleguideExcludes.' ) ;
561- }
543+ logger . debug ( `Omitting ${ patternType } from building a viewall page because its patternGroup is specified in styleguideExcludes.` ) ;
562544 } else {
563545 patterns = patterns . concat ( styleguideTypePatterns ) ;
564546 }
@@ -671,10 +653,8 @@ const ui_builder = function () {
671653 let patternlabSiteHtml ;
672654 try {
673655 patternlabSiteHtml = fs . readFileSync ( path . resolve ( paths . source . styleguide , 'index.html' ) , 'utf8' ) ;
674- } catch ( error ) {
675- console . log ( error ) ;
676- console . log ( "\nERROR: Could not load one or more styleguidekit assets from" , paths . source . styleguide , '\n' ) ;
677- process . exit ( 1 ) ;
656+ } catch ( err ) {
657+ logger . error ( `Could not load one or more styleguidekit assets from ${ paths . source . styleguide } ` ) ;
678658 }
679659 fs . outputFileSync ( path . resolve ( paths . public . root , 'index.html' ) , patternlabSiteHtml ) ;
680660
0 commit comments