-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathmain.js
64 lines (55 loc) · 1.48 KB
/
main.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
61
62
63
64
const fs = require("fs")
const ignoreFiles = [
".github",
".git",
"Contribution.md",
"LICENSE",
"main.js",
"add-key.js",
"README.md",
]
function getFiles(dir, files = []) {
// Get an array of all files and directories in the passed directory using fs.readdirSync
const fileList = fs.readdirSync(dir)
const filteredFileList = fileList.filter(file => !ignoreFiles.includes(file))
for (const file of filteredFileList) {
const name = `${dir}/${file}`
if (fs.statSync(name).isDirectory()) {
getFiles(name, files)
} else {
files.push(name)
}
}
return files
}
const main = () => {
// We already know this
const enPath = "./en/translation.json"
const enData = fs.readFileSync(enPath, {
encoding: "utf-8",
})
const targetKeys = Object.keys(JSON.parse(enData))
const files = getFiles(".")
files.forEach(file => {
if (file != enPath) {
console.info(`Checking locale ${file}`)
let not_included = []
try {
const data = fs.readFileSync(file, {
encoding: "utf-8",
})
const thisLang = JSON.parse(data)
const thisLangKeys = Object.keys(thisLang)
not_included = targetKeys.filter(t_key => !thisLangKeys.includes(t_key))
} catch (e) {
console.error(`Unexpected Error: ${e}`)
}
if (not_included.length > 0) {
throw new Error(
`Missing keys for locale ${file}: \n - ${not_included.join(" \n - ")}\n\n`
)
}
}
})
}
main()