Skip to content

Commit 93a4bc6

Browse files
committed
event emitter and initial events for end to end test of plugin-node-tab
as part of #432
1 parent d087d99 commit 93a4bc6

File tree

5 files changed

+36
-8
lines changed

5 files changed

+36
-8
lines changed

core/lib/object_factory.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,19 @@ Pattern.prototype = {
8787
// calculated path from the root of the public directory to the generated html
8888
// file for this pattern.
8989
// Should look something like '00-atoms-00-global-00-colors/00-atoms-00-global-00-colors.html'
90-
getPatternLink: function (patternlab, suffixType) {
90+
getPatternLink: function (patternlab, suffixType, customfileExtension) {
9191
// if no suffixType is provided, we default to rendered
9292
var suffixConfig = patternlab.config.outputFileSuffixes;
9393
var suffix = suffixType ? suffixConfig[suffixType] : suffixConfig.rendered;
9494

9595
if (suffixType === 'rawTemplate') {
9696
return this.name + path.sep + this.name + suffix + this.fileExtension;
9797
}
98+
99+
if (suffixType === 'custom') {
100+
return this.name + path.sep + this.name + customfileExtension;
101+
}
102+
98103
return this.name + path.sep + this.name + suffix + '.html';
99104
},
100105

core/lib/patternlab.js

+22
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@ var diveSync = require('diveSync'),
1414
glob = require('glob'),
1515
_ = require('lodash'),
1616
path = require('path'),
17+
inherits = require('util').inherits,
1718
pm = require('./plugin_manager'),
1819
plutils = require('./utilities');
1920

21+
var EventEmitter = require('events').EventEmitter;
22+
2023
function buildPatternData(dataFilesPath, fs) {
2124
var dataFilesPath = dataFilesPath;
2225
var dataFiles = glob.sync(dataFilesPath + '*.json', {"ignore" : [dataFilesPath + 'listitems.json']});
@@ -88,6 +91,11 @@ function initializePlugins(patternlab) {
8891
}
8992
}
9093

94+
function PatternLabEventEmitter() {
95+
EventEmitter.call(this);
96+
}
97+
inherits(PatternLabEventEmitter, EventEmitter);
98+
9199
var patternlab_engine = function (config) {
92100
'use strict';
93101

@@ -102,8 +110,11 @@ var patternlab_engine = function (config) {
102110

103111
patternlab.package = fs.readJSONSync(path.resolve(__dirname, '../../package.json'));
104112
patternlab.config = config || fs.readJSONSync(path.resolve(__dirname, '../../patternlab-config.json'));
113+
patternlab.events = new PatternLabEventEmitter();
105114

106115
checkConfiguration(patternlab);
116+
117+
//todo: determine if this is the best place to wire up plugins
107118
initializePlugins(patternlab);
108119

109120
var paths = patternlab.config.paths;
@@ -207,6 +218,9 @@ var patternlab_engine = function (config) {
207218
}
208219

209220
function buildPatterns(deletePatternDir) {
221+
222+
patternlab.events.emit('patternlab-build-pattern-start', patternlab);
223+
210224
try {
211225
patternlab.data = buildPatternData(paths.source.data, fs);
212226
} catch (ex) {
@@ -244,9 +258,13 @@ var patternlab_engine = function (config) {
244258

245259
pattern_assembler.combine_listItems(patternlab);
246260

261+
patternlab.events.emit('patternlab-build-global-data-end', patternlab);
262+
247263
// diveSync once to perform iterative populating of patternlab object
248264
processAllPatternsIterative(pattern_assembler, patterns_dir, patternlab);
249265

266+
patternlab.events.emit('patternlab-pattern-iteration-end', patternlab);
267+
250268
//diveSync again to recursively include partials, filling out the
251269
//extendedTemplate property of the patternlab.patterns elements
252270
processAllPatternsRecursive(pattern_assembler, patterns_dir, patternlab);
@@ -369,6 +387,8 @@ var patternlab_engine = function (config) {
369387
patternLabFoot : footerPartial
370388
});
371389

390+
patternlab.events.emit('patternlab-pattern-write-begin', patternlab, pattern);
391+
372392
//write the compiled template to the public patterns directory
373393
var patternPage = headHTML + pattern.patternPartialCode + footerHTML;
374394
fs.outputFileSync(paths.public.patterns + pattern.getPatternLink(patternlab, 'rendered'), patternPage);
@@ -379,6 +399,8 @@ var patternlab_engine = function (config) {
379399
//write the encoded version too
380400
fs.outputFileSync(paths.public.patterns + pattern.getPatternLink(patternlab, 'markupOnly'), pattern.patternPartialCode);
381401

402+
patternlab.events.emit('patternlab-pattern-write-end', patternlab, pattern);
403+
382404
return true;
383405
});
384406

core/lib/plugin_manager.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,13 @@ var plugin_manager = function (config, configPath) {
2727

2828
//write config entry back
2929
var diskConfig = fs.readJSONSync(path.resolve(configPath), 'utf8');
30-
diskConfig[pluginName] = true;
30+
diskConfig[pluginName] = false;
3131
fs.outputFileSync(path.resolve(configPath), JSON.stringify(diskConfig, null, 2));
32+
33+
util.logGreen('Plugin ' + pluginName + ' installed.');
34+
35+
//todo, tell them how to uninstall or disable
36+
3237
}
3338
} catch (ex) {
3439
console.log(ex);

core/lib/ui_builder.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -532,8 +532,8 @@ var ui_builder = function () {
532532
//viewAllPaths
533533
output += 'var viewAllPaths = ' + JSON.stringify(patternlab.viewAllPaths) + ';' + eol;
534534

535-
//plugins someday
536-
output += 'var plugins = [];' + eol;
535+
//plugins
536+
output += 'var plugins = ' + JSON.stringify(patternlab.plugins) + ';' + eol;
537537

538538
//smaller config elements
539539
output += 'var defaultShowPatternInfo = ' + (patternlab.config.defaultShowPatternInfo ? patternlab.config.defaultShowPatternInfo : 'false') + ';' + eol;

core/scripts/postinstall.js

-4
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@ try{
3636
}
3737
}
3838

39-
40-
41-
42-
4339
u.logGreen('Pattern Lab postinstall complete.');
4440

4541
} catch (ex) {

0 commit comments

Comments
 (0)