@enplug/scripts 1.11.4-dev57 → 1.11.4-dev59

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -109,19 +109,19 @@ function getCrowdinConfig() {
109
109
 
110
110
  async function findCrowdinAppDirectoryId(credentials, crowdinPath, appName) {
111
111
  try {
112
- if(crowdinPath.startsWith('apps')){
112
+ if(crowdinPath.startsWith('apps') || appName !== 'en.json') { // path is apps/{app-name}/... or dashboard/{data-connector or regions-map or uploader}/en.json
113
113
  const url = `${CROWDIN_PROJECT_URL}/directories?filter=${appName}`;
114
114
  const AuthStr = 'Bearer '.concat(credentials.token);
115
115
  const resp = await axios.get(url, { headers: { Authorization: AuthStr } });
116
116
  const directory = resp.data.data.find(d => d.data.name === appName );
117
117
  return directory ? directory.data.id : undefined;
118
- } else if(crowdinPath.startsWith('dashboard')) {
118
+ } else if((crowdinPath.startsWith('dashboard') || crowdinPath.startsWith('player-web') || crowdinPath.startsWith('components')) && appName === 'en.json') { //path is dashboard/en.json or player-web/en.json or components/en.json
119
119
  const url = `${CROWDIN_PROJECT_URL}/directories?filter=dashboard`;
120
120
  const AuthStr = 'Bearer '.concat(credentials.token);
121
121
  const resp = await axios.get(url, { headers: { Authorization: AuthStr } });
122
122
  const directory = resp.data.data.find(d => d.data.name === 'dashboard' && d.data.title === 'Dashboard' && d.data.path === '/dashboard');
123
123
  return directory ? directory.data.id : undefined;
124
- }
124
+ }
125
125
  } catch (err) {
126
126
  if (err.response.status === HTTP_UNAUTHORIZED_STATUS_CODE) {
127
127
  console.error(`\n${chalk.red.bold('Provided Crowdin token is invalid')}`);
@@ -238,16 +238,15 @@ async function addCrowdinFile(credentials, crowdinPath, storageId, folderId) {
238
238
  })).toPromise();
239
239
  }
240
240
 
241
- function fetchFileFromCrowdin(credentials, crowdinPath, language) {
242
- const url = `${CROWDIN_PROJECT_URL}/export-file`;
243
- const params = {
244
- 'login': credentials.login,
245
- 'account-key': credentials.accountKey,
246
- 'file': crowdinPath,
247
- 'language': language
241
+ function fetchFileFromCrowdin(credentials, language, fileId) {
242
+ const url = `${CROWDIN_PROJECT_URL}/translations/exports`;
243
+ const AuthStr = 'Bearer '.concat(credentials.token);
244
+ const body = {
245
+ "targetLanguageId": language,
246
+ "fileIds": [fileId]
248
247
  };
249
248
 
250
- return axios.get(url, { params });
249
+ return axios.post(url, body, { headers: { Authorization: AuthStr } });
251
250
  }
252
251
 
253
252
  function promptAddFile(crowdinPath) {
@@ -66,7 +66,7 @@ async function syncTranslations(s3Client, bucket) {
66
66
  const appName = crowdinPathSections[1];
67
67
  const appDirectoryId = await findCrowdinAppDirectoryId(credentials, crowdinPath, appName);
68
68
  if(appDirectoryId === undefined) {
69
- console.error(`\n${chalk.red.bold('Directory does not exist')} ${chalk.yellow.bold(`[${appName}]`)}`);
69
+ console.error(`\n${chalk.red.bold('Directory does not exist')} ${chalk.yellow.bold(`${appName}`)}`);
70
70
  console.log('Create the directory in the Crowdin panel first.');
71
71
  return;
72
72
  }
@@ -84,32 +84,44 @@ async function syncTranslations(s3Client, bucket) {
84
84
  if(fileId) {
85
85
  const storageId = await uploadFileToCrowdinStorage(credentials, config.localPath);
86
86
  if(fileId && storageId) {
87
- updateCrowdinFile(credentials, crowdinPath, storageId.data.data.id, fileId);
87
+ await updateCrowdinFile(credentials, crowdinPath, storageId.data.data.id, fileId);
88
88
  }
89
89
  } else {
90
90
  const storageId = await uploadFileToCrowdinStorage(credentials, config.localPath);
91
91
  if(storageId) {
92
- addCrowdinFile(credentials, crowdinPath, storageId.data.data.id, folderId);
92
+ const result = await addCrowdinFile(credentials, crowdinPath, storageId.data.data.id, folderId);
93
+ console.log('add result', result.data);
93
94
  }
94
95
  }
95
- } else if(crowdinPathSections[0] === 'dashboard' && appDirectoryId) {
96
+ } else if((crowdinPathSections[0] === 'dashboard' || crowdinPathSections[0] === 'player-web' || crowdinPathSections[0] === 'components') && appDirectoryId) {
96
97
  if(crowdinPathSections[1] === 'en.json') {
97
98
  const fileId = await getFileIdIfExists(credentials, appDirectoryId, crowdinPathSections[1]); // en.json file id to update
98
99
  if(fileId) {
99
100
  const storageId = await uploadFileToCrowdinStorage(credentials, config.localPath);
100
101
  if(fileId && storageId) {
101
- updateCrowdinFile(credentials, crowdinPath, storageId.data.data.id, fileId);
102
+ await updateCrowdinFile(credentials, crowdinPath, storageId.data.data.id, fileId);
102
103
  }
103
104
  } else {
104
- console.error(`Could not upload ${chalk.yellow.bold(`[${rowdinPathSections[1]}]`)}. Only en.json supported.`);
105
+ console.error(`Could not upload ${chalk.yellow.bold(`${rowdinPathSections[1]}`)}. Only en.json supported.`);
105
106
  }
106
- } // TODO else for data-connector, regions-map and uploader
107
+ } else { // data-connector, regions-map and uploader in dashboard folder
108
+ const folderId = await findCrowdinAppDirectoryId(credentials, crowdinPath, crowdinPathSections[1]);
109
+ if(folderId === undefined) {
110
+ console.error(`Could not find ${chalk.yellow.bold(`${folderId}`)} folder`);
111
+ }
112
+ const fileId = await getFileIdIfExists(credentials, folderId, crowdinPathSections[2]); // en.json file id to update
113
+ const storageId = await uploadFileToCrowdinStorage(credentials, config.localPath);
114
+ if(fileId && storageId) {
115
+ await updateCrowdinFile(credentials, crowdinPath, storageId.data.data.id, fileId);
116
+ }
117
+ }
107
118
  }
108
- // await uploadFileToCrowdin(credentials, config.crowdinPath, config.localPath);
109
- // const { data: fakeTranslation } = await fetchFileFromCrowdin(credentials, config.crowdinPath, FAKE_IN_CONTEXT_LANGUAGE);
110
-
111
- // const s3TranslationsPath = path.parse(s3EnPath).dir;
112
- // const s3FakeTranslationPath = path.join(s3TranslationsPath, FAKE_IN_CONTEXT_LANGUAGE_FILE);
119
+ const { data: fakeTranslation } = await fetchFileFromCrowdin(credentials, FAKE_IN_CONTEXT_LANGUAGE, fileId);
120
+ console.log('eo data', fakeTranslation);
121
+ const s3TranslationsPath = path.parse(s3EnPath).dir;
122
+ console.log('s3TranslationsPath', s3TranslationsPath);
123
+ const s3FakeTranslationPath = path.join(s3TranslationsPath, FAKE_IN_CONTEXT_LANGUAGE_FILE);
124
+ console.log('s3FakeTranslationPath', s3FakeTranslationPath);
113
125
 
114
126
  // await uploadTranslationToS3(s3Client, bucket, s3FakeTranslationPath, JSON.stringify(fakeTranslation));
115
127
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@enplug/scripts",
3
- "version": "1.11.4-dev57",
3
+ "version": "1.11.4-dev59",
4
4
  "description": "Enplug scripts",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",