@enplug/scripts 1.11.4-dev56 → 1.11.4-dev58

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')}`);
@@ -225,7 +225,7 @@ async function addCrowdinFile(credentials, crowdinPath, storageId, folderId) {
225
225
  return from(axios.post(url, body, { headers: { Authorization: AuthStr } })).pipe(tap({
226
226
  next: response => {
227
227
  if (response.data) {
228
- console.log(`${chalk.green.bold('Translations added to Crowdin')} ${chalk.yellow.bold(`[${crowdinPath}]`)}`);
228
+ console.log(`${chalk.green.bold('Translations uploaded to Crowdin')} ${chalk.yellow.bold(`[${crowdinPath}]`)}`);
229
229
  } else {
230
230
  console.error('Unexpected result');
231
231
  console.log(response);
@@ -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,27 +84,36 @@ async function syncTranslations(s3Client, bucket) {
84
84
  if(fileId) {
85
85
  const storageId = await uploadFileToCrowdinStorage(credentials, config.localPath);
86
86
  if(fileId && storageId) {
87
- const response = await updateCrowdinFile(credentials, crowdinPath, storageId.data.data.id, fileId);
87
+ updateCrowdinFile(credentials, crowdinPath, storageId.data.data.id, fileId);
88
88
  }
89
89
  } else {
90
- // console.error(`Could not find ${chalk.yellow.bold(`${crowdinPathSections[3]}`)} file, create it in the Crowdin panel first.`);
91
90
  const storageId = await uploadFileToCrowdinStorage(credentials, config.localPath);
92
91
  if(storageId) {
93
- const response = await addCrowdinFile(credentials, crowdinPath, storageId.data.data.id, folderId);
92
+ addCrowdinFile(credentials, crowdinPath, storageId.data.data.id, folderId);
94
93
  }
95
94
  }
96
- } else if(crowdinPathSections[0] === 'dashboard' && appDirectoryId) {
95
+ } else if((crowdinPathSections[0] === 'dashboard' || crowdinPathSections[0] === 'player-web' || crowdinPathSections[0] === 'components') && appDirectoryId) {
97
96
  if(crowdinPathSections[1] === 'en.json') {
98
97
  const fileId = await getFileIdIfExists(credentials, appDirectoryId, crowdinPathSections[1]); // en.json file id to update
99
98
  if(fileId) {
100
99
  const storageId = await uploadFileToCrowdinStorage(credentials, config.localPath);
101
100
  if(fileId && storageId) {
102
- const response = await updateCrowdinFile(credentials, crowdinPath, storageId.data.data.id, fileId);
101
+ updateCrowdinFile(credentials, crowdinPath, storageId.data.data.id, fileId);
103
102
  }
104
103
  } else {
105
- console.error(`Could not upload ${chalk.yellow.bold(`[${rowdinPathSections[1]}]`)}. Only en.json supported.`);
104
+ console.error(`Could not upload ${chalk.yellow.bold(`${rowdinPathSections[1]}`)}. Only en.json supported.`);
106
105
  }
107
- } // TODO else for data-connector, regions-map and uploader
106
+ } else { // data-connector, regions-map and uploader in dashboard folder
107
+ const folderId = await findCrowdinAppDirectoryId(credentials, crowdinPath, crowdinPathSections[1]);
108
+ if(folderId === undefined) {
109
+ console.error(`Could not find ${chalk.yellow.bold(`${folderId}`)} folder`);
110
+ }
111
+ const fileId = await getFileIdIfExists(credentials, folderId, crowdinPathSections[2]); // en.json file id to update
112
+ const storageId = await uploadFileToCrowdinStorage(credentials, config.localPath);
113
+ if(fileId && storageId) {
114
+ updateCrowdinFile(credentials, crowdinPath, storageId.data.data.id, fileId);
115
+ }
116
+ }
108
117
  }
109
118
  // await uploadFileToCrowdin(credentials, config.crowdinPath, config.localPath);
110
119
  // const { data: fakeTranslation } = await fetchFileFromCrowdin(credentials, config.crowdinPath, FAKE_IN_CONTEXT_LANGUAGE);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@enplug/scripts",
3
- "version": "1.11.4-dev56",
3
+ "version": "1.11.4-dev58",
4
4
  "description": "Enplug scripts",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",