@beinformed/ui 1.54.1 → 1.54.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/esm/builder/mergeLayoutHintConfigurations.js +10 -2
- package/esm/builder/mergeLayoutHintConfigurations.js.map +1 -1
- package/lib/builder/__tests__/mergeLayoutHintConfigurations.spec.js.flow +22 -2
- package/lib/builder/mergeLayoutHintConfigurations.js +10 -2
- package/lib/builder/mergeLayoutHintConfigurations.js.flow +9 -1
- package/lib/builder/mergeLayoutHintConfigurations.js.map +1 -1
- package/package.json +1 -1
- package/src/builder/__tests__/LayoutHintConfig.json +9 -0
- package/src/builder/__tests__/mergeLayoutHintConfigurations.spec.js +22 -2
- package/src/builder/__tests__/subdir/LayoutHintConfig.json +9 -0
- package/src/builder/mergeLayoutHintConfigurations.js +9 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## [1.54.2](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.54.1...v1.54.2) (2024-09-17)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* **layouthint-config:** merge duplicate hint entries ([29b837c](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/commit/29b837c83d991d6f5dada5f6cd0eb165abdbd2eb))
|
|
11
|
+
|
|
5
12
|
## [1.54.1](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.54.0...v1.54.1) (2024-09-17)
|
|
6
13
|
|
|
7
14
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
|
|
2
|
-
import
|
|
2
|
+
import _Set from "@babel/runtime-corejs3/core-js-stable/set";
|
|
3
3
|
import _JSON$stringify from "@babel/runtime-corejs3/core-js-stable/json/stringify";
|
|
4
4
|
import _Promise from "@babel/runtime-corejs3/core-js-stable/promise";
|
|
5
5
|
const path = require("path");
|
|
@@ -9,6 +9,7 @@ const {
|
|
|
9
9
|
readFileSync,
|
|
10
10
|
writeFileSync
|
|
11
11
|
} = require("fs");
|
|
12
|
+
const mergeWith = require("lodash/mergeWith");
|
|
12
13
|
const {
|
|
13
14
|
LayoutHintConfiguration
|
|
14
15
|
} = require("../constants/LayoutHintConfig");
|
|
@@ -42,7 +43,14 @@ exports.mergeLayoutHintConfigurations = async (srcFolder, outputFolder) => {
|
|
|
42
43
|
const content = readFileSync(file, "utf-8");
|
|
43
44
|
return JSON.parse(content);
|
|
44
45
|
});
|
|
45
|
-
|
|
46
|
+
|
|
47
|
+
// Function to merge arrays during merging
|
|
48
|
+
const customizer = (objValue, srcValue) => {
|
|
49
|
+
if (Array.isArray(objValue)) {
|
|
50
|
+
return [...new _Set([...objValue, ...srcValue])];
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
const newConfig = mergeWith(LayoutHintConfiguration, ...jsons, customizer);
|
|
46
54
|
writeFileSync(path.join(outputFolder, "LayoutHintConfig.json"), _JSON$stringify(newConfig));
|
|
47
55
|
return _Promise.resolve();
|
|
48
56
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mergeLayoutHintConfigurations.js","names":["path","require","readdirSync","statSync","readFileSync","writeFileSync","LayoutHintConfiguration","findFiles","dir","matchedFiles","files","file","absolute","join","isDirectory","foundFiles","push","filename","basename","exports","mergeLayoutHintConfigurations","srcFolder","outputFolder","escapedSrcFolder","replace","jsons","_mapInstanceProperty","call","content","JSON","parse","
|
|
1
|
+
{"version":3,"file":"mergeLayoutHintConfigurations.js","names":["path","require","readdirSync","statSync","readFileSync","writeFileSync","mergeWith","LayoutHintConfiguration","findFiles","dir","matchedFiles","files","file","absolute","join","isDirectory","foundFiles","push","filename","basename","exports","mergeLayoutHintConfigurations","srcFolder","outputFolder","escapedSrcFolder","replace","jsons","_mapInstanceProperty","call","content","JSON","parse","customizer","objValue","srcValue","Array","isArray","_Set","newConfig","_JSON$stringify","_Promise","resolve"],"sources":["../../src/builder/mergeLayoutHintConfigurations.js"],"sourcesContent":["// @flow\nconst path = require(\"path\");\nconst { readdirSync, statSync, readFileSync, writeFileSync } = require(\"fs\");\n\nconst mergeWith = require(\"lodash/mergeWith\");\nconst { LayoutHintConfiguration } = require(\"../constants/LayoutHintConfig\");\n\nconst findFiles = (dir: string): Array<string> => {\n const matchedFiles = [];\n\n const files = readdirSync(dir);\n\n for (const file of files) {\n const absolute = path.join(dir, file);\n if (statSync(absolute).isDirectory()) {\n const foundFiles = findFiles(absolute);\n matchedFiles.push(...foundFiles);\n } else {\n const filename = path.basename(file);\n if (filename === \"LayoutHintConfig.json\") {\n matchedFiles.push(absolute);\n }\n }\n }\n\n return matchedFiles;\n};\n\n/**\n * Merge all LayoutHintConfig.json files from this library and in the srcFolder\n * together into one config file, and copies it to the outputFolder.<br/>\n * This file is consumed by Be Informed studio to give layout hint information\n */\nexports.mergeLayoutHintConfigurations = async (\n srcFolder: string,\n outputFolder: string,\n): Promise<void> => {\n const escapedSrcFolder = srcFolder.replace(/\\\\/g, \"/\");\n\n const files = findFiles(escapedSrcFolder);\n\n const jsons = files.map((file) => {\n const content = readFileSync(file, \"utf-8\");\n return JSON.parse(content);\n });\n\n // Function to merge arrays during merging\n const customizer = (objValue: Object, srcValue: Object): Object => {\n if (Array.isArray(objValue)) {\n return [...new Set([...objValue, ...srcValue])];\n }\n };\n\n const newConfig = mergeWith(LayoutHintConfiguration, ...jsons, customizer);\n\n writeFileSync(\n path.join(outputFolder, \"LayoutHintConfig.json\"),\n JSON.stringify(newConfig),\n );\n\n return Promise.resolve();\n};\n"],"mappings":";;;;AACA,MAAMA,IAAI,GAAGC,OAAO,CAAC,MAAM,CAAC;AAC5B,MAAM;EAAEC,WAAW;EAAEC,QAAQ;EAAEC,YAAY;EAAEC;AAAc,CAAC,GAAGJ,OAAO,CAAC,IAAI,CAAC;AAE5E,MAAMK,SAAS,GAAGL,OAAO,CAAC,kBAAkB,CAAC;AAC7C,MAAM;EAAEM;AAAwB,CAAC,GAAGN,OAAO,CAAC,+BAA+B,CAAC;AAE5E,MAAMO,SAAS,GAAIC,GAAW,IAAoB;EAChD,MAAMC,YAAY,GAAG,EAAE;EAEvB,MAAMC,KAAK,GAAGT,WAAW,CAACO,GAAG,CAAC;EAE9B,KAAK,MAAMG,IAAI,IAAID,KAAK,EAAE;IACxB,MAAME,QAAQ,GAAGb,IAAI,CAACc,IAAI,CAACL,GAAG,EAAEG,IAAI,CAAC;IACrC,IAAIT,QAAQ,CAACU,QAAQ,CAAC,CAACE,WAAW,CAAC,CAAC,EAAE;MACpC,MAAMC,UAAU,GAAGR,SAAS,CAACK,QAAQ,CAAC;MACtCH,YAAY,CAACO,IAAI,CAAC,GAAGD,UAAU,CAAC;IAClC,CAAC,MAAM;MACL,MAAME,QAAQ,GAAGlB,IAAI,CAACmB,QAAQ,CAACP,IAAI,CAAC;MACpC,IAAIM,QAAQ,KAAK,uBAAuB,EAAE;QACxCR,YAAY,CAACO,IAAI,CAACJ,QAAQ,CAAC;MAC7B;IACF;EACF;EAEA,OAAOH,YAAY;AACrB,CAAC;;AAED;AACA;AACA;AACA;AACA;AACAU,OAAO,CAACC,6BAA6B,GAAG,OACtCC,SAAiB,EACjBC,YAAoB,KACF;EAClB,MAAMC,gBAAgB,GAAGF,SAAS,CAACG,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;EAEtD,MAAMd,KAAK,GAAGH,SAAS,CAACgB,gBAAgB,CAAC;EAEzC,MAAME,KAAK,GAAGC,oBAAA,CAAAhB,KAAK,EAAAiB,IAAA,CAALjB,KAAK,EAAMC,IAAI,IAAK;IAChC,MAAMiB,OAAO,GAAGzB,YAAY,CAACQ,IAAI,EAAE,OAAO,CAAC;IAC3C,OAAOkB,IAAI,CAACC,KAAK,CAACF,OAAO,CAAC;EAC5B,CAAC,CAAC;;EAEF;EACA,MAAMG,UAAU,GAAGA,CAACC,QAAgB,EAAEC,QAAgB,KAAa;IACjE,IAAIC,KAAK,CAACC,OAAO,CAACH,QAAQ,CAAC,EAAE;MAC3B,OAAO,CAAC,GAAG,IAAAI,IAAA,CAAQ,CAAC,GAAGJ,QAAQ,EAAE,GAAGC,QAAQ,CAAC,CAAC,CAAC;IACjD;EACF,CAAC;EAED,MAAMI,SAAS,GAAGhC,SAAS,CAACC,uBAAuB,EAAE,GAAGmB,KAAK,EAAEM,UAAU,CAAC;EAE1E3B,aAAa,CACXL,IAAI,CAACc,IAAI,CAACS,YAAY,EAAE,uBAAuB,CAAC,EAChDgB,eAAA,CAAeD,SAAS,CAC1B,CAAC;EAED,OAAOE,QAAA,CAAQC,OAAO,CAAC,CAAC;AAC1B,CAAC","ignoreList":[]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { mergeLayoutHintConfigurations } from "../mergeLayoutHintConfigurations";
|
|
2
2
|
import { LayoutHintConfiguration } from "../../constants/LayoutHintConfig";
|
|
3
3
|
const fs = require("fs");
|
|
4
|
+
|
|
4
5
|
//
|
|
5
6
|
const projectJson1 = {
|
|
6
7
|
MOCK: {
|
|
@@ -26,6 +27,18 @@ const projectJson2 = {
|
|
|
26
27
|
},
|
|
27
28
|
};
|
|
28
29
|
|
|
30
|
+
const projectMerge = {
|
|
31
|
+
MERGE: {
|
|
32
|
+
hint: "merge",
|
|
33
|
+
description: {
|
|
34
|
+
NL: "merge with extra component",
|
|
35
|
+
EN: "merge with extra component",
|
|
36
|
+
},
|
|
37
|
+
link: "",
|
|
38
|
+
component: ["component1", "component2", "component3"],
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
|
|
29
42
|
jest.mock("fs", () => ({
|
|
30
43
|
...jest.requireActual("fs"),
|
|
31
44
|
writeFileSync: jest.fn(),
|
|
@@ -33,19 +46,26 @@ jest.mock("fs", () => ({
|
|
|
33
46
|
|
|
34
47
|
describe("mergeLayoutHintConfigurations", () => {
|
|
35
48
|
it("generates layouthint.json", async () => {
|
|
36
|
-
expect.assertions(
|
|
49
|
+
expect.assertions(2);
|
|
37
50
|
|
|
38
51
|
const expectedJson = {
|
|
39
52
|
...LayoutHintConfiguration,
|
|
40
53
|
...projectJson1,
|
|
41
54
|
...projectJson2,
|
|
55
|
+
...projectMerge,
|
|
42
56
|
};
|
|
43
57
|
|
|
44
58
|
await mergeLayoutHintConfigurations("./src", "/output");
|
|
45
59
|
|
|
46
60
|
expect(fs.writeFileSync).toHaveBeenCalledWith(
|
|
47
61
|
expect.stringContaining("LayoutHintConfig.json"),
|
|
48
|
-
|
|
62
|
+
expect.any(String),
|
|
49
63
|
);
|
|
64
|
+
|
|
65
|
+
// Check that the JSON written matches the expected JSON
|
|
66
|
+
const actualJson = JSON.parse(fs.writeFileSync.mock.calls[0][1]);
|
|
67
|
+
|
|
68
|
+
// Compare objects using deep comparison to ensure they are equal
|
|
69
|
+
expect(actualJson).toEqual(expectedJson);
|
|
50
70
|
});
|
|
51
71
|
});
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
|
4
4
|
var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map"));
|
|
5
|
-
var
|
|
5
|
+
var _set = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/set"));
|
|
6
6
|
var _stringify = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/json/stringify"));
|
|
7
7
|
var _promise = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/promise"));
|
|
8
8
|
const path = require("path");
|
|
@@ -12,6 +12,7 @@ const {
|
|
|
12
12
|
readFileSync,
|
|
13
13
|
writeFileSync
|
|
14
14
|
} = require("fs");
|
|
15
|
+
const mergeWith = require("lodash/mergeWith");
|
|
15
16
|
const {
|
|
16
17
|
LayoutHintConfiguration
|
|
17
18
|
} = require("../constants/LayoutHintConfig");
|
|
@@ -45,7 +46,14 @@ exports.mergeLayoutHintConfigurations = async (srcFolder, outputFolder) => {
|
|
|
45
46
|
const content = readFileSync(file, "utf-8");
|
|
46
47
|
return JSON.parse(content);
|
|
47
48
|
});
|
|
48
|
-
|
|
49
|
+
|
|
50
|
+
// Function to merge arrays during merging
|
|
51
|
+
const customizer = (objValue, srcValue) => {
|
|
52
|
+
if (Array.isArray(objValue)) {
|
|
53
|
+
return [...new _set.default([...objValue, ...srcValue])];
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
const newConfig = mergeWith(LayoutHintConfiguration, ...jsons, customizer);
|
|
49
57
|
writeFileSync(path.join(outputFolder, "LayoutHintConfig.json"), (0, _stringify.default)(newConfig));
|
|
50
58
|
return _promise.default.resolve();
|
|
51
59
|
};
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
const path = require("path");
|
|
3
3
|
const { readdirSync, statSync, readFileSync, writeFileSync } = require("fs");
|
|
4
4
|
|
|
5
|
+
const mergeWith = require("lodash/mergeWith");
|
|
5
6
|
const { LayoutHintConfiguration } = require("../constants/LayoutHintConfig");
|
|
6
7
|
|
|
7
8
|
const findFiles = (dir: string): Array<string> => {
|
|
@@ -43,7 +44,14 @@ exports.mergeLayoutHintConfigurations = async (
|
|
|
43
44
|
return JSON.parse(content);
|
|
44
45
|
});
|
|
45
46
|
|
|
46
|
-
|
|
47
|
+
// Function to merge arrays during merging
|
|
48
|
+
const customizer = (objValue: Object, srcValue: Object): Object => {
|
|
49
|
+
if (Array.isArray(objValue)) {
|
|
50
|
+
return [...new Set([...objValue, ...srcValue])];
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const newConfig = mergeWith(LayoutHintConfiguration, ...jsons, customizer);
|
|
47
55
|
|
|
48
56
|
writeFileSync(
|
|
49
57
|
path.join(outputFolder, "LayoutHintConfig.json"),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mergeLayoutHintConfigurations.js","names":["path","require","readdirSync","statSync","readFileSync","writeFileSync","LayoutHintConfiguration","findFiles","dir","matchedFiles","files","file","absolute","join","isDirectory","foundFiles","push","filename","basename","exports","mergeLayoutHintConfigurations","srcFolder","outputFolder","escapedSrcFolder","replace","jsons","_map","default","call","content","JSON","parse","
|
|
1
|
+
{"version":3,"file":"mergeLayoutHintConfigurations.js","names":["path","require","readdirSync","statSync","readFileSync","writeFileSync","mergeWith","LayoutHintConfiguration","findFiles","dir","matchedFiles","files","file","absolute","join","isDirectory","foundFiles","push","filename","basename","exports","mergeLayoutHintConfigurations","srcFolder","outputFolder","escapedSrcFolder","replace","jsons","_map","default","call","content","JSON","parse","customizer","objValue","srcValue","Array","isArray","_set","newConfig","_stringify","_promise","resolve"],"sources":["../../src/builder/mergeLayoutHintConfigurations.js"],"sourcesContent":["// @flow\nconst path = require(\"path\");\nconst { readdirSync, statSync, readFileSync, writeFileSync } = require(\"fs\");\n\nconst mergeWith = require(\"lodash/mergeWith\");\nconst { LayoutHintConfiguration } = require(\"../constants/LayoutHintConfig\");\n\nconst findFiles = (dir: string): Array<string> => {\n const matchedFiles = [];\n\n const files = readdirSync(dir);\n\n for (const file of files) {\n const absolute = path.join(dir, file);\n if (statSync(absolute).isDirectory()) {\n const foundFiles = findFiles(absolute);\n matchedFiles.push(...foundFiles);\n } else {\n const filename = path.basename(file);\n if (filename === \"LayoutHintConfig.json\") {\n matchedFiles.push(absolute);\n }\n }\n }\n\n return matchedFiles;\n};\n\n/**\n * Merge all LayoutHintConfig.json files from this library and in the srcFolder\n * together into one config file, and copies it to the outputFolder.<br/>\n * This file is consumed by Be Informed studio to give layout hint information\n */\nexports.mergeLayoutHintConfigurations = async (\n srcFolder: string,\n outputFolder: string,\n): Promise<void> => {\n const escapedSrcFolder = srcFolder.replace(/\\\\/g, \"/\");\n\n const files = findFiles(escapedSrcFolder);\n\n const jsons = files.map((file) => {\n const content = readFileSync(file, \"utf-8\");\n return JSON.parse(content);\n });\n\n // Function to merge arrays during merging\n const customizer = (objValue: Object, srcValue: Object): Object => {\n if (Array.isArray(objValue)) {\n return [...new Set([...objValue, ...srcValue])];\n }\n };\n\n const newConfig = mergeWith(LayoutHintConfiguration, ...jsons, customizer);\n\n writeFileSync(\n path.join(outputFolder, \"LayoutHintConfig.json\"),\n JSON.stringify(newConfig),\n );\n\n return Promise.resolve();\n};\n"],"mappings":";;;;;;;AACA,MAAMA,IAAI,GAAGC,OAAO,CAAC,MAAM,CAAC;AAC5B,MAAM;EAAEC,WAAW;EAAEC,QAAQ;EAAEC,YAAY;EAAEC;AAAc,CAAC,GAAGJ,OAAO,CAAC,IAAI,CAAC;AAE5E,MAAMK,SAAS,GAAGL,OAAO,CAAC,kBAAkB,CAAC;AAC7C,MAAM;EAAEM;AAAwB,CAAC,GAAGN,OAAO,CAAC,+BAA+B,CAAC;AAE5E,MAAMO,SAAS,GAAIC,GAAW,IAAoB;EAChD,MAAMC,YAAY,GAAG,EAAE;EAEvB,MAAMC,KAAK,GAAGT,WAAW,CAACO,GAAG,CAAC;EAE9B,KAAK,MAAMG,IAAI,IAAID,KAAK,EAAE;IACxB,MAAME,QAAQ,GAAGb,IAAI,CAACc,IAAI,CAACL,GAAG,EAAEG,IAAI,CAAC;IACrC,IAAIT,QAAQ,CAACU,QAAQ,CAAC,CAACE,WAAW,CAAC,CAAC,EAAE;MACpC,MAAMC,UAAU,GAAGR,SAAS,CAACK,QAAQ,CAAC;MACtCH,YAAY,CAACO,IAAI,CAAC,GAAGD,UAAU,CAAC;IAClC,CAAC,MAAM;MACL,MAAME,QAAQ,GAAGlB,IAAI,CAACmB,QAAQ,CAACP,IAAI,CAAC;MACpC,IAAIM,QAAQ,KAAK,uBAAuB,EAAE;QACxCR,YAAY,CAACO,IAAI,CAACJ,QAAQ,CAAC;MAC7B;IACF;EACF;EAEA,OAAOH,YAAY;AACrB,CAAC;;AAED;AACA;AACA;AACA;AACA;AACAU,OAAO,CAACC,6BAA6B,GAAG,OACtCC,SAAiB,EACjBC,YAAoB,KACF;EAClB,MAAMC,gBAAgB,GAAGF,SAAS,CAACG,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;EAEtD,MAAMd,KAAK,GAAGH,SAAS,CAACgB,gBAAgB,CAAC;EAEzC,MAAME,KAAK,GAAG,IAAAC,IAAA,CAAAC,OAAA,EAAAjB,KAAK,EAAAkB,IAAA,CAALlB,KAAK,EAAMC,IAAI,IAAK;IAChC,MAAMkB,OAAO,GAAG1B,YAAY,CAACQ,IAAI,EAAE,OAAO,CAAC;IAC3C,OAAOmB,IAAI,CAACC,KAAK,CAACF,OAAO,CAAC;EAC5B,CAAC,CAAC;;EAEF;EACA,MAAMG,UAAU,GAAGA,CAACC,QAAgB,EAAEC,QAAgB,KAAa;IACjE,IAAIC,KAAK,CAACC,OAAO,CAACH,QAAQ,CAAC,EAAE;MAC3B,OAAO,CAAC,GAAG,IAAAI,IAAA,CAAAV,OAAA,CAAQ,CAAC,GAAGM,QAAQ,EAAE,GAAGC,QAAQ,CAAC,CAAC,CAAC;IACjD;EACF,CAAC;EAED,MAAMI,SAAS,GAAGjC,SAAS,CAACC,uBAAuB,EAAE,GAAGmB,KAAK,EAAEO,UAAU,CAAC;EAE1E5B,aAAa,CACXL,IAAI,CAACc,IAAI,CAACS,YAAY,EAAE,uBAAuB,CAAC,EAChD,IAAAiB,UAAA,CAAAZ,OAAA,EAAeW,SAAS,CAC1B,CAAC;EAED,OAAOE,QAAA,CAAAb,OAAA,CAAQc,OAAO,CAAC,CAAC;AAC1B,CAAC","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -7,5 +7,14 @@
|
|
|
7
7
|
},
|
|
8
8
|
"link": "",
|
|
9
9
|
"component": ["attribute"]
|
|
10
|
+
},
|
|
11
|
+
"MERGE": {
|
|
12
|
+
"hint": "merge",
|
|
13
|
+
"description": {
|
|
14
|
+
"NL": "merge with extra component",
|
|
15
|
+
"EN": "merge with extra component"
|
|
16
|
+
},
|
|
17
|
+
"link": "",
|
|
18
|
+
"component": ["component1", "component2"]
|
|
10
19
|
}
|
|
11
20
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { mergeLayoutHintConfigurations } from "../mergeLayoutHintConfigurations";
|
|
2
2
|
import { LayoutHintConfiguration } from "../../constants/LayoutHintConfig";
|
|
3
3
|
const fs = require("fs");
|
|
4
|
+
|
|
4
5
|
//
|
|
5
6
|
const projectJson1 = {
|
|
6
7
|
MOCK: {
|
|
@@ -26,6 +27,18 @@ const projectJson2 = {
|
|
|
26
27
|
},
|
|
27
28
|
};
|
|
28
29
|
|
|
30
|
+
const projectMerge = {
|
|
31
|
+
MERGE: {
|
|
32
|
+
hint: "merge",
|
|
33
|
+
description: {
|
|
34
|
+
NL: "merge with extra component",
|
|
35
|
+
EN: "merge with extra component",
|
|
36
|
+
},
|
|
37
|
+
link: "",
|
|
38
|
+
component: ["component1", "component2", "component3"],
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
|
|
29
42
|
jest.mock("fs", () => ({
|
|
30
43
|
...jest.requireActual("fs"),
|
|
31
44
|
writeFileSync: jest.fn(),
|
|
@@ -33,19 +46,26 @@ jest.mock("fs", () => ({
|
|
|
33
46
|
|
|
34
47
|
describe("mergeLayoutHintConfigurations", () => {
|
|
35
48
|
it("generates layouthint.json", async () => {
|
|
36
|
-
expect.assertions(
|
|
49
|
+
expect.assertions(2);
|
|
37
50
|
|
|
38
51
|
const expectedJson = {
|
|
39
52
|
...LayoutHintConfiguration,
|
|
40
53
|
...projectJson1,
|
|
41
54
|
...projectJson2,
|
|
55
|
+
...projectMerge,
|
|
42
56
|
};
|
|
43
57
|
|
|
44
58
|
await mergeLayoutHintConfigurations("./src", "/output");
|
|
45
59
|
|
|
46
60
|
expect(fs.writeFileSync).toHaveBeenCalledWith(
|
|
47
61
|
expect.stringContaining("LayoutHintConfig.json"),
|
|
48
|
-
|
|
62
|
+
expect.any(String),
|
|
49
63
|
);
|
|
64
|
+
|
|
65
|
+
// Check that the JSON written matches the expected JSON
|
|
66
|
+
const actualJson = JSON.parse(fs.writeFileSync.mock.calls[0][1]);
|
|
67
|
+
|
|
68
|
+
// Compare objects using deep comparison to ensure they are equal
|
|
69
|
+
expect(actualJson).toEqual(expectedJson);
|
|
50
70
|
});
|
|
51
71
|
});
|
|
@@ -7,5 +7,14 @@
|
|
|
7
7
|
},
|
|
8
8
|
"link": "",
|
|
9
9
|
"component": ["attribute"]
|
|
10
|
+
},
|
|
11
|
+
"MERGE": {
|
|
12
|
+
"hint": "merge",
|
|
13
|
+
"description": {
|
|
14
|
+
"NL": "merge with extra component",
|
|
15
|
+
"EN": "merge with extra component"
|
|
16
|
+
},
|
|
17
|
+
"link": "",
|
|
18
|
+
"component": ["component1", "component3"]
|
|
10
19
|
}
|
|
11
20
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
const path = require("path");
|
|
3
3
|
const { readdirSync, statSync, readFileSync, writeFileSync } = require("fs");
|
|
4
4
|
|
|
5
|
+
const mergeWith = require("lodash/mergeWith");
|
|
5
6
|
const { LayoutHintConfiguration } = require("../constants/LayoutHintConfig");
|
|
6
7
|
|
|
7
8
|
const findFiles = (dir: string): Array<string> => {
|
|
@@ -43,7 +44,14 @@ exports.mergeLayoutHintConfigurations = async (
|
|
|
43
44
|
return JSON.parse(content);
|
|
44
45
|
});
|
|
45
46
|
|
|
46
|
-
|
|
47
|
+
// Function to merge arrays during merging
|
|
48
|
+
const customizer = (objValue: Object, srcValue: Object): Object => {
|
|
49
|
+
if (Array.isArray(objValue)) {
|
|
50
|
+
return [...new Set([...objValue, ...srcValue])];
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const newConfig = mergeWith(LayoutHintConfiguration, ...jsons, customizer);
|
|
47
55
|
|
|
48
56
|
writeFileSync(
|
|
49
57
|
path.join(outputFolder, "LayoutHintConfig.json"),
|