@@ -27,6 +27,9 @@ var patternlab_engine = function () {
2727 patternlab . package = fs . readJSONSync ( './package.json' ) ;
2828 patternlab . config = fs . readJSONSync ( './config.json' ) ;
2929
30+ var paths = patternlab . config . paths ;
31+
32+
3033 function getVersion ( ) {
3134 console . log ( patternlab . package . version ) ;
3235 }
@@ -55,18 +58,18 @@ var patternlab_engine = function () {
5558 }
5659
5760 function buildPatterns ( deletePatternDir ) {
58- patternlab . data = fs . readJSONSync ( './ source/_data/ data.json') ;
59- patternlab . listitems = fs . readJSONSync ( './ source/_data/ listitems.json') ;
60- patternlab . header = fs . readFileSync ( './ source/_patternlab-files/ pattern-header-footer/header.html', 'utf8' ) ;
61- patternlab . footer = fs . readFileSync ( './ source/_patternlab-files/ pattern-header-footer/footer.html', 'utf8' ) ;
61+ patternlab . data = fs . readJSONSync ( path . resolve ( paths . source . data , 'data .json') ) ;
62+ patternlab . listitems = fs . readJSONSync ( path . resolve ( paths . source . data , ' listitems.json') ) ;
63+ patternlab . header = fs . readFileSync ( path . resolve ( paths . source . patternlabFiles , ' pattern-header-footer/header.html') , 'utf8' ) ;
64+ patternlab . footer = fs . readFileSync ( path . resolve ( paths . source . patternlabFiles , ' pattern-header-footer/footer.html') , 'utf8' ) ;
6265 patternlab . patterns = [ ] ;
6366 patternlab . partials = { } ;
6467 patternlab . data . link = { } ;
6568
6669 var pattern_assembler = new pa ( ) ,
6770 entity_encoder = new he ( ) ,
6871 pattern_exporter = new pe ( ) ,
69- patterns_dir = './ source/_patterns' ;
72+ patterns_dir = paths . source . patterns ;
7073
7174 pattern_assembler . combine_listItems ( patternlab ) ;
7275
@@ -87,7 +90,6 @@ var patternlab_engine = function () {
8790 console . log ( err ) ;
8891 return ;
8992 }
90-
9193 pattern_assembler . process_pattern_iterative ( file . substring ( 2 ) , patternlab ) ;
9294 } ) ;
9395
@@ -113,13 +115,12 @@ var patternlab_engine = function () {
113115 console . log ( err ) ;
114116 return ;
115117 }
116-
117118 pattern_assembler . process_pattern_recursive ( file . substring ( 2 ) , patternlab ) ;
118119 } ) ;
119120
120121 //delete the contents of config.patterns.public before writing
121122 if ( deletePatternDir ) {
122- fs . emptyDirSync ( patternlab . config . patterns . public ) ;
123+ fs . emptyDirSync ( paths . public . patterns ) ;
123124 }
124125
125126 //render all patterns last, so lineageR works
@@ -136,13 +137,13 @@ var patternlab_engine = function () {
136137 var patternFooter = pattern_assembler . renderPattern ( patternlab . footer , pattern ) ;
137138
138139 //write the compiled template to the public patterns directory
139- fs . outputFileSync ( patternlab . config . patterns . public + pattern . patternLink , patternlab . header + pattern . patternPartial + patternFooter ) ;
140+ fs . outputFileSync ( paths . public . patterns + pattern . patternLink , patternlab . header + pattern . patternPartial + patternFooter ) ;
140141
141142 //write the mustache file too
142- fs . outputFileSync ( patternlab . config . patterns . public + pattern . patternLink . replace ( '.html' , '.mustache' ) , entity_encoder . encode ( pattern . template ) ) ;
143+ fs . outputFileSync ( paths . public . patterns + pattern . patternLink . replace ( '.html' , '.mustache' ) , entity_encoder . encode ( pattern . template ) ) ;
143144
144145 //write the encoded version too
145- fs . outputFileSync ( patternlab . config . patterns . public + pattern . patternLink . replace ( '.html' , '.escaped.html' ) , entity_encoder . encode ( pattern . patternPartial ) ) ;
146+ fs . outputFileSync ( paths . public . patterns + pattern . patternLink . replace ( '.html' , '.escaped.html' ) , entity_encoder . encode ( pattern . patternPartial ) ) ;
146147 } ) ;
147148
148149 //export patterns if necessary
@@ -164,7 +165,7 @@ var patternlab_engine = function () {
164165 media_hunter . find_media_queries ( './source/css' , patternlab ) ;
165166
166167 // check if patterns are excluded, if not add them to styleguidePatterns
167- if ( styleGuideExcludes . length ) {
168+ if ( styleGuideExcludes && styleGuideExcludes . length ) {
168169 for ( i = 0 ; i < patternlab . patterns . length ; i ++ ) {
169170
170171 // skip underscore-prefixed files
@@ -187,9 +188,9 @@ var patternlab_engine = function () {
187188 }
188189
189190 //build the styleguide
190- var styleguideTemplate = fs . readFileSync ( './ source/_patternlab-files/ styleguide.mustache', 'utf8' ) ,
191+ var styleguideTemplate = fs . readFileSync ( path . resolve ( paths . source . patternlabFiles , ' styleguide.mustache') , 'utf8' ) ,
191192 styleguideHtml = pattern_assembler . renderPattern ( styleguideTemplate , { partials : styleguidePatterns } ) ;
192- fs . outputFileSync ( './ public/ styleguide/ html/styleguide.html', styleguideHtml ) ;
193+ fs . outputFileSync ( path . resolve ( paths . public . styleguide , ' html/styleguide.html') , styleguideHtml ) ;
193194
194195 //build the viewall pages
195196 var prevSubdir = '' ,
@@ -228,14 +229,14 @@ var patternlab_engine = function () {
228229 }
229230 }
230231
231- var viewAllTemplate = fs . readFileSync ( './ source/_patternlab-files/ viewall.mustache', 'utf8' ) ;
232+ var viewAllTemplate = fs . readFileSync ( path . resolve ( paths . source . patternlabFiles , ' viewall.mustache') , 'utf8' ) ;
232233 var viewAllHtml = pattern_assembler . renderPattern ( viewAllTemplate , { partials : viewAllPatterns , patternPartial : patternPartial } ) ;
233- fs . outputFileSync ( patternlab . config . patterns . public + pattern . flatPatternPath + '/index.html' , viewAllHtml ) ;
234+ fs . outputFileSync ( paths . public . patterns + pattern . flatPatternPath + '/index.html' , viewAllHtml ) ;
234235 }
235236 }
236237
237238 //build the patternlab website
238- var patternlabSiteTemplate = fs . readFileSync ( './ source/_patternlab-files/ index.mustache', 'utf8' ) ;
239+ var patternlabSiteTemplate = fs . readFileSync ( path . resolve ( paths . source . patternlabFiles , ' index.mustache') , 'utf8' ) ;
239240
240241 //sort all patterns explicitly.
241242 patternlab . patterns = patternlab . patterns . sort ( function ( a , b ) {
@@ -415,20 +416,20 @@ var patternlab_engine = function () {
415416
416417 //the patternlab site requires a lot of partials to be rendered.
417418 //patternNav
418- var patternNavTemplate = fs . readFileSync ( './ source/_patternlab-files/ partials/patternNav.mustache', 'utf8' ) ;
419+ var patternNavTemplate = fs . readFileSync ( path . resolve ( paths . source . patternlabFiles , ' partials/patternNav.mustache') , 'utf8' ) ;
419420 var patternNavPartialHtml = pattern_assembler . renderPattern ( patternNavTemplate , patternlab ) ;
420421
421422 //ishControls
422- var ishControlsTemplate = fs . readFileSync ( './ source/_patternlab-files/ partials/ishControls.mustache', 'utf8' ) ;
423+ var ishControlsTemplate = fs . readFileSync ( path . resolve ( paths . source . patternlabFiles , ' partials/ishControls.mustache') , 'utf8' ) ;
423424 patternlab . config . mqs = patternlab . mediaQueries ;
424425 var ishControlsPartialHtml = pattern_assembler . renderPattern ( ishControlsTemplate , patternlab . config ) ;
425426
426427 //patternPaths
427- var patternPathsTemplate = fs . readFileSync ( './ source/_patternlab-files/ partials/patternPaths.mustache', 'utf8' ) ;
428+ var patternPathsTemplate = fs . readFileSync ( path . resolve ( paths . source . patternlabFiles , ' partials/patternPaths.mustache') , 'utf8' ) ;
428429 var patternPathsPartialHtml = pattern_assembler . renderPattern ( patternPathsTemplate , { 'patternPaths' : JSON . stringify ( patternlab . patternPaths ) } ) ;
429430
430431 //viewAllPaths
431- var viewAllPathsTemplate = fs . readFileSync ( './ source/_patternlab-files/ partials/viewAllPaths.mustache', 'utf8' ) ;
432+ var viewAllPathsTemplate = fs . readFileSync ( path . resolve ( paths . source . patternlabFiles , ' partials/viewAllPaths.mustache') , 'utf8' ) ;
432433 var viewAllPathsPartialHtml = pattern_assembler . renderPattern ( viewAllPathsTemplate , { 'viewallpaths' : JSON . stringify ( patternlab . viewAllPaths ) } ) ;
433434
434435 //render the patternlab template, with all partials
@@ -438,7 +439,7 @@ var patternlab_engine = function () {
438439 'patternPaths' : patternPathsPartialHtml ,
439440 'viewAllPaths' : viewAllPathsPartialHtml
440441 } ) ;
441- fs . outputFileSync ( './ public/ index.html', patternlabSiteHtml ) ;
442+ fs . outputFileSync ( path . resolve ( paths . public . root , ' index.html') , patternlabSiteHtml ) ;
442443 }
443444
444445 function addToPatternPaths ( bucketName , pattern ) {
0 commit comments