Skip to content

Commit

Permalink
Merge pull request #655 from pattern-lab/dev
Browse files Browse the repository at this point in the history
Pattern Lab Node Core 2.9.2
  • Loading branch information
bmuenzenmeyer authored Apr 27, 2017
2 parents 1fc695a + 579cc98 commit 3a1a92a
Show file tree
Hide file tree
Showing 15 changed files with 156 additions and 17 deletions.
20 changes: 10 additions & 10 deletions core/lib/patternlab.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* patternlab-node - v2.9.1 - 2017
* patternlab-node - v2.9.2 - 2017
*
* Brian Muenzenmeyer, Geoff Pursell, Raphael Okon, tburny and the web community.
* Licensed under the MIT license.
Expand All @@ -22,6 +22,10 @@ var diveSync = require('diveSync'),
packageInfo = require('../../package.json'),
plutils = require('./utilities'),
jsonCopy = require('./json_copy'),
ui = require('./ui_builder'),
ui_builder = new ui(),
pe = require('./pattern_exporter'),
pattern_exporter = new pe(),
PatternGraph = require('./pattern_graph').PatternGraph;

//register our log events
Expand Down Expand Up @@ -148,9 +152,7 @@ var patternlab_engine = function (config) {
'use strict';

var pa = require('./pattern_assembler'),
pe = require('./pattern_exporter'),
lh = require('./lineage_hunter'),
ui = require('./ui_builder'),
sm = require('./starterkit_manager'),
Pattern = require('./object_factory').Pattern,
CompileState = require('./object_factory').CompileState,
Expand All @@ -159,7 +161,6 @@ var patternlab_engine = function (config) {
patternlab.engines = patternEngines;

var pattern_assembler = new pa(),
pattern_exporter = new pe(),
lineage_hunter = new lh();

patternlab.package = fs.readJSONSync(path.resolve(__dirname, '../../package.json'));
Expand Down Expand Up @@ -528,6 +529,10 @@ var patternlab_engine = function (config) {

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

//now that all the main patterns are known, look for any links that might be within data and expand them
//we need to do this before expanding patterns & partials into extendedTemplates, otherwise we could lose the data -> partial reference
pattern_assembler.parse_data_links(patternlab);

//diveSync again to recursively include partials, filling out the
//extendedTemplate property of the patternlab.patterns elements
// TODO we can reduce the time needed by only processing changed patterns and their partials
Expand All @@ -537,10 +542,6 @@ var patternlab_engine = function (config) {
processHeadPattern();
processFootPattern();

//now that all the main patterns are known, look for any links that might be within data and expand them
//we need to do this before expanding patterns & partials into extendedTemplates, otherwise we could lose the data -> partial reference
pattern_assembler.parse_data_links(patternlab);

//cascade any patternStates
lineage_hunter.cascade_pattern_states(patternlab);

Expand Down Expand Up @@ -580,7 +581,6 @@ var patternlab_engine = function (config) {
}
}


//render all patterns last, so lineageR works
patternsToBuild.forEach(pattern => renderSinglePattern(pattern, head));

Expand All @@ -606,7 +606,7 @@ var patternlab_engine = function (config) {
}
patternlab.isBusy = true;
buildPatterns(deletePatternDir);
new ui().buildFrontend(patternlab);
ui_builder.buildFrontend(patternlab);
printDebug();
patternlab.isBusy = false;
callback();
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.9.1",
"version": "2.9.2",
"main": "./core/lib/patternlab.js",
"dependencies": {
"chalk": "^1.1.3",
Expand Down
11 changes: 9 additions & 2 deletions test/files/_data/listitems.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
{
"test_list_item" : "izzn thizzle"
"1": {
"title": "Nullizzle shizznit velizzle, hizzle, suscipit own yo', gravida vizzle, arcu."
},
"2": {
"title": "Veggies sunt bona vobis, proinde vos postulo"
},
"3": {
"title": "Bacon ipsum dolor sit amet turducken strip steak beef ribs shank"
}
}

Empty file.
Empty file.
3 changes: 3 additions & 0 deletions test/files/_patterns/00-test/paramMiddle.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class="{{styleModifier}}">
{{> test-link }}
</div>
3 changes: 3 additions & 0 deletions test/files/_patterns/00-test/paramParent.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"url" : "link.test-foo"
}
1 change: 1 addition & 0 deletions test/files/_patterns/00-test/paramParent.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{> test-paramMiddle(styleModifier: "foo") }}
Empty file.
Empty file.
Empty file.
Empty file.
Empty file added test/files/viewall.mustache
Empty file.
66 changes: 62 additions & 4 deletions test/patternlab_tests.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,73 @@
'use strict';

var tap = require('tap');
const tap = require('tap');
const rewire = require("rewire");
const _ = require('lodash');
const fs = require('fs-extra');
var config = require('./util/patternlab-config.json');

var plEngineModule = rewire('../core/lib/patternlab');

//set up a global mocks - we don't want to be writing/rendering any files right now
const uiBuilderMock = {
buildFrontend: function (patternlab) { }
};

const fsMock = {
outputFileSync: function (path, content) { /* INTENTIONAL NOOP */},
readJSONSync: function(path, encoding) {
return fs.readJSONSync(path, encoding);
},
removeSync: function(path) { fs.removeSync(path); },
emptyDirSync: function(path) { fs.emptyDirSync(path); },
readFileSync: function(path, encoding) { return fs.readFileSync(path, encoding); },
}

//set our mocks in place of usual require()
plEngineModule.__set__({
'ui_builder': uiBuilderMock,
'fs': fsMock
});

tap.test('buildPatternData - should merge all JSON files in the data folder except listitems', function(test){
var fs = require('fs-extra');
var plMain = require('../core/lib/patternlab');
var data_dir = './test/files/_data/';

var dataResult = plMain.build_pattern_data(data_dir, fs);
var dataResult = plEngineModule.build_pattern_data(data_dir, fs);
test.equals(dataResult.data, "test");
test.equals(dataResult.foo, "bar");
test.equals(dataResult.test_list_item, undefined);
test.end();
});

tap.test('buildPatterns - should replace data link even when pattern parameter present', function(test) {
//arrange

var patternExporterMock = {
/*
In this test, we actually take advantage of the pattern export functionality post-build to inspect what
the contents of the patterns look like. This, coupled with a mocking of fs and the ui_builder, allow us to focus
only on the order of events within build.
*/
export_patterns: function (patternlab) {
var pattern = _.find(patternlab.patterns, (pattern) => {
return pattern.patternPartial === 'test-paramParent';
});
//assert
test.equals(pattern.patternPartialCode.indexOf('00-test-00-foo.rendered.html') > -1, true, 'data link should be replaced properly');
}
};

plEngineModule.__set__({
'pattern_exporter': patternExporterMock
});

config.patternExportPatternPartials = ['test-paramParent'];
var pl = new plEngineModule(config);

//act
pl.build(function() {
test.end();
}, true);


});
67 changes: 67 additions & 0 deletions test/util/patternlab-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"paths" : {
"source" : {
"root": "./test/files/",
"patterns" : "./test/files/_patterns/",
"data" : "./test/files/_data/",
"meta": "./test/files/_meta/",
"styleguide" : "./test/files/styleguide/",
"patternlabFiles" : "./test/files/",
"js" : "./test/files/js",
"images" : "./test/files/images",
"fonts" : "./test/files/fonts",
"css" : "./test/files/css/"
},
"public" : {
"root" : "./test/public/",
"patterns" : "./test/public/patterns/",
"data" : "./test/public/data/",
"styleguide" : "./test/public/styleguide/",
"js" : "./test/public/js",
"images" : "./test/public/images",
"fonts" : "./test/public/fonts",
"css" : "./test/public/css"
}
},
"styleGuideExcludes": [
"templates",
"pages"
],
"defaultPattern": "all",
"ignored-extensions" : ["scss", "DS_Store", "less"],
"ignored-directories" : ["scss"],
"debug": false,
"ishControlsHide": {
"s": false,
"m": false,
"l": false,
"full": false,
"random": false,
"disco": false,
"hay": true,
"mqs": false,
"find": false,
"views-all": false,
"views-annotations": false,
"views-code": false,
"views-new": false,
"tools-all": false,
"tools-docs": false
},
"ishMinimum": "240",
"ishMaximum": "2600",
"patternStateCascade": ["inprogress", "inreview", "complete"],
"patternStates": {
},
"patternExportPatternPartials": [],
"patternExportDirectory": "./pattern_exports/",
"cacheBust": true,
"outputFileSuffixes": {
"rendered": ".rendered",
"rawTemplate": "",
"markupOnly": ".markup-only"
},
"cleanOutputHtml": true,
"exportToGraphViz": false,
"cleanPublic": true
}

0 comments on commit 3a1a92a

Please sign in to comment.