11/*
2- * patternlab-node - v0.1.1 - 2014-05-07
2+ * patternlab-node - v0.1.2 - 2014-05-08
33 *
44 * Brian Muenzenmeyer, and the web community.
55 * Licensed under the MIT license.
88 *
99 */
1010
11- var plnode = function ( grunt ) {
11+ var patternlab_engine = function ( grunt ) {
1212 var path = require ( 'path' ) ,
13- mustache = require ( 'mustache' ) ,
14- of = require ( './object_factory' ) ,
15- pa = require ( './pattern_assembler' ) ,
16- patternlab = { } ;
13+ mustache = require ( 'mustache' ) ,
14+ of = require ( './object_factory' ) ,
15+ pa = require ( './pattern_assembler' ) ,
16+ patternlab = { } ;
1717
1818 patternlab . package = grunt . file . readJSON ( 'package.json' ) ;
1919
@@ -25,19 +25,22 @@ var plnode = function(grunt){
2525 grunt . log . ok ( 'patternlab help coming soon' ) ;
2626 }
2727
28- function build ( ) {
28+ function printDebug ( ) {
29+ //debug file can be written by setting flag on package.json
30+ if ( patternlab . package . debug ) {
31+ var outputFilename = './patternlab.json' ;
32+ grunt . file . write ( outputFilename , JSON . stringify ( patternlab , null , 3 ) ) ;
33+ }
34+ }
2935
36+ function buildPatterns ( ) {
3037 patternlab . data = grunt . file . readJSON ( './source/_data/data.json' ) ;
3138 patternlab . listitems = grunt . file . readJSON ( './source/_data/listitems.json' ) ;
3239 patternlab . header = grunt . file . read ( './source/_patternlab-files/pattern-header-footer/header.html' ) ;
3340 patternlab . footer = grunt . file . read ( './source/_patternlab-files/pattern-header-footer/footer.html' ) ;
3441 patternlab . patterns = [ ] ;
3542 patternlab . patternIndex = [ ] ;
3643 patternlab . partials = { } ;
37- patternlab . buckets = [ ] ;
38- patternlab . bucketIndex = [ ] ;
39- patternlab . patternPaths = { } ;
40- patternlab . viewAllPaths = { } ;
4144
4245 grunt . file . recurse ( './source/_patterns' , function ( abspath , rootdir , subdir , filename ) {
4346 //check if the pattern already exists.
@@ -130,6 +133,14 @@ var plnode = function(grunt){
130133
131134 } ) ;
132135
136+ }
137+
138+ function buildFrontEnd ( ) {
139+ patternlab . buckets = [ ] ;
140+ patternlab . bucketIndex = [ ] ;
141+ patternlab . patternPaths = { } ;
142+ patternlab . viewAllPaths = { } ;
143+
133144 //build the styleguide
134145 var styleguideTemplate = grunt . file . read ( './source/_patternlab-files/styleguide.mustache' ) ;
135146 var styleguideHtml = mustache . render ( styleguideTemplate , { partials : patternlab . patterns } ) ;
@@ -294,56 +305,55 @@ var plnode = function(grunt){
294305 } ) ;
295306 grunt . file . write ( './public/index.html' , patternlabSiteHtml ) ;
296307
297- //debug file can be written by setting flag on package.json
298- if ( patternlab . package . debug ) {
299- var outputFilename = './patternlab.json' ;
300- grunt . file . write ( outputFilename , JSON . stringify ( patternlab , null , 3 ) ) ;
301- }
302-
303308 }
304309
305310 return {
306311 version : function ( ) {
307312 return getVersion ( ) ;
308313 } ,
309314 build : function ( ) {
310- build ( ) ;
315+ buildPatterns ( ) ;
316+ buildFrontEnd ( ) ;
317+ printDebug ( ) ;
318+
311319 } ,
312320 help : function ( ) {
313321 help ( ) ;
314322 } ,
315323 build_patterns_only : function ( ) {
316324 grunt . log . ok ( 'only_patterns argument not yet implemented' ) ;
325+ buildPatterns ( ) ;
326+ printDebug ( ) ;
317327 }
318328 } ;
319329
320330} ;
321331
322- module . exports = plnode ;
332+ module . exports = patternlab_engine ;
323333
324334module . exports = function ( grunt ) {
325335 grunt . registerTask ( 'patternlab' , 'create design systems with atomic design' , function ( arg ) {
326336
327- var pl = plnode ( grunt ) ;
337+ var patternlab = patternlab_engine ( grunt ) ;
328338
329339 if ( arguments . length === 0 ) {
330- pl . build ( ) ;
331- }
340+ patternlab . build ( ) ;
341+ }
332342
333343 if ( arg && arg === 'v' ) {
334- pl . version ( ) ;
335- }
344+ patternlab . version ( ) ;
345+ }
336346
337347 if ( arg && arg === "only_patterns" ) {
338- pl . build_patterns_only ( ) ;
348+ patternlab . build_patterns_only ( ) ;
339349 }
340350
341351 if ( arg && arg === "help" ) {
342- pl . help ( ) ;
352+ patternlab . help ( ) ;
343353 }
344354
345355 if ( arg && ( arg !== "v" && arg !== "only_patterns" ) ) {
346- pl . help ( ) ;
356+ patternlab . help ( ) ;
347357 }
348358
349359 } ) ;
0 commit comments