This repository has been archived by the owner on Nov 20, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
60 lines (51 loc) · 1.62 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
var fetchUrl = require("fetch").fetchUrl;
var _ = require("lodash");
const compareHierarchy = function(a, b, path = []) {
let hasErrors = false;
const pathString = path.join(".") || "()";
if (typeof a === typeof b) {
if (typeof a === "string") {
return false;
}
if (typeof a === "object") {
const aKeys = Object.keys(a);
const bKeys = Object.keys(b);
const onlyA = _.difference(aKeys, bKeys);
if (onlyA.length) {
const list = onlyA.join(", ");
console.error(
`\x1b[32m\x1b[1m${pathString}\x1b[0m → \x1b[31mleft only\x1b[0m → \x1b[33m\x1b[1m${list}\x1b[0m`
);
hasErrors = true;
}
const onlyB = _.difference(bKeys, aKeys);
if (onlyB.length) {
const list = onlyB.join(", ");
console.error(
`\x1b[32m\x1b[1m${pathString}\x1b[0m → \x1b[31mright only\x1b[0m → \x1b[33m\x1b[1m${list}\x1b[0m`
);
hasErrors = true;
}
const both = _.intersection(aKeys, bKeys);
both.forEach(
key => (hasErrors |= compareHierarchy(a[key], b[key], [...path, key]))
);
}
} else {
console.error(
`\x1b[32m\x1b[1m${pathString}\x1b[0m → \x1b[31mleft type:\x1b[0m \x1b[33m\x1b[1m${typeof a}\x1b[0m vs. \x1b[31mright type:\x1b[0m \x1b[33m\x1b[1m${typeof b}\x1b[0m`
);
hasErrors = true;
}
return hasErrors;
};
fetchUrl(`https://unpkg.com/@vue/cli-ui@latest/locales/en.json`, function(
error,
meta,
body
) {
const en = JSON.parse(body.toString());
const de = require("./locales/de.json");
const result = compareHierarchy(en, de);
process.exit(result);
});