forked from appium/appium-desktop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
crowdin-update-resources.js
39 lines (34 loc) · 1.1 KB
/
crowdin-update-resources.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
const { logger } = require('appium-support');
const request = require('request');
const path = require('path');
const { createReadStream } = require('fs');
const log = logger.getLogger('CROWDIN');
const PROJECT_ID = process.env.CROWDIN_PROJECT_ID;
const PROJECT_KEY = process.env.CROWDIN_PROJECT_KEY;
if (!PROJECT_ID || !PROJECT_KEY) {
throw new Error(`Both CROWDIN_PROJECT_ID and CROWDIN_PROJECT_KEY environment ` +
`variables must be set`);
}
const resourcePath = path.resolve('assets', 'locales', 'en', 'translation.json');
const fieldName = `files[/${path.basename(resourcePath)}]`;
const options = {
url: `https://api.crowdin.com/api/project/${PROJECT_ID}/update-file?key=${PROJECT_KEY}`,
port: 443,
method: 'POST',
headers: {
'User-Agent': 'Appium Desktop',
},
formData: {
[fieldName]: createReadStream(resourcePath)
}
};
// eslint-disable-next-line promise/prefer-await-to-callbacks
request(options, (err, res, body) => {
if (err) {
throw err;
}
log.debug(`Response code: ${res.statusCode}`);
if (res.statusCode >= 400) {
throw new Error(JSON.stringify(body));
}
});