-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
31 lines (27 loc) · 926 Bytes
/
index.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
require("dotenv").config();
const fetch = require("node-fetch");
const admZip = require("adm-zip");
const localesDir = `${process.cwd()}/${process.env.LOCALES_DIR}`;
const PROJECT = process.env.CROWDIN_PROJECT;
const KEY = process.env.CROWDIN_KEY;
const url = "https://api.crowdin.com/api/project";
const builtUrl = `${url}/${PROJECT}/export?key=${KEY}`;
const downloadUrl = `${url}/${PROJECT}/download/all.zip?key=${KEY}`;
async function main() {
console.log("Creating latest build...");
await fetch(builtUrl);
console.log("Downloading latest build...");
const body = await fetch(downloadUrl);
const buffer = await body.buffer();
const zip = new admZip(buffer);
console.log("Updating local files...");
zip.extractAllTo(localesDir + "/", true);
console.log("Files have been updated.");
process.exit();
}
try {
main();
} catch (error) {
console.log("Something went wrong.");
console.log(error);
}