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');
9
9
const render = require ( './render' ) ;
10
10
const uikitExcludePattern = require ( './uikitExcludePattern' ) ;
11
11
const pm = require ( './plugin_manager' ) ;
12
+ const dataMerger = require ( './dataMerger' ) ;
12
13
const pluginManager = new pm ( ) ;
13
14
14
15
const Pattern = require ( './object_factory' ) . Pattern ;
@@ -56,8 +57,14 @@ module.exports = async function(pattern, patternlab) {
56
57
'listitems.json + any pattern listitems.json'
57
58
) ;
58
59
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);
61
68
allData . cacheBuster = patternlab . cacheBuster ;
62
69
allData . patternPartial = pattern . patternPartial ;
63
70
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');
13
13
const lineage_hunter = new lh ( ) ;
14
14
const changes_hunter = new ch ( ) ;
15
15
const yaml = require ( 'js-yaml' ) ;
16
+ const dataMerger = require ( './dataMerger' ) ;
16
17
17
18
const pseudopattern_hunter = function ( ) { } ;
18
19
@@ -60,24 +61,10 @@ pseudopattern_hunter.prototype.find_pseudopatterns = function(
60
61
}
61
62
62
63
//extend any existing data with variant data
63
- variantFileData = _ . mergeWith (
64
- { } ,
64
+ variantFileData = dataMerger (
65
65
currentPattern . jsonFileData ,
66
66
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
81
68
) ;
82
69
83
70
const variantName = pseudoPatterns [ i ]
You can’t perform that action at this time.
0 commit comments