@@ -47,6 +47,31 @@ plutils.log.on('info', msg => console.log(msg));
47
47
const patternEngines = require ( './pattern_engines' ) ;
48
48
const EventEmitter = require ( 'events' ) . EventEmitter ;
49
49
50
+ class PatternLab {
51
+ constructor ( config ) {
52
+ // Either use the config we were passed, or load one up from the config file ourselves
53
+ this . config = config || fs . readJSONSync ( path . resolve ( __dirname , '../../patternlab-config.json' ) ) ;
54
+ // Load up engines please
55
+ this . engines = patternEngines ;
56
+ this . engines . loadAllEngines ( config ) ;
57
+
58
+ // Cache the package.json in RAM
59
+ this . package = fs . readJSONSync ( path . resolve ( __dirname , '../../package.json' ) ) ;
60
+
61
+ // Make ye olde event emitter
62
+ this . events = new PatternLabEventEmitter ( ) ;
63
+
64
+ // Make a place for the pattern graph to sit
65
+ this . graph = null ;
66
+
67
+ // Verify correctness of configuration (?)
68
+ checkConfiguration ( this ) ;
69
+
70
+ // TODO: determine if this is the best place to wire up plugins
71
+ initializePlugins ( this ) ;
72
+ }
73
+ }
74
+
50
75
function buildPatternData ( dataFilesPath , fsDep ) {
51
76
const dataFiles = glob . sync ( dataFilesPath + '*.json' , { "ignore" : [ dataFilesPath + 'listitems.json' ] } ) ;
52
77
let mergeObject = { } ;
@@ -183,22 +208,7 @@ function PatternLabEventEmitter() {
183
208
inherits ( PatternLabEventEmitter , EventEmitter ) ;
184
209
185
210
const patternlab_engine = function ( config ) {
186
- const patternlab = { } ;
187
-
188
- patternlab . engines = patternEngines ;
189
- patternlab . engines . loadAllEngines ( config ) ;
190
-
191
- patternlab . package = fs . readJSONSync ( path . resolve ( __dirname , '../../package.json' ) ) ;
192
- patternlab . config = config || fs . readJSONSync ( path . resolve ( __dirname , '../../patternlab-config.json' ) ) ;
193
- patternlab . events = new PatternLabEventEmitter ( ) ;
194
-
195
- // Initialized when building
196
- patternlab . graph = null ;
197
-
198
- checkConfiguration ( patternlab ) ;
199
-
200
- //todo: determine if this is the best place to wire up plugins
201
- initializePlugins ( patternlab ) ;
211
+ const patternlab = new PatternLab ( config ) ;
202
212
203
213
const paths = patternlab . config . paths ;
204
214
@@ -563,6 +573,7 @@ const patternlab_engine = function (config) {
563
573
}
564
574
565
575
function buildPatterns ( deletePatternDir ) {
576
+ patternlab . events . emit ( 'patternlab-build-pattern-start' , patternlab ) ;
566
577
567
578
if ( patternlab . config . debug ) {
568
579
console . log (
@@ -572,8 +583,6 @@ const patternlab_engine = function (config) {
572
583
) ;
573
584
}
574
585
575
- patternlab . events . emit ( 'patternlab-build-pattern-start' , patternlab ) ;
576
-
577
586
//
578
587
// CHECK INCREMENTAL BUILD GRAPH
579
588
//
0 commit comments