File tree Expand file tree Collapse file tree 3 files changed +44
-18
lines changed Expand file tree Collapse file tree 3 files changed +44
-18
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ const parseLink = require('./parseLink');
99const render = require ( './render' ) ;
1010const uikitExcludePattern = require ( './uikitExcludePattern' ) ;
1111const pm = require ( './plugin_manager' ) ;
12+ const dataMerger = require ( './dataMerger' ) ;
1213const pluginManager = new pm ( ) ;
1314
1415const Pattern = require ( './object_factory' ) . Pattern ;
@@ -56,8 +57,14 @@ module.exports = async function(pattern, patternlab) {
5657 'listitems.json + any pattern listitems.json'
5758 ) ;
5859
59- allData = _ . merge ( { } , patternlab . data , pattern . jsonFileData ) ;
60- allData = _ . merge ( { } , allData , allListItems ) ;
60+ allData = dataMerger (
61+ patternlab . data ,
62+ pattern . jsonFileData ,
63+ patternlab . config
64+ ) ;
65+ // _.merge({}, patternlab.data, pattern.jsonFileData);
66+ allData = dataMerger ( allData , allListItems , patternlab . config ) ;
67+ // _.merge({}, allData, allListItems);
6168 allData . cacheBuster = patternlab . cacheBuster ;
6269 allData . patternPartial = pattern . patternPartial ;
6370
Original file line number Diff line number Diff line change 1+ const _ = require ( 'lodash' ) ;
2+
3+ /**
4+ * Merges two objects depending on the configuration and will either merge
5+ * arrays and only replaces items on the index or replace the entire
6+ * collection of the different parameters
7+ *
8+ * @param {* } dataObject the object that contains the main data
9+ * @param {* } dataToMergeWithObject the object that should be merged with the original data
10+ * @param {* } patternlabConfig the patternlab configuration object
11+ */
12+ module . exports = function ( dataObject , dataToMergeWithObject , patternlabConfig ) {
13+ return _ . mergeWith (
14+ { } ,
15+ dataObject ,
16+ dataToMergeWithObject ,
17+ ( objValue , srcValue ) => {
18+ if (
19+ _ . isArray ( objValue ) &&
20+ // If the parameter is not available after updating pattern lab but
21+ // not the patternlab-config it should not override arrays.
22+ patternlabConfig . hasOwnProperty ( 'patternMergeVariantArrays' ) &&
23+ ! patternlabConfig . patternMergeVariantArrays
24+ ) {
25+ return srcValue ;
26+ }
27+ // Lodash will only check for "undefined" and eslint needs a consistent
28+ // return so do not remove
29+ return undefined ;
30+ }
31+ ) ;
32+ } ;
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ const readDocumentation = require('./readDocumentation');
1313const lineage_hunter = new lh ( ) ;
1414const changes_hunter = new ch ( ) ;
1515const yaml = require ( 'js-yaml' ) ;
16+ const dataMerger = require ( './dataMerger' ) ;
1617
1718const pseudopattern_hunter = function ( ) { } ;
1819
@@ -60,24 +61,10 @@ pseudopattern_hunter.prototype.find_pseudopatterns = function(
6061 }
6162
6263 //extend any existing data with variant data
63- variantFileData = _ . mergeWith (
64- { } ,
64+ variantFileData = dataMerger (
6565 currentPattern . jsonFileData ,
6666 variantFileData ,
67- ( objValue , srcValue ) => {
68- if (
69- _ . isArray ( objValue ) &&
70- // If the parameter is not available after updating pattern lab but
71- // not the patternlab-config it should not override arrays.
72- patternlab . config . hasOwnProperty ( 'patternMergeVariantArrays' ) &&
73- ! patternlab . config . patternMergeVariantArrays
74- ) {
75- return srcValue ;
76- }
77- // Lodash will only check for "undefined" and eslint needs a consistent
78- // return so do not remove
79- return undefined ;
80- }
67+ patternlab . config
8168 ) ;
8269
8370 const variantName = pseudoPatterns [ i ]
You can’t perform that action at this time.
0 commit comments