@@ -27,6 +27,9 @@ var patternlab_engine = function () {
27
27
patternlab . package = fs . readJSONSync ( './package.json' ) ;
28
28
patternlab . config = fs . readJSONSync ( './config.json' ) ;
29
29
30
+ var paths = patternlab . config . paths ;
31
+
32
+
30
33
function getVersion ( ) {
31
34
console . log ( patternlab . package . version ) ;
32
35
}
@@ -55,18 +58,18 @@ var patternlab_engine = function () {
55
58
}
56
59
57
60
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' ) ;
62
65
patternlab . patterns = [ ] ;
63
66
patternlab . partials = { } ;
64
67
patternlab . data . link = { } ;
65
68
66
69
var pattern_assembler = new pa ( ) ,
67
70
entity_encoder = new he ( ) ,
68
71
pattern_exporter = new pe ( ) ,
69
- patterns_dir = './ source/_patterns' ;
72
+ patterns_dir = paths . source . patterns ;
70
73
71
74
pattern_assembler . combine_listItems ( patternlab ) ;
72
75
@@ -87,7 +90,6 @@ var patternlab_engine = function () {
87
90
console . log ( err ) ;
88
91
return ;
89
92
}
90
-
91
93
pattern_assembler . process_pattern_iterative ( file . substring ( 2 ) , patternlab ) ;
92
94
} ) ;
93
95
@@ -113,13 +115,12 @@ var patternlab_engine = function () {
113
115
console . log ( err ) ;
114
116
return ;
115
117
}
116
-
117
118
pattern_assembler . process_pattern_recursive ( file . substring ( 2 ) , patternlab ) ;
118
119
} ) ;
119
120
120
121
//delete the contents of config.patterns.public before writing
121
122
if ( deletePatternDir ) {
122
- fs . emptyDirSync ( patternlab . config . patterns . public ) ;
123
+ fs . emptyDirSync ( paths . public . patterns ) ;
123
124
}
124
125
125
126
//render all patterns last, so lineageR works
@@ -136,13 +137,13 @@ var patternlab_engine = function () {
136
137
var patternFooter = pattern_assembler . renderPattern ( patternlab . footer , pattern ) ;
137
138
138
139
//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 ) ;
140
141
141
142
//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 ) ) ;
143
144
144
145
//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 ) ) ;
146
147
} ) ;
147
148
148
149
//export patterns if necessary
@@ -164,7 +165,7 @@ var patternlab_engine = function () {
164
165
media_hunter . find_media_queries ( './source/css' , patternlab ) ;
165
166
166
167
// check if patterns are excluded, if not add them to styleguidePatterns
167
- if ( styleGuideExcludes . length ) {
168
+ if ( styleGuideExcludes && styleGuideExcludes . length ) {
168
169
for ( i = 0 ; i < patternlab . patterns . length ; i ++ ) {
169
170
170
171
// skip underscore-prefixed files
@@ -187,9 +188,9 @@ var patternlab_engine = function () {
187
188
}
188
189
189
190
//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' ) ,
191
192
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 ) ;
193
194
194
195
//build the viewall pages
195
196
var prevSubdir = '' ,
@@ -228,14 +229,14 @@ var patternlab_engine = function () {
228
229
}
229
230
}
230
231
231
- var viewAllTemplate = fs . readFileSync ( './ source/_patternlab-files/ viewall.mustache', 'utf8' ) ;
232
+ var viewAllTemplate = fs . readFileSync ( path . resolve ( paths . source . patternlabFiles , ' viewall.mustache') , 'utf8' ) ;
232
233
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 ) ;
234
235
}
235
236
}
236
237
237
238
//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' ) ;
239
240
240
241
//sort all patterns explicitly.
241
242
patternlab . patterns = patternlab . patterns . sort ( function ( a , b ) {
@@ -415,20 +416,20 @@ var patternlab_engine = function () {
415
416
416
417
//the patternlab site requires a lot of partials to be rendered.
417
418
//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' ) ;
419
420
var patternNavPartialHtml = pattern_assembler . renderPattern ( patternNavTemplate , patternlab ) ;
420
421
421
422
//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' ) ;
423
424
patternlab . config . mqs = patternlab . mediaQueries ;
424
425
var ishControlsPartialHtml = pattern_assembler . renderPattern ( ishControlsTemplate , patternlab . config ) ;
425
426
426
427
//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' ) ;
428
429
var patternPathsPartialHtml = pattern_assembler . renderPattern ( patternPathsTemplate , { 'patternPaths' : JSON . stringify ( patternlab . patternPaths ) } ) ;
429
430
430
431
//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' ) ;
432
433
var viewAllPathsPartialHtml = pattern_assembler . renderPattern ( viewAllPathsTemplate , { 'viewallpaths' : JSON . stringify ( patternlab . viewAllPaths ) } ) ;
433
434
434
435
//render the patternlab template, with all partials
@@ -438,7 +439,7 @@ var patternlab_engine = function () {
438
439
'patternPaths' : patternPathsPartialHtml ,
439
440
'viewAllPaths' : viewAllPathsPartialHtml
440
441
} ) ;
441
- fs . outputFileSync ( './ public/ index.html', patternlabSiteHtml ) ;
442
+ fs . outputFileSync ( path . resolve ( paths . public . root , ' index.html') , patternlabSiteHtml ) ;
442
443
}
443
444
444
445
function addToPatternPaths ( bucketName , pattern ) {
0 commit comments