2018-11-16 02:45:41 -07:00
|
|
|
const path = require('path');
|
|
|
|
const fs = require('fs');
|
|
|
|
const request = require('request-promise');
|
2019-08-20 07:12:11 -07:00
|
|
|
const twoskyConfig = require('../../.twosky.json')[0];
|
2018-11-16 02:45:41 -07:00
|
|
|
|
2021-12-03 06:20:10 -07:00
|
|
|
const { project_id: TWOSKY_PROJECT_ID, base_locale: DEFAULT_LANGUAGE } = twoskyConfig;
|
2018-11-18 23:57:45 -07:00
|
|
|
const LOCALES_DIR = '../../client/src/__locales';
|
2019-07-18 08:35:23 -07:00
|
|
|
const BASE_FILE = 'en.json';
|
|
|
|
const TWOSKY_URI = process.env.TWOSKY_URI;
|
2018-11-16 02:45:41 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Prepare post params
|
|
|
|
*/
|
2019-07-18 08:35:23 -07:00
|
|
|
const getRequestData = (url, projectId) => {
|
2021-12-03 06:20:10 -07:00
|
|
|
const language = process.env.UPLOAD_LANGUAGE || DEFAULT_LANGUAGE;
|
2018-11-16 02:45:41 -07:00
|
|
|
const formData = {
|
2019-07-18 08:35:23 -07:00
|
|
|
format: 'json',
|
2021-12-03 06:20:10 -07:00
|
|
|
language: language,
|
2019-07-18 08:35:23 -07:00
|
|
|
filename: BASE_FILE,
|
|
|
|
project: projectId,
|
2021-12-03 06:20:10 -07:00
|
|
|
file: fs.createReadStream(path.resolve(LOCALES_DIR, `${language}.json`)),
|
2018-11-16 02:45:41 -07:00
|
|
|
};
|
|
|
|
|
2021-12-03 06:20:10 -07:00
|
|
|
console.log(`uploading ${language}`);
|
|
|
|
|
2019-07-18 08:35:23 -07:00
|
|
|
return {
|
|
|
|
url: `${url}/upload`,
|
|
|
|
formData
|
|
|
|
};
|
2018-11-16 02:45:41 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2019-07-18 08:35:23 -07:00
|
|
|
* Make request to twosky to upload new json
|
2018-11-16 02:45:41 -07:00
|
|
|
*/
|
|
|
|
const upload = () => {
|
2019-07-18 08:35:23 -07:00
|
|
|
if (!TWOSKY_URI) {
|
|
|
|
console.error('No credentials');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const { url, formData } = getRequestData(TWOSKY_URI, TWOSKY_PROJECT_ID);
|
2018-11-16 02:45:41 -07:00
|
|
|
request
|
|
|
|
.post({ url, formData })
|
|
|
|
.catch(err => console.log(err));
|
|
|
|
};
|
|
|
|
|
|
|
|
upload();
|