@enplug/scripts 1.11.4-dev2 → 1.11.4-dev20

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,16 +109,19 @@ function getCrowdinConfig() {
109
109
  }
110
110
 
111
111
  function generateFormData(crowdinPath, localPath) {
112
+ // const reader = new FileReader();
113
+ const buffer = fs.readFileSync(localPath);
114
+ console.log('buffer',buffer);
112
115
  const formData = new FormData();
113
116
 
114
117
  // formData.append('update_option', 'update_without_changes'); // Previous translations should remain valid
115
- formData.append('json', '');
116
- formData.append(`files[${crowdinPath}]`, fs.createReadStream(localPath));
117
- formData.append(`export_patterns[${crowdinPath}]`, '%locale%.json');
118
+ // formData.append('json', '');
119
+ formData.append('file', buffer, 'en.json');
120
+ // formData.append(`export_patterns[${crowdinPath}]`, '%locale%.json');
118
121
  return formData;
119
122
  }
120
123
 
121
- function postFileToCrowdin(operation, credentials, crowdinPath, localPath) {
124
+ function postFileToCrowdin(credentials, crowdinPath, localPath) {
122
125
  const AuthStr = 'Bearer '.concat(credentials.token);
123
126
  const formData = generateFormData(crowdinPath, localPath);
124
127
 
@@ -137,28 +140,32 @@ async function findCrowdinAppDirectoryId(credentials, crowdinPath) {
137
140
  const appName = path.split('/')[1];
138
141
  const url = `${CROWDIN_PROJECT_URL}/directories?filter=${appName}`;
139
142
  const AuthStr = 'Bearer '.concat(credentials.token);
140
- const directories = await axios.get(url, { headers: { Authorization: AuthStr } });
141
- return directories.data.find(d => d.data.name === appName).id;
143
+ const resp = await axios.get(url, { headers: { Authorization: AuthStr } });
144
+ const directory = resp.data.data.find(d => d.data.name === appName );
145
+ return directory.data.id
142
146
  } else if(path.startsWith('dashboard')) {
143
147
  const url = `${CROWDIN_PROJECT_URL}/directories?filter=dashboard`;
144
148
  const AuthStr = 'Bearer '.concat(credentials.token);
145
- const directories = axios.get(url, { headers: { Authorization: AuthStr } });
146
- return directories.data.find(d => d.data.name === 'dashboard' && d.data.title === 'Dashboard' && d.data.path === '/dashboard').id;
149
+ const resp = axios.get(url, { headers: { Authorization: AuthStr } });
150
+ const directory = resp.data.data.find(d => d.data.name === 'dashboard' && d.data.title === 'Dashboard' && d.data.path === '/dashboard');
151
+ return directory.data.id;
147
152
  }
148
153
  }
149
154
 
150
155
  async function findCrowdinAppSubFolderId(credentials, directoryId, subfolderName) {
151
156
  const url = `${CROWDIN_PROJECT_URL}/directories?directoryId=${directoryId}`;
152
157
  const AuthStr = 'Bearer '.concat(credentials.token);
153
- const directories = await axios.get(url, { headers: { Authorization: AuthStr } });
154
- return directories.data.find(d => d.data.name === subfolderName).id;
158
+ const resp = await axios.get(url, { headers: { Authorization: AuthStr } });
159
+ const subdirectory = resp.data.data.find(d => d.data.name === subfolderName)
160
+ return subdirectory.data.id;
155
161
  }
156
162
 
157
163
  async function getFileIdIfExists(credentials, directoryId, fileName) {
158
164
  const url = `${CROWDIN_PROJECT_URL}/files?directoryId=${directoryId}`;
159
165
  const AuthStr = 'Bearer '.concat(credentials.token);
160
- const files = await axios.get(url, { headers: { Authorization: AuthStr } });
161
- return files.data.find(d => d.data.name === fileName).id;
166
+ const resp = await axios.get(url, { headers: { Authorization: AuthStr } });
167
+ const file = resp.data.data.find(d => d.data.name === fileName);
168
+ return file.data.id;
162
169
  }
163
170
 
164
171
  async function uploadFileToCrowdinStorage(credentials, crowdinPath, localPath) {
@@ -167,15 +174,15 @@ async function uploadFileToCrowdinStorage(credentials, crowdinPath, localPath) {
167
174
  throw new Error('Local file does not exist');
168
175
  }
169
176
 
170
- return postFileToCrowdin('update', credentials, crowdinPath, localPath).pipe(
177
+ return postFileToCrowdin(credentials, crowdinPath, localPath).pipe(
171
178
  catchError(error => {
172
- if (error.response.status === HTTP_NOT_FOUND_STATUS_CODE) {
173
- return promptAddFile(crowdinPath).pipe(
174
- filter(({addFileConfirm}) => addFileConfirm === true),
175
- switchMap(() => postFileToCrowdin('add', credentials, crowdinPath, localPath))
176
- );
177
- }
178
-
179
+ // if (error.response.status === HTTP_NOT_FOUND_STATUS_CODE) {
180
+ // return promptAddFile(crowdinPath).pipe(
181
+ // filter(({addFileConfirm}) => addFileConfirm === true),
182
+ // switchMap(() => postFileToCrowdin(credentials, crowdinPath, localPath))
183
+ // );
184
+ // }
185
+ console('ERROR could not upload file to crowdin storage')
179
186
  return throwError(error);
180
187
  }),
181
188
  tap({
@@ -206,6 +213,8 @@ async function uploadFileToCrowdinStorage(credentials, crowdinPath, localPath) {
206
213
  }
207
214
 
208
215
  function updateCrowdinFile(credentials, storageId, fileId) {
216
+ console.log('storageId', storageId);
217
+ console.log('fileId', fileId);
209
218
  const url = `${CROWDIN_PROJECT_URL}/files/${fileId}`;
210
219
  const AuthStr = 'Bearer '.concat(credentials.token);
211
220
  const body = {
@@ -62,17 +62,15 @@ async function syncTranslations(s3Client, bucket) {
62
62
 
63
63
  if (isProduction) {
64
64
  const appDirectoryId = await findCrowdinAppDirectoryId(credentials, config.crowdinPath);
65
- console.log('found directoryId', appDirectoryId);
66
65
  if(config.crowdinPath.includes('apps')) {
67
- const path = crowdinPath.startsWith('/') ? crowdinPath.substr(1) : crowdinPath;
66
+ const path = config.crowdinPath.startsWith('/') ? config.crowdinPath.substr(1) : config.crowdinPath;
68
67
  const subfolderName = path.split('/')[2];
69
68
  const folderId = await findCrowdinAppSubFolderId(credentials, appDirectoryId, subfolderName);
70
- console.log('found folderId', folderId);
71
- const fileId = await getFileIdIfExists(credentials, appDirectoryId, path.split('/')[3]);
72
- console.log('found fileId', fileId);
73
- const storageId = await uploadFileToCrowdinStorage(credentials, config.crowdinPath, config.localPath)
74
- if(fileId) {
75
- await updateCrowdinFile(credentials, storageId, fileId);
69
+ const fileId = await getFileIdIfExists(credentials, folderId, path.split('/')[3]);
70
+ const storageId = await uploadFileToCrowdinStorage(credentials, config.crowdinPath, config.localPath);
71
+ if(fileId && storageId) {
72
+ const response = await updateCrowdinFile(credentials, storageId.data.data.id, fileId);
73
+ console.log('response', response.data);
76
74
  }
77
75
  } else {
78
76
  // TODO Update dashboard transtlations file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@enplug/scripts",
3
- "version": "1.11.4-dev2",
3
+ "version": "1.11.4-dev20",
4
4
  "description": "Enplug scripts",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",