Skip to content

Commit

Permalink
event emitter and initial events for end to end test of plugin-node-tab
Browse files Browse the repository at this point in the history
as part of #432
  • Loading branch information
bmuenzenmeyer committed Sep 11, 2016
1 parent d087d99 commit 93a4bc6
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 8 deletions.
7 changes: 6 additions & 1 deletion core/lib/object_factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,19 @@ Pattern.prototype = {
// calculated path from the root of the public directory to the generated html
// file for this pattern.
// Should look something like '00-atoms-00-global-00-colors/00-atoms-00-global-00-colors.html'
getPatternLink: function (patternlab, suffixType) {
getPatternLink: function (patternlab, suffixType, customfileExtension) {
// if no suffixType is provided, we default to rendered
var suffixConfig = patternlab.config.outputFileSuffixes;
var suffix = suffixType ? suffixConfig[suffixType] : suffixConfig.rendered;

if (suffixType === 'rawTemplate') {
return this.name + path.sep + this.name + suffix + this.fileExtension;
}

if (suffixType === 'custom') {
return this.name + path.sep + this.name + customfileExtension;
}

return this.name + path.sep + this.name + suffix + '.html';
},

Expand Down
22 changes: 22 additions & 0 deletions core/lib/patternlab.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ var diveSync = require('diveSync'),
glob = require('glob'),
_ = require('lodash'),
path = require('path'),
inherits = require('util').inherits,
pm = require('./plugin_manager'),
plutils = require('./utilities');

var EventEmitter = require('events').EventEmitter;

function buildPatternData(dataFilesPath, fs) {
var dataFilesPath = dataFilesPath;
var dataFiles = glob.sync(dataFilesPath + '*.json', {"ignore" : [dataFilesPath + 'listitems.json']});
Expand Down Expand Up @@ -88,6 +91,11 @@ function initializePlugins(patternlab) {
}
}

function PatternLabEventEmitter() {
EventEmitter.call(this);
}
inherits(PatternLabEventEmitter, EventEmitter);

var patternlab_engine = function (config) {
'use strict';

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

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

checkConfiguration(patternlab);

//todo: determine if this is the best place to wire up plugins
initializePlugins(patternlab);

var paths = patternlab.config.paths;
Expand Down Expand Up @@ -207,6 +218,9 @@ var patternlab_engine = function (config) {
}

function buildPatterns(deletePatternDir) {

patternlab.events.emit('patternlab-build-pattern-start', patternlab);

try {
patternlab.data = buildPatternData(paths.source.data, fs);
} catch (ex) {
Expand Down Expand Up @@ -244,9 +258,13 @@ var patternlab_engine = function (config) {

pattern_assembler.combine_listItems(patternlab);

patternlab.events.emit('patternlab-build-global-data-end', patternlab);

// diveSync once to perform iterative populating of patternlab object
processAllPatternsIterative(pattern_assembler, patterns_dir, patternlab);

patternlab.events.emit('patternlab-pattern-iteration-end', patternlab);

//diveSync again to recursively include partials, filling out the
//extendedTemplate property of the patternlab.patterns elements
processAllPatternsRecursive(pattern_assembler, patterns_dir, patternlab);
Expand Down Expand Up @@ -369,6 +387,8 @@ var patternlab_engine = function (config) {
patternLabFoot : footerPartial
});

patternlab.events.emit('patternlab-pattern-write-begin', patternlab, pattern);

//write the compiled template to the public patterns directory
var patternPage = headHTML + pattern.patternPartialCode + footerHTML;
fs.outputFileSync(paths.public.patterns + pattern.getPatternLink(patternlab, 'rendered'), patternPage);
Expand All @@ -379,6 +399,8 @@ var patternlab_engine = function (config) {
//write the encoded version too
fs.outputFileSync(paths.public.patterns + pattern.getPatternLink(patternlab, 'markupOnly'), pattern.patternPartialCode);

patternlab.events.emit('patternlab-pattern-write-end', patternlab, pattern);

return true;
});

Expand Down
7 changes: 6 additions & 1 deletion core/lib/plugin_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,13 @@ var plugin_manager = function (config, configPath) {

//write config entry back
var diskConfig = fs.readJSONSync(path.resolve(configPath), 'utf8');
diskConfig[pluginName] = true;
diskConfig[pluginName] = false;
fs.outputFileSync(path.resolve(configPath), JSON.stringify(diskConfig, null, 2));

util.logGreen('Plugin ' + pluginName + ' installed.');

//todo, tell them how to uninstall or disable

}
} catch (ex) {
console.log(ex);
Expand Down
4 changes: 2 additions & 2 deletions core/lib/ui_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -532,8 +532,8 @@ var ui_builder = function () {
//viewAllPaths
output += 'var viewAllPaths = ' + JSON.stringify(patternlab.viewAllPaths) + ';' + eol;

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

//smaller config elements
output += 'var defaultShowPatternInfo = ' + (patternlab.config.defaultShowPatternInfo ? patternlab.config.defaultShowPatternInfo : 'false') + ';' + eol;
Expand Down
4 changes: 0 additions & 4 deletions core/scripts/postinstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ try{
}
}





u.logGreen('Pattern Lab postinstall complete.');

} catch (ex) {
Expand Down

0 comments on commit 93a4bc6

Please # to comment.