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
/
todo.js
60 lines (49 loc) · 1.65 KB
/
todo.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 fs = require('fs');
const path = require('path');
const { sortedJSON } = require('./utils');
const markDeprecated = function(obj) {
if (typeof obj === 'string') {
if (!/^DEPRECATED /.test(obj)) {
obj = `DEPRECATED ${obj}`
}
} else if (typeof obj === 'object') {
Object.keys(obj).forEach(key => obj[key] = markDeprecated(obj[key]));
}
return obj;
}
const todoCopy = function(from, to) {
if (typeof from === typeof to && typeof from === 'object') {
const fromKeys = Object.keys(from);
const toKeys = Object.keys(to);
const newKeys = _.difference(fromKeys, toKeys);
newKeys.forEach(key => {
const newValue = from[key];
if (typeof newValue === 'string') {
to[key] = `TODO ${newValue}`;
} else if (typeof newValue === 'object') {
to[key] = todoCopy(newValue, {});
}
})
const oldKeys = _.difference(toKeys, fromKeys);
oldKeys.forEach(key => to[key] = markDeprecated(to[key]));
const bothKeys = _.intersection(fromKeys, toKeys);
bothKeys.forEach(key => {
to[key] = todoCopy(from[key], to[key]);
});
}
return to;
};
fetchUrl(`https://unpkg.com/@vue/cli-ui@latest/locales/en.json`, function(
error,
meta,
body
) {
const filepath = path.resolve(path.relative(__dirname, "./locales/de.json"));
const base = JSON.parse(body.toString());
let locale = require(filepath);
locale = todoCopy(base, locale);
let json = JSON.stringify(locale, sortedJSON, 2) + "\n";
fs.writeFileSync(filepath, json, 'utf8');
});