Skip to content

Commit cee0279

Browse files
committed
a decent start at a real Pattern Lab object class
1 parent 8b9e7d0 commit cee0279

File tree

1 file changed

+27
-18
lines changed

1 file changed

+27
-18
lines changed

core/lib/patternlab.js

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,31 @@ plutils.log.on('info', msg => console.log(msg));
4747
const patternEngines = require('./pattern_engines');
4848
const EventEmitter = require('events').EventEmitter;
4949

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+
5075
function buildPatternData(dataFilesPath, fsDep) {
5176
const dataFiles = glob.sync(dataFilesPath + '*.json', {"ignore" : [dataFilesPath + 'listitems.json']});
5277
let mergeObject = {};
@@ -183,22 +208,7 @@ function PatternLabEventEmitter() {
183208
inherits(PatternLabEventEmitter, EventEmitter);
184209

185210
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);
202212

203213
const paths = patternlab.config.paths;
204214

@@ -563,6 +573,7 @@ const patternlab_engine = function (config) {
563573
}
564574

565575
function buildPatterns(deletePatternDir) {
576+
patternlab.events.emit('patternlab-build-pattern-start', patternlab);
566577

567578
if (patternlab.config.debug) {
568579
console.log(
@@ -572,8 +583,6 @@ const patternlab_engine = function (config) {
572583
);
573584
}
574585

575-
patternlab.events.emit('patternlab-build-pattern-start', patternlab);
576-
577586
//
578587
// CHECK INCREMENTAL BUILD GRAPH
579588
//

0 commit comments

Comments
 (0)