locize-cli 8.6.0 → 8.6.2

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,14 @@ 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
+ ## [8.6.2](https://github.com/locize/locize-cli/compare/v8.6.1...v8.6.2) - 2025-03-18
9
+
10
+ - fix migrate command to handle paged update
11
+
12
+ ## [8.6.1](https://github.com/locize/locize-cli/compare/v8.6.0...v8.6.1) - 2025-03-11
13
+
14
+ - fix .yml yaml format variats to address [104](https://github.com/locize/locize-cli/issues/104)
15
+
8
16
  ## [8.6.0](https://github.com/locize/locize-cli/compare/v8.5.1...v8.6.0) - 2025-03-10
9
17
 
10
18
  - introduce .yml yaml format variats to address [104](https://github.com/locize/locize-cli/issues/104)
@@ -117,19 +117,28 @@ const convertToFlatFormat = (opt, data, lng, cb) => {
117
117
  cb(null, data);
118
118
  return;
119
119
  }
120
- if (opt.format === 'yaml') {
120
+ if (
121
+ opt.format === 'yaml' ||
122
+ opt.format === 'yml'
123
+ ) {
121
124
  const d = data.toString();
122
125
  if (!d || d === '') return cb(null, {});
123
126
  cb(null, flatten(jsyaml.load(d)));
124
127
  return;
125
128
  }
126
- if (opt.format === 'yaml-nested') {
129
+ if (
130
+ opt.format === 'yaml-nested' ||
131
+ opt.format === 'yml-nested'
132
+ ) {
127
133
  const d = data.toString();
128
134
  if (!d || d === '') return cb(null, {});
129
135
  cb(null, flatten(jsyaml.load(d)));
130
136
  return;
131
137
  }
132
- if (opt.format === 'yaml-rails') {
138
+ if (
139
+ opt.format === 'yaml-rails' ||
140
+ opt.format === 'yml-rails'
141
+ ) {
133
142
  const d = data.toString();
134
143
  if (!d || d === '') return cb(null, {});
135
144
  const jsObj = jsyaml.load(d);
package/migrate.js CHANGED
@@ -69,28 +69,79 @@ const transfer = (opt, ns, cb) => {
69
69
 
70
70
  if (!opt.replace) url = url.replace('/update/', '/missing/');
71
71
 
72
- request(url + `?replace=${!!opt.replace}`, {
73
- method: 'post',
74
- body: ns.value,
75
- headers: {
76
- 'Authorization': opt.apiKey
72
+ var data = ns.value;
73
+ var keysToSend = Object.keys(data).length;
74
+ if (keysToSend === 0) return cb(null);
75
+
76
+ var payloadKeysLimit = 1000;
77
+
78
+ function send(d, so, isFirst, clb, isRetrying) {
79
+ const queryParams = new URLSearchParams();
80
+ if (so) {
81
+ queryParams.append('omitstatsgeneration', 'true');
77
82
  }
78
- }, (err, res, obj) => {
79
- if (err || (obj && (obj.errorMessage || obj.message))) {
80
- if (url.indexOf('/missing/') > -1 && res.status === 412) {
81
- console.log(colors.green(`transfered ${opt.version}/${ns.language}/${ns.namespace} (but all keys already existed)...`));
82
- cb(null);
83
- return;
83
+ if (isFirst && opt.replace) {
84
+ queryParams.append('replace', 'true');
85
+ }
86
+
87
+ const queryString = queryParams.size > 0 ? '?' + queryParams.toString() : '';
88
+
89
+ request(url + queryString, {
90
+ method: 'post',
91
+ body: d,
92
+ headers: {
93
+ 'Authorization': opt.apiKey
84
94
  }
85
- console.log(colors.red(`transfer failed for ${opt.version}/${ns.language}/${ns.namespace}...`));
95
+ }, (err, res, obj) => {
96
+ if (err || (obj && (obj.errorMessage || obj.message))) {
97
+ if (url.indexOf('/missing/') > -1 && res.status === 412) {
98
+ console.log(colors.green(`transfered ${Object.keys(d).length} keys ${opt.version}/${ns.language}/${ns.namespace} (but all keys already existed)...`));
99
+ clb(null);
100
+ return;
101
+ }
102
+ if (res.status === 504 && !isRetrying) {
103
+ return setTimeout(() => send(d, so, isFirst, clb, true), 3000);
104
+ }
105
+ console.log(colors.red(`transfer failed for ${Object.keys(d).length} keys ${opt.version}/${ns.language}/${ns.namespace}...`));
86
106
 
87
- if (err) return cb(err);
88
- if (obj && (obj.errorMessage || obj.message)) return cb(new Error((obj.errorMessage || obj.message)));
107
+ if (err) return clb(err);
108
+ if (obj && (obj.errorMessage || obj.message)) return clb(new Error((obj.errorMessage || obj.message)));
109
+ }
110
+ if (res.status >= 300 && res.status !== 412) {
111
+ if (obj && (obj.errorMessage || obj.message)) {
112
+ return clb(new Error((obj.errorMessage || obj.message)));
113
+ }
114
+ return clb(new Error(res.statusText + ' (' + res.status + ')'));
115
+ }
116
+ console.log(colors.green(`transfered ${Object.keys(d).length} keys ${opt.version}/${ns.language}/${ns.namespace}...`));
117
+ clb(null);
118
+ });
119
+ }
120
+
121
+ if (keysToSend > payloadKeysLimit) {
122
+ var tasks = [];
123
+ var keysInObj = Object.keys(data);
124
+
125
+ while (keysInObj.length > payloadKeysLimit) {
126
+ (function() {
127
+ var pagedData = {};
128
+ keysInObj.splice(0, payloadKeysLimit).forEach((k) => pagedData[k] = data[k]);
129
+ var hasMoreKeys = keysInObj.length > 0;
130
+ tasks.push((c) => send(pagedData, hasMoreKeys, false, c));
131
+ })();
89
132
  }
90
- if (res.status >= 300 && res.status !== 412) return cb(new Error(res.statusText + ' (' + res.status + ')'));
91
- console.log(colors.green(`transfered ${opt.version}/${ns.language}/${ns.namespace}...`));
92
- cb(null);
93
- });
133
+
134
+ if (keysInObj.length === 0) return cb(null);
135
+
136
+ var finalPagedData = {};
137
+ keysInObj.splice(0, keysInObj.length).forEach((k) => finalPagedData[k] = data[k]);
138
+ tasks.push((c) => send(finalPagedData, false, false, c));
139
+
140
+ async.series(tasks, cb);
141
+ return;
142
+ }
143
+
144
+ send(data, false, true, cb);
94
145
  };
95
146
 
96
147
  const upload = (opt, nss, cb) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "locize-cli",
3
- "version": "8.6.0",
3
+ "version": "8.6.2",
4
4
  "description": "locize cli to import locales",
5
5
  "main": "index.js",
6
6
  "bin": {
package/sync.js CHANGED
@@ -272,7 +272,6 @@ const update = (opt, lng, ns, shouldOmit, cb) => {
272
272
  queryParams.append('autotranslate', 'true');
273
273
  }
274
274
  if (so) {
275
- // no API docs for this
276
275
  queryParams.append('omitstatsgeneration', 'true');
277
276
  }
278
277