-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.js
executable file
·38 lines (35 loc) · 1.3 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
#!/usr/bin/env node
const path = require("path");
const fs = require("fs");
var combineInputs = (dir) => {
// expected input: a directory containing subdirs, each of which contains displayMessages.json
var ret = [];
var subDirs = fs.readdirSync(dir);
subDirs.forEach((subdir) => {
var messageFile = path.join(dir, subdir, "displayMessages.json");
var messages = JSON.parse(fs.readFileSync(messageFile));
messages.forEach((message) => {ret.push(message);});
});
return ret;
};
var inData = combineInputs(process.argv[2]);
var outData = {};
inData.forEach((message) => {
outData[message["id"]] = message["defaultMessage"];
});
if (process.argv[3] === "--comments") {
process.stdout.write("generating bash scripts...\n");
var messageInfo = JSON.parse(fs.readFileSync(__dirname + "/bash_scripts/hashmap.json"));
var dataPath = __dirname + "/bash_scripts/hashed_data.txt";
fs.writeFileSync(dataPath, "");
inData.forEach((message) => {
var info = messageInfo.find(mi => mi.key == message.id);
if (info) {
fs.appendFileSync(dataPath, info.string_hash + "|" + message.description + "\n");
} else {
process.stdout.write("string " + message.id + " does not yet exist on transifex!\n");
}
});
} else {
fs.writeFileSync(process.argv[3], JSON.stringify(outData, null, 2));
}