Skip to content

Commit 125f1fd

Browse files
HydranerHydranerbmuenzenmeyerJosefBredereck
authored
Make sure every uikit is going to be reset when the frontend is build. (#1139)
* Make sure every uikit is going to be reset when the frontend is built. * Make export data uikit sensible. * #1139: Fix failing tests Co-authored-by: Hydraner <drupal@pascalcrott.del> Co-authored-by: Brian Muenzenmeyer <brian.muenzenmeyer@gmail.com> Co-authored-by: Josef Bredreck <slime.games@outlook.de>
1 parent 7763bed commit 125f1fd

File tree

5 files changed

+76
-48
lines changed

5 files changed

+76
-48
lines changed

packages/core/src/lib/exportData.js

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
'use strict';
22

3-
const eol = require('os').EOL;
43
const path = require('path');
5-
const _ = require('lodash');
4+
const eol = require('os').EOL;
65

76
const ae = require('./annotation_exporter');
87

@@ -12,7 +11,7 @@ let fs = require('fs-extra'); //eslint-disable-line prefer-const
1211
* Write out our pattern information for use by the front end
1312
* @param patternlab - global data store
1413
*/
15-
module.exports = function(patternlab) {
14+
module.exports = function(patternlab, uikit) {
1615
const annotation_exporter = new ae(patternlab);
1716

1817
const paths = patternlab.config.paths;
@@ -71,42 +70,38 @@ module.exports = function(patternlab) {
7170
const annotationsJSON = annotation_exporter.gather();
7271
const annotations =
7372
'var comments = { "comments" : ' + JSON.stringify(annotationsJSON) + '};';
74-
_.each(patternlab.uikits, uikit => {
75-
fs.outputFileSync(
76-
path.resolve(
77-
path.join(
78-
process.cwd(),
79-
uikit.outputDir,
80-
paths.public.annotations,
81-
'annotations.js'
82-
)
83-
),
84-
annotations
85-
);
86-
});
73+
fs.outputFileSync(
74+
path.resolve(
75+
path.join(
76+
process.cwd(),
77+
uikit.outputDir,
78+
paths.public.annotations,
79+
'annotations.js'
80+
)
81+
),
82+
annotations
83+
);
8784

8885
// add module.export to the Nodejs-specific file generated.
8986
const exportedOutput =
9087
output +
9188
'module.exports = { config, ishControls, navItems, patternPaths, viewAllPaths, plugins, defaultShowPatternInfo, defaultPattern };';
9289

9390
//write all output to patternlab-data
94-
_.each(patternlab.uikits, uikit => {
95-
fs.outputFileSync(
96-
path.resolve(
97-
path.join(process.cwd(), uikit.outputDir, paths.public.data),
98-
'patternlab-data.js'
99-
),
100-
output
101-
);
102-
fs.outputFileSync(
103-
path.resolve(
104-
path.join(process.cwd(), uikit.outputDir, paths.public.data),
105-
'patternlab-data.cjs.js'
106-
),
107-
exportedOutput
108-
);
109-
});
91+
fs.outputFileSync(
92+
path.resolve(
93+
path.join(process.cwd(), uikit.outputDir, paths.public.data),
94+
'patternlab-data.js'
95+
),
96+
output
97+
);
98+
fs.outputFileSync(
99+
path.resolve(
100+
path.join(process.cwd(), uikit.outputDir, paths.public.data),
101+
'patternlab-data.cjs.js'
102+
),
103+
exportedOutput
104+
);
110105

111106
return output;
112107
};

packages/core/src/lib/ui_builder.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -755,17 +755,18 @@ const ui_builder = function() {
755755

756756
/**
757757
* The main entry point for ui_builder
758-
*
759-
* @param patternlab - global data store
758+
* @param patternlabGlobal - global data store
760759
* @returns {Promise} a promise fulfilled when build is complete
761760
*/
762-
function buildFrontend(patternlab) {
763-
resetUIBuilderState(patternlab);
761+
function buildFrontend(patternlabGlobal) {
762+
const paths = patternlabGlobal.config.paths;
764763

765-
const paths = patternlab.config.paths;
764+
const uikitPromises = _.map(patternlabGlobal.uikits, uikit => {
765+
//we need to make sure the patternlab object gets manipulated per uikit
766+
const patternlab = Object.assign({}, patternlabGlobal);
766767

767-
const uikitPromises = _.map(patternlab.uikits, uikit => {
768-
// determine which patterns should be included in the front-end rendering
768+
resetUIBuilderState(patternlab);
769+
//determine which patterns should be included in the front-end rendering
769770
const styleguidePatterns = groupPatterns(patternlab, uikit);
770771

771772
return new Promise(resolve => {
@@ -891,8 +892,8 @@ const ui_builder = function() {
891892
patternlabSiteHtml
892893
);
893894

894-
// write out patternlab.data object to be read by the client
895-
exportData(patternlab);
895+
//write out patternlab.data object to be read by the client
896+
exportData(patternlab, uikit);
896897
resolve();
897898
})
898899
.catch(reason => {

packages/core/test/exportData_tests.js

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,48 +20,77 @@ exportData.__set__({
2020
fs: fsMock,
2121
});
2222

23-
const patternlab = util.fakePatternLab(testPatternsPath);
24-
const result = exportData(patternlab);
23+
const uikitFoo = {
24+
name: 'uikit-foo',
25+
enabled: true,
26+
outputDir: 'foo',
27+
excludedPatternStates: ['legacy'],
28+
excludedTags: ['baz'],
29+
};
2530

2631
tap.test('exportData exports config', function(test) {
32+
const patternlab = util.fakePatternLab(testPatternsPath);
33+
const result = exportData(patternlab, uikitFoo);
34+
2735
test.equals(result.indexOf('config') > -1, true);
2836
test.equals(result.indexOf('paths') > -1, true);
2937
test.equals(result.indexOf('theme') > -1, true);
3038
test.end();
3139
});
3240

3341
tap.test('exportData exports ishControls', function(test) {
42+
const patternlab = util.fakePatternLab(testPatternsPath);
43+
const result = exportData(patternlab, uikitFoo);
44+
3445
test.equals(result.indexOf('ishControlsHide') > -1, true);
3546
test.end();
3647
});
3748

3849
tap.test('exportData exports navItems', function(test) {
50+
const patternlab = util.fakePatternLab(testPatternsPath);
51+
const result = exportData(patternlab, uikitFoo);
52+
3953
test.equals(result.indexOf('patternTypes') > -1, true);
4054
test.end();
4155
});
4256

4357
tap.test('exportData exports patternPaths', function(test) {
58+
const patternlab = util.fakePatternLab(testPatternsPath);
59+
const result = exportData(patternlab, uikitFoo);
60+
4461
test.equals(result.indexOf('patternPaths') > -1, true);
4562
test.end();
4663
});
4764

4865
tap.test('exportData exports viewAllPaths', function(test) {
66+
const patternlab = util.fakePatternLab(testPatternsPath);
67+
const result = exportData(patternlab, uikitFoo);
68+
4969
test.equals(result.indexOf('viewAllPaths') > -1, true);
5070
test.end();
5171
});
5272

5373
tap.test('exportData exports plugins', function(test) {
74+
const patternlab = util.fakePatternLab(testPatternsPath);
75+
const result = exportData(patternlab, uikitFoo);
76+
5477
test.equals(result.indexOf('plugins') > -1, true);
5578
test.end();
5679
});
5780

5881
tap.test('exportData exports defaultShowPatternInfo', function(test) {
82+
const patternlab = util.fakePatternLab(testPatternsPath);
83+
const result = exportData(patternlab, uikitFoo);
84+
5985
test.equals(result.indexOf('defaultShowPatternInfo') > -1, true);
6086
test.equals(result.indexOf('"defaultShowPatternInfo":false') > -1, true);
6187
test.end();
6288
});
6389

6490
tap.test('exportData exports defaultPattern', function(test) {
91+
const patternlab = util.fakePatternLab(testPatternsPath);
92+
const result = exportData(patternlab, uikitFoo);
93+
6594
test.equals(result.indexOf('defaultPattern') > -1, true);
6695
test.equals(result.indexOf('"defaultPattern":"all"') > -1, true);
6796
test.end();

packages/plugin-tab/src/snippet.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
window.patternlab.panels.add({
22
id: 'sg-panel-<<type>>',
33
name: '<<typeUC>>',
4-
default: window.config.defaultPatternInfoPanelCode && window.config.defaultPatternInfoPanelCode === "<<type>>",
4+
default:
5+
window.config.defaultPatternInfoPanelCode &&
6+
window.config.defaultPatternInfoPanelCode === '<<type>>',
57
templateID: 'pl-panel-template-code',
68
httpRequest: true,
79
httpRequestReplace: '.<<type>>',
810
httpRequestCompleted: false,
911
prismHighlight: true,
10-
language: '<<type>>'//,
12+
language: '<<type>>', //,
1113
/* TODO: We would need to find a way to enable keyCombo for multiple panels
1214
keyCombo: 'ctrl+shift+z',*/
1315
});

packages/uikit-workshop/src/scripts/components/panels.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,10 @@ function init(event) {
6868
Panels.add({
6969
id: 'pl-panel-pattern',
7070
name: window.config.patternExtension.toUpperCase(),
71-
default: !window.config.defaultPatternInfoPanelCode ||
72-
window.config.defaultPatternInfoPanelCode ===
73-
window.config.patternExtension,
71+
default:
72+
!window.config.defaultPatternInfoPanelCode ||
73+
window.config.defaultPatternInfoPanelCode ===
74+
window.config.patternExtension,
7475
templateID: 'pl-panel-template-code',
7576
httpRequest: true,
7677
httpRequestReplace: fileSuffixPattern,

0 commit comments

Comments
 (0)