Skip to content

Commit 3a1a92a

Browse files
Merge pull request #655 from pattern-lab/dev
Pattern Lab Node Core 2.9.2
2 parents 1fc695a + 579cc98 commit 3a1a92a

15 files changed

+156
-17
lines changed

core/lib/patternlab.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* patternlab-node - v2.9.1 - 2017
2+
* patternlab-node - v2.9.2 - 2017
33
*
44
* Brian Muenzenmeyer, Geoff Pursell, Raphael Okon, tburny and the web community.
55
* Licensed under the MIT license.
@@ -22,6 +22,10 @@ var diveSync = require('diveSync'),
2222
packageInfo = require('../../package.json'),
2323
plutils = require('./utilities'),
2424
jsonCopy = require('./json_copy'),
25+
ui = require('./ui_builder'),
26+
ui_builder = new ui(),
27+
pe = require('./pattern_exporter'),
28+
pattern_exporter = new pe(),
2529
PatternGraph = require('./pattern_graph').PatternGraph;
2630

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

150154
var pa = require('./pattern_assembler'),
151-
pe = require('./pattern_exporter'),
152155
lh = require('./lineage_hunter'),
153-
ui = require('./ui_builder'),
154156
sm = require('./starterkit_manager'),
155157
Pattern = require('./object_factory').Pattern,
156158
CompileState = require('./object_factory').CompileState,
@@ -159,7 +161,6 @@ var patternlab_engine = function (config) {
159161
patternlab.engines = patternEngines;
160162

161163
var pattern_assembler = new pa(),
162-
pattern_exporter = new pe(),
163164
lineage_hunter = new lh();
164165

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

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

532+
//now that all the main patterns are known, look for any links that might be within data and expand them
533+
//we need to do this before expanding patterns & partials into extendedTemplates, otherwise we could lose the data -> partial reference
534+
pattern_assembler.parse_data_links(patternlab);
535+
531536
//diveSync again to recursively include partials, filling out the
532537
//extendedTemplate property of the patternlab.patterns elements
533538
// TODO we can reduce the time needed by only processing changed patterns and their partials
@@ -537,10 +542,6 @@ var patternlab_engine = function (config) {
537542
processHeadPattern();
538543
processFootPattern();
539544

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

@@ -580,7 +581,6 @@ var patternlab_engine = function (config) {
580581
}
581582
}
582583

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

@@ -606,7 +606,7 @@ var patternlab_engine = function (config) {
606606
}
607607
patternlab.isBusy = true;
608608
buildPatterns(deletePatternDir);
609-
new ui().buildFrontend(patternlab);
609+
ui_builder.buildFrontend(patternlab);
610610
printDebug();
611611
patternlab.isBusy = false;
612612
callback();

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "patternlab-node",
33
"description": "Pattern Lab is a collection of tools to help you create atomic design systems. This is the node command line interface (CLI).",
4-
"version": "2.9.1",
4+
"version": "2.9.2",
55
"main": "./core/lib/patternlab.js",
66
"dependencies": {
77
"chalk": "^1.1.3",

test/files/_data/listitems.json

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
{
2-
"test_list_item" : "izzn thizzle"
2+
"1": {
3+
"title": "Nullizzle shizznit velizzle, hizzle, suscipit own yo', gravida vizzle, arcu."
4+
},
5+
"2": {
6+
"title": "Veggies sunt bona vobis, proinde vos postulo"
7+
},
8+
"3": {
9+
"title": "Bacon ipsum dolor sit amet turducken strip steak beef ribs shank"
10+
}
311
}
4-

test/files/_meta/_00-head.mustache

Whitespace-only changes.

test/files/_meta/_01-foot.mustache

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<div class="{{styleModifier}}">
2+
{{> test-link }}
3+
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"url" : "link.test-foo"
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{{> test-paramMiddle(styleModifier: "foo") }}

test/files/partials/general-footer.mustache

Whitespace-only changes.

test/files/partials/general-header.mustache

Whitespace-only changes.

test/files/partials/patternSection.mustache

Whitespace-only changes.

test/files/partials/patternSectionSubtype.mustache

Whitespace-only changes.

test/files/viewall.mustache

Whitespace-only changes.

test/patternlab_tests.js

+62-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,73 @@
11
'use strict';
22

3-
var tap = require('tap');
3+
const tap = require('tap');
4+
const rewire = require("rewire");
5+
const _ = require('lodash');
6+
const fs = require('fs-extra');
7+
var config = require('./util/patternlab-config.json');
8+
9+
var plEngineModule = rewire('../core/lib/patternlab');
10+
11+
//set up a global mocks - we don't want to be writing/rendering any files right now
12+
const uiBuilderMock = {
13+
buildFrontend: function (patternlab) { }
14+
};
15+
16+
const fsMock = {
17+
outputFileSync: function (path, content) { /* INTENTIONAL NOOP */},
18+
readJSONSync: function(path, encoding) {
19+
return fs.readJSONSync(path, encoding);
20+
},
21+
removeSync: function(path) { fs.removeSync(path); },
22+
emptyDirSync: function(path) { fs.emptyDirSync(path); },
23+
readFileSync: function(path, encoding) { return fs.readFileSync(path, encoding); },
24+
}
25+
26+
//set our mocks in place of usual require()
27+
plEngineModule.__set__({
28+
'ui_builder': uiBuilderMock,
29+
'fs': fsMock
30+
});
431

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

10-
var dataResult = plMain.build_pattern_data(data_dir, fs);
35+
var dataResult = plEngineModule.build_pattern_data(data_dir, fs);
1136
test.equals(dataResult.data, "test");
1237
test.equals(dataResult.foo, "bar");
1338
test.equals(dataResult.test_list_item, undefined);
1439
test.end();
1540
});
41+
42+
tap.test('buildPatterns - should replace data link even when pattern parameter present', function(test) {
43+
//arrange
44+
45+
var patternExporterMock = {
46+
/*
47+
In this test, we actually take advantage of the pattern export functionality post-build to inspect what
48+
the contents of the patterns look like. This, coupled with a mocking of fs and the ui_builder, allow us to focus
49+
only on the order of events within build.
50+
*/
51+
export_patterns: function (patternlab) {
52+
var pattern = _.find(patternlab.patterns, (pattern) => {
53+
return pattern.patternPartial === 'test-paramParent';
54+
});
55+
//assert
56+
test.equals(pattern.patternPartialCode.indexOf('00-test-00-foo.rendered.html') > -1, true, 'data link should be replaced properly');
57+
}
58+
};
59+
60+
plEngineModule.__set__({
61+
'pattern_exporter': patternExporterMock
62+
});
63+
64+
config.patternExportPatternPartials = ['test-paramParent'];
65+
var pl = new plEngineModule(config);
66+
67+
//act
68+
pl.build(function() {
69+
test.end();
70+
}, true);
71+
72+
73+
});

