locize-cli 7.12.2 → 7.12.5

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.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,19 @@ All notable changes to this project will be documented in this file.
5
5
  Project versioning adheres to [Semantic Versioning](http://semver.org/).
6
6
  Change log format is based on [Keep a Changelog](http://keepachangelog.com/).
7
7
 
8
+ ## [7.12.5](https://github.com/locize/locize-cli/compare/v7.12.4...v7.12.5) - 2022-08-25
9
+
10
+ - update dependencies
11
+
12
+ ## [7.12.4](https://github.com/locize/locize-cli/compare/v7.12.3...v7.12.4) - 2022-07-20
13
+
14
+ - optimize update handling
15
+ - update dependencies
16
+
17
+ ## [7.12.3](https://github.com/locize/locize-cli/compare/v7.12.2...v7.12.3) - 2022-07-20
18
+
19
+ - update dependencies
20
+
8
21
  ## [7.12.2](https://github.com/locize/locize-cli/compare/v7.12.1...v7.12.2) - 2022-07-12
9
22
 
10
23
  - limit parallel downloads
package/download.js CHANGED
@@ -95,7 +95,7 @@ function handleDownload(opt, url, err, res, downloads, cb) {
95
95
 
96
96
  function handlePull(opt, toDownload, cb) {
97
97
  const url = opt.apiPath + '/pull/' + opt.projectId + '/' + opt.version;
98
- async.eachLimit(toDownload, 20, (download, clb) => {
98
+ async.eachLimit(toDownload, 5, (download, clb) => {
99
99
  const lng = download.language;
100
100
  const namespace = download.namespace;
101
101
 
@@ -2,7 +2,9 @@ const request = require('./request');
2
2
  const flatten = require('flat');
3
3
  const sortFlatResources = require('./sortFlatResources');
4
4
 
5
- const getRemoteNamespace = (opt, lng, ns, cb) => {
5
+ const getRandomDelay = (delayFrom, delayTo) => Math.floor(Math.random() * delayTo) + delayFrom;
6
+
7
+ const getRemoteNamespace = (opt, lng, ns, cb, retry) => {
6
8
  request(opt.apiPath + (opt.isPrivate ? '/private' : opt.unpublished ? '/pull' : '') + '/' + opt.projectId + '/' + opt.version + '/' + lng + '/' + ns + '?ts=' + Date.now(), {
7
9
  method: 'get',
8
10
  headers: (opt.isPrivate || opt.unpublished) ? {
@@ -11,6 +13,13 @@ const getRemoteNamespace = (opt, lng, ns, cb) => {
11
13
  }, (err, res, obj) => {
12
14
  if (err) return cb(err);
13
15
  if (res.status >= 300) {
16
+ retry = retry || 0;
17
+ if (retry < 3 && res.status !== 401) {
18
+ setTimeout(() => {
19
+ getRemoteNamespace(opt, lng, ns, cb, retry + 1);
20
+ }, opt.unpublished ? getRandomDelay(3000, 10000) : getRandomDelay(100, 1000));
21
+ return;
22
+ }
14
23
  if (obj && (obj.errorMessage || obj.message)) {
15
24
  return cb(new Error((obj.errorMessage || obj.message)));
16
25
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "locize-cli",
3
- "version": "7.12.2",
3
+ "version": "7.12.5",
4
4
  "description": "locize cli to import locales",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -10,16 +10,16 @@
10
10
  "@js.properties/properties": "0.5.4",
11
11
  "android-string-resource": "2.3.4",
12
12
  "async": "3.2.4",
13
- "cacheable-lookup": "6.0.4",
13
+ "cacheable-lookup": "6.1.0",
14
14
  "colors": "1.4.0",
15
- "commander": "9.3.0",
15
+ "commander": "9.4.0",
16
16
  "csvjson": "5.1.0",
17
17
  "diff": "5.1.0",
18
18
  "flat": "5.0.2",
19
19
  "fluent_conv": "3.1.0",
20
- "gettext-converter": "1.2.2",
20
+ "gettext-converter": "1.2.3",
21
21
  "https-proxy-agent": "5.0.1",
22
- "ini": "3.0.0",
22
+ "ini": "3.0.1",
23
23
  "js-yaml": "4.1.0",
24
24
  "laravelphp": "2.0.3",
25
25
  "lodash.clonedeep": "4.5.0",
@@ -29,13 +29,13 @@
29
29
  "rimraf": "3.0.2",
30
30
  "strings-file": "0.0.5",
31
31
  "tmexchange": "2.0.4",
32
- "xliff": "6.0.3",
32
+ "xliff": "6.1.0",
33
33
  "xlsx": "0.18.5"
34
34
  },
35
35
  "devDependencies": {
36
- "eslint": "8.17.0",
36
+ "eslint": "8.22.0",
37
37
  "gh-release": "6.0.4",
38
- "pkg": "5.7.0"
38
+ "pkg": "5.8.0"
39
39
  },
40
40
  "scripts": {
41
41
  "lint": "eslint .",
package/sync.js CHANGED
@@ -205,7 +205,7 @@ const downloadAll = (opt, remoteLanguages, omitRef, manipulate, cb) => {
205
205
  return lng !== opt.referenceLanguage;
206
206
  });
207
207
  }
208
- async.eachLimit(downloads, 20, (download, clb) => {
208
+ async.eachLimit(downloads, opt.unpublished ? 5 : 20, (download, clb) => {
209
209
  const splitted = download.key.split('/');
210
210
  const lng = splitted[download.isPrivate ? 3 : 2];
211
211
  const namespace = splitted[download.isPrivate ? 4 : 3];
@@ -254,14 +254,15 @@ const update = (opt, lng, ns, shouldOmit, cb) => {
254
254
  ns.diff.toUpdate.forEach((k) => data[k] = ns.content[k]);
255
255
  }
256
256
 
257
- if (Object.keys(data).length === 0) return cb(null);
257
+ var keysToSend = Object.keys(data).length;
258
+ if (keysToSend === 0) return cb(null);
258
259
 
259
260
  if (opt.dry) return cb(null);
260
261
 
261
262
  var payloadKeysLimit = 1000;
262
263
 
263
- function send(d, clb, isRetrying) {
264
- request(opt.apiPath + '/update/' + opt.projectId + '/' + opt.version + '/' + lng + '/' + ns.namespace + (shouldOmit ? '?omitstatsgeneration=true' : ''), {
264
+ function send(d, so, clb, isRetrying) {
265
+ request(opt.apiPath + '/update/' + opt.projectId + '/' + opt.version + '/' + lng + '/' + ns.namespace + (so ? '?omitstatsgeneration=true' : ''), {
265
266
  method: 'post',
266
267
  body: d,
267
268
  headers: {
@@ -270,7 +271,7 @@ const update = (opt, lng, ns, shouldOmit, cb) => {
270
271
  }, (err, res, obj) => {
271
272
  if (err) return clb(err);
272
273
  if (res.status === 504 && !isRetrying) {
273
- return setTimeout(() => send(d, clb, true), 3000);
274
+ return setTimeout(() => send(d, so, clb, true), 3000);
274
275
  }
275
276
  if (res.status >= 300 && res.status !== 412) {
276
277
  if (obj && (obj.errorMessage || obj.message)) {
@@ -282,7 +283,7 @@ const update = (opt, lng, ns, shouldOmit, cb) => {
282
283
  });
283
284
  }
284
285
 
285
- if (Object.keys(data).length > payloadKeysLimit) {
286
+ if (keysToSend > payloadKeysLimit) {
286
287
  var tasks = [];
287
288
  var keysInObj = Object.keys(data);
288
289
 
@@ -290,7 +291,8 @@ const update = (opt, lng, ns, shouldOmit, cb) => {
290
291
  (function() {
291
292
  var pagedData = {};
292
293
  keysInObj.splice(0, payloadKeysLimit).forEach((k) => pagedData[k] = data[k]);
293
- tasks.push((c) => send(pagedData, c));
294
+ var hasMoreKeys = keysInObj.length > 0;
295
+ tasks.push((c) => send(pagedData, hasMoreKeys ? true : shouldOmit, c));
294
296
  })();
295
297
  }
296
298
 
@@ -298,13 +300,13 @@ const update = (opt, lng, ns, shouldOmit, cb) => {
298
300
 
299
301
  var finalPagedData = {};
300
302
  keysInObj.splice(0, keysInObj.length).forEach((k) => finalPagedData[k] = data[k]);
301
- tasks.push((c) => send(finalPagedData, c));
303
+ tasks.push((c) => send(finalPagedData, shouldOmit, c));
302
304
 
303
305
  async.series(tasks, cb);
304
306
  return;
305
307
  }
306
308
 
307
- send(data, cb);
309
+ send(data, shouldOmit, cb);
308
310
  };
309
311
 
310
312
  const cleanupLanguages = (opt, remoteLanguages) => {