Skip to content

Commit

Permalink
Merge pull request #451 from pattern-lab/dev
Browse files Browse the repository at this point in the history
Pattern Lab Node Core 2.4.4
  • Loading branch information
bmuenzenmeyer authored Aug 25, 2016
2 parents 3739152 + b79f5c1 commit 9529336
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 17 deletions.
21 changes: 17 additions & 4 deletions core/lib/patternlab.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*
* patternlab-node - v2.4.3 - 2016
* patternlab-node - v2.4.4 - 2016
*
* Brian Muenzenmeyer, Geoff Pursell, and the web community.
* Licensed under the MIT license.
*
* Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice.
* Licensed under the MIT license.
*
* Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice.
*
*/

Expand Down Expand Up @@ -339,6 +339,7 @@ var patternlab_engine = function (config) {
patternName: pattern.patternName,
patternPartial: pattern.patternPartial,
patternState: pattern.patternState,
patternEngineName: pattern.engine.engineName,
extraOutput: {}
});

Expand Down Expand Up @@ -375,17 +376,29 @@ var patternlab_engine = function (config) {
return getVersion();
},
build: function (callback, deletePatternDir) {
if (patternlab && patternlab.isBusy) {
console.log('Pattern Lab is busy building a previous run - returning early.');
return;
}
patternlab.isBusy = true;
buildPatterns(deletePatternDir);
new ui().buildFrontend(patternlab);
printDebug();
patternlab.isBusy = false;
callback();
},
help: function () {
help();
},
patternsonly: function (callback, deletePatternDir) {
if (patternlab && patternlab.isBusy) {
console.log('Pattern Lab is busy building a previous run - returning early.');
return;
}
patternlab.isBusy = true;
buildPatterns(deletePatternDir);
printDebug();
patternlab.isBusy = false;
callback();
},
liststarterkits: function () {
Expand Down
26 changes: 14 additions & 12 deletions core/lib/ui_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ var ui_builder = function () {
* @param pattern - the pattern to add
*/
function addToPatternPaths(patternlab, pattern) {
if (!patternlab.patternPaths) {
patternlab.patternPaths = {};
}

if (!patternlab.patternPaths[pattern.patternGroup]) {
patternlab.patternPaths[pattern.patternGroup] = {};
}
Expand All @@ -40,10 +36,6 @@ var ui_builder = function () {
* @param pattern - the pattern to add
*/
function addToViewAllPaths(patternlab, pattern) {
if (!patternlab.viewAllPaths) {
patternlab.viewAllPaths = {};
}

if (!patternlab.viewAllPaths[pattern.patternGroup]) {
patternlab.viewAllPaths[pattern.patternGroup] = {};
}
Expand Down Expand Up @@ -342,10 +334,6 @@ var ui_builder = function () {
patternGroups: {}
};

if (!patternlab.patternTypes) {
patternlab.patternTypes = [];
}

_.forEach(sortPatterns(patternlab.patterns), function (pattern) {

//ignore patterns we can omit from rendering directly
Expand Down Expand Up @@ -560,12 +548,23 @@ var ui_builder = function () {
writeFile(path.resolve(paths.public.annotations, 'annotations.js'), annotations);
}

/**
* Reset any global data we use between builds to guard against double adding things
*/
function resetUIBuilderState(patternlab) {
patternlab.patternPaths = {};
patternlab.viewAllPaths = {};
patternlab.patternTypes = [];
}

/**
* The main entry point for ui_builder
* @param patternlab - global data store
*/
function buildFrontend(patternlab) {

resetUIBuilderState(patternlab);

var paths = patternlab.config.paths;

//determine which patterns should be included in the front-end rendering
Expand Down Expand Up @@ -626,6 +625,9 @@ var ui_builder = function () {
},
groupPatterns: function (patternlab) {
return groupPatterns(patternlab);
},
resetUIBuilderState: function (patternlab) {
resetUIBuilderState(patternlab);
}
};

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "patternlab-node",
"description": "Pattern Lab is a collection of tools to help you create atomic design systems. This is the node command line interface (CLI).",
"version": "2.4.3",
"version": "2.4.4",
"main": "./core/lib/patternlab.js",
"dependencies": {
"diveSync": "^0.3.0",
Expand Down
23 changes: 23 additions & 0 deletions test/ui_builder_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ exports['ui_builder'] = {
new Pattern('patternType1/patternSubType2/grey.mustache'),
new Pattern('patternType1/patternSubType2/white.mustache')
);
ui.resetUIBuilderState(patternlab);

//act
var result = ui.groupPatterns(patternlab);
Expand Down Expand Up @@ -150,6 +151,7 @@ exports['ui_builder'] = {
new Pattern('patternType1/patternSubType2/grey.mustache'),
new Pattern('patternType1/patternSubType2/white.mustache')
);
ui.resetUIBuilderState(patternlab);

//act
var result = ui.groupPatterns(patternlab);
Expand Down Expand Up @@ -179,6 +181,7 @@ exports['ui_builder'] = {
new Pattern('patternType1/patternSubType2/grey.mustache'),
new Pattern('patternType1/patternSubType2/white.mustache')
);
ui.resetUIBuilderState(patternlab);

//act
var result = ui.groupPatterns(patternlab);
Expand Down Expand Up @@ -214,13 +217,33 @@ exports['ui_builder'] = {
new Pattern('patternType1/patternSubType2/grey.mustache'),
new Pattern('patternType1/patternSubType2/white.mustache')
);
ui.resetUIBuilderState(patternlab);

//act
var result = ui.groupPatterns(patternlab);

//assert
test.equals('todo', 'todo');

test.done();
},

'resetUIBuilderState - reset global objects' : function (test) {
//arrange
var patternlab = createFakePatternLab({
patternPaths: { foo: 1},
viewAllPaths: { bar: 2},
patternTypes: ['baz']
});

//act
ui.resetUIBuilderState(patternlab);

//assert
test.equals(patternlab.patternPaths.foo, undefined);
test.equals(patternlab.viewAllPaths.bar, undefined);
test.equals(patternlab.patternTypes.length, 0);

test.done();
}

Expand Down

0 comments on commit 9529336

Please sign in to comment.