@enplug/scripts 1.11.4-dev52 → 1.11.4-dev54

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.
@@ -172,7 +172,7 @@ async function uploadFileToCrowdinStorage(credentials, localPath) {
172
172
  ).toPromise();
173
173
  }
174
174
 
175
- async function updateCrowdinFile(credentials, crowdinPath, storageId, fileId) {
175
+ async function updateCrowdinFile(credentials, crowdinPath, storageId, fileId) {
176
176
  const url = `${CROWDIN_PROJECT_URL}/files/${fileId}`;
177
177
  const AuthStr = 'Bearer '.concat(credentials.token);
178
178
  const body = {
@@ -197,7 +197,43 @@ async function updateCrowdinFile(credentials, crowdinPath, storageId, fileId) {
197
197
  }
198
198
  },
199
199
  error: error => {
200
- const crowdinError = error.response && error.response.data && error.response.data.error;
200
+ console.error('\nUnexpected error:');
201
+ console.error(error);
202
+ }
203
+ })).toPromise();
204
+ }
205
+
206
+ async function addCrowdinFile(credentials, crowdinPath, storageId, folderId) {
207
+ const url = `${CROWDIN_PROJECT_URL}/files`;
208
+ const AuthStr = 'Bearer '.concat(credentials.token);
209
+ const body = {
210
+ "storageId": storageId,
211
+ "name": "en.json",
212
+ "branchId": null,
213
+ "directoryId": folderId,
214
+ "title": null,
215
+ "context": null,
216
+ "type": "json",
217
+ "parserVersion": 1,
218
+ "importOptions": {
219
+ "contentSegmentation": false,
220
+ "customSegmentation": false
221
+ },
222
+ "exportOptions": {
223
+ "exportPattern": "%locale%.json"
224
+ },
225
+ "excludedTargetLanguages": null
226
+ }
227
+ return from(axios.post(url, body, { headers: { Authorization: AuthStr } })).pipe(tap({
228
+ next: response => {
229
+ if (response.data) {
230
+ console.log(`${chalk.green.bold('Translations uploaded to Crowdin')} ${chalk.yellow.bold(`[${crowdinPath}]`)}`);
231
+ } else {
232
+ console.error('Unexpected result');
233
+ console.log(response);
234
+ }
235
+ },
236
+ error: error => {
201
237
  console.error('\nUnexpected error:');
202
238
  console.error(error);
203
239
  }
@@ -73,6 +73,7 @@ async function syncTranslations(s3Client, bucket) {
73
73
  if(crowdinPathSections[0] === 'apps' && appDirectoryId) {
74
74
  if(crowdinPathSections.length !== 4 && crowdinPathSections[3] !== 'en.json') {
75
75
  console.error(`\n${chalk.red.bold('Crowdin path provided does not match defined format, make sure the path is as follows /apps/{app-id}/dashboard/en.json or /apps/{app-id}/app/en.json')}`);
76
+ return;
76
77
  }
77
78
  const subfolderName = crowdinPathSections[2]; //dashboard or app folder
78
79
  const folderId = await findCrowdinAppSubFolderId(credentials, appDirectoryId, subfolderName);
@@ -86,7 +87,11 @@ async function syncTranslations(s3Client, bucket) {
86
87
  const response = await updateCrowdinFile(credentials, crowdinPath, storageId.data.data.id, fileId);
87
88
  }
88
89
  } else {
89
- //TODO add file
90
+ // console.error(`Could not find ${chalk.yellow.bold(`${crowdinPathSections[3]}`)} file, create it in the Crowdin panel first.`);
91
+ const storageId = await uploadFileToCrowdinStorage(credentials, config.localPath);
92
+ if(storageId) {
93
+ const response = await addCrowdinFile(credentials, crowdinPath, storageId.data.data.id, folderId);
94
+ }
90
95
  }
91
96
  } else if(crowdinPathSections[0] === 'dashboard' && appDirectoryId) {
92
97
  if(crowdinPathSections[1] === 'en.json') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@enplug/scripts",
3
- "version": "1.11.4-dev52",
3
+ "version": "1.11.4-dev54",
4
4
  "description": "Enplug scripts",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",