1 | "use strict";
|
2 |
|
3 | const _ = require(`lodash`);
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | module.exports = (a, b) => {
|
10 |
|
11 | const allGatsbyConfigKeysWithAValue = _.uniq(Object.keys(a).concat(Object.keys(b)));
|
12 |
|
13 |
|
14 | const mergedConfig = allGatsbyConfigKeysWithAValue.reduce((config, gatsbyConfigKey) => {
|
15 |
|
16 |
|
17 | const mergeFn = howToMerge[gatsbyConfigKey] || howToMerge.byDefault;
|
18 | return Object.assign({}, config, {
|
19 | [gatsbyConfigKey]: mergeFn(a[gatsbyConfigKey], b[gatsbyConfigKey])
|
20 | });
|
21 | }, {});
|
22 |
|
23 | return mergedConfig;
|
24 | };
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 | const normalizePluginEntry = entry => _.isString(entry) ? {
|
35 | resolve: entry,
|
36 | options: {}
|
37 | } : _.isObject(entry) ? Object.assign({
|
38 | options: {}
|
39 | }, entry) : entry;
|
40 |
|
41 | const howToMerge = {
|
42 | |
43 |
|
44 |
|
45 |
|
46 |
|
47 | byDefault: (a, b) => b || a,
|
48 | siteMetadata: (objA, objB) => _.merge({}, objA, objB),
|
49 |
|
50 | plugins: (a = [], b = []) => _.uniqWith(a.concat(b), (a, b) => _.isEqual(normalizePluginEntry(a), normalizePluginEntry(b))),
|
51 | mapping: (objA, objB) => _.merge({}, objA, objB)
|
52 | };
|
53 |
|
\ | No newline at end of file |