test/util/patternlab-config.json

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
{
2+
"paths" : {
3+
"source" : {
4+
"root": "./test/files/",
5+
"patterns" : "./test/files/_patterns/",
6+
"data" : "./test/files/_data/",
7+
"meta": "./test/files/_meta/",
8+
"styleguide" : "./test/files/styleguide/",
9+
"patternlabFiles" : "./test/files/",
10+
"js" : "./test/files/js",
11+
"images" : "./test/files/images",
12+
"fonts" : "./test/files/fonts",
13+
"css" : "./test/files/css/"
14+
},
15+
"public" : {
16+
"root" : "./test/public/",
17+
"patterns" : "./test/public/patterns/",
18+
"data" : "./test/public/data/",
19+
"styleguide" : "./test/public/styleguide/",
20+
"js" : "./test/public/js",
21+
"images" : "./test/public/images",
22+
"fonts" : "./test/public/fonts",
23+
"css" : "./test/public/css"
24+
}
25+
},
26+
"styleGuideExcludes": [
27+
"templates",
28+
"pages"
29+
],
30+
"defaultPattern": "all",
31+
"ignored-extensions" : ["scss", "DS_Store", "less"],
32+
"ignored-directories" : ["scss"],
33+
"debug": false,
34+
"ishControlsHide": {
35+
"s": false,
36+
"m": false,
37+
"l": false,
38+
"full": false,
39+
"random": false,
40+
"disco": false,
41+
"hay": true,
42+
"mqs": false,
43+
"find": false,
44+
"views-all": false,
45+
"views-annotations": false,
46+
"views-code": false,
47+
"views-new": false,
48+
"tools-all": false,
49+
"tools-docs": false
50+
},
51+
"ishMinimum": "240",
52+
"ishMaximum": "2600",
53+
"patternStateCascade": ["inprogress", "inreview", "complete"],
54+
"patternStates": {
55+
},
56+
"patternExportPatternPartials": [],
57+
"patternExportDirectory": "./pattern_exports/",
58+
"cacheBust": true,
59+
"outputFileSuffixes": {
60+
"rendered": ".rendered",
61+
"rawTemplate": "",
62+
"markupOnly": ".markup-only"
63+
},
64+
"cleanOutputHtml": true,
65+
"exportToGraphViz": false,
66+
"cleanPublic": true
67+
}

0 commit comments

Comments
 (0)