@enplug/scripts 1.11.4-dev45 → 1.11.4-dev47

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.
@@ -14,9 +14,7 @@ const { catchError, switchMap, tap, filter } = require('rxjs/operators');
14
14
  const HTTP_UNAUTHORIZED_STATUS_CODE = 401;
15
15
  const HTTP_NOT_FOUND_STATUS_CODE = 404;
16
16
 
17
- // const CROWDIN_PROJECT_ID = 'enplug';
18
17
  const CROWDIN_PROJECT_ID = '401630';
19
- // const CROWDIN_PROJECT_URL = `https://api.crowdin.com/api/project/${CROWDIN_PROJECT_ID}`;
20
18
  const CROWDIN_PROJECT_URL = `https://api.crowdin.com/api/v2/projects/${CROWDIN_PROJECT_ID}`;
21
19
  const CROWDIN_STORAGE_URL = `https://api.crowdin.com/api/v2/storages`;
22
20
  const CROWDIN_DIRECTORY_NOT_FOUND_ERROR_CODE = 17;
@@ -113,9 +111,17 @@ async function findCrowdinAppDirectoryId(credentials, crowdinPath, appName) {
113
111
  if(crowdinPath.startsWith('apps')){
114
112
  const url = `${CROWDIN_PROJECT_URL}/directories?filter=${appName}`;
115
113
  const AuthStr = 'Bearer '.concat(credentials.token);
116
- const resp = await axios.get(url, { headers: { Authorization: AuthStr } });
117
- const directory = resp.data.data.find(d => d.data.name === appName );
118
- return directory ? directory.data.id : undefined;
114
+ try {
115
+ const resp = await axios.get(url, { headers: { Authorization: AuthStr } });
116
+ const directory = resp.data.data.find(d => d.data.name === appName );
117
+ return directory ? directory.data.id : undefined;
118
+ } catch (err) {
119
+ if (error.response.status === HTTP_UNAUTHORIZED_STATUS_CODE) {
120
+ console.error(`\n${chalk.red.bold('Provided Crowdin token is invalid')}`);
121
+ console.log(`Check the ${chalk.default.yellow('dev.private.json')} file.`);
122
+ throw new Error('Could not get Crowdin config');
123
+ }
124
+ }
119
125
  } else if(crowdinPath.startsWith('dashboard')) {
120
126
  const url = `${CROWDIN_PROJECT_URL}/directories?filter=dashboard`;
121
127
  const AuthStr = 'Bearer '.concat(credentials.token);
@@ -167,7 +173,6 @@ async function uploadFileToCrowdinStorage(credentials, localPath) {
167
173
  }
168
174
 
169
175
  async function updateCrowdinFile(credentials, crowdinPath, storageId, fileId) {
170
- console.log('fileId', fileId);
171
176
  const url = `${CROWDIN_PROJECT_URL}/files/${fileId}`;
172
177
  const AuthStr = 'Bearer '.concat(credentials.token);
173
178
  const body = {
@@ -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 could not find app ${chalk.yellow.bold(`[${appName}]`)} directory`)
69
+ console.log(`ERROR could not find app ${chalk.yellow.bold(`[${appName}]`)} directory`)
70
70
  return throwError(error);
71
71
  }
72
72
  if(crowdinPathSections[0] === 'apps' && appDirectoryId) {
@@ -83,7 +83,6 @@ async function syncTranslations(s3Client, bucket) {
83
83
  const storageId = await uploadFileToCrowdinStorage(credentials, config.localPath);
84
84
  if(fileId && storageId) {
85
85
  const response = await updateCrowdinFile(credentials, crowdinPath, storageId.data.data.id, fileId);
86
- console.log('response', response);
87
86
  }
88
87
  } else {
89
88
  //TODO add file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@enplug/scripts",
3
- "version": "1.11.4-dev45",
3
+ "version": "1.11.4-dev47",
4
4
  "description": "Enplug scripts",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",