locize-cli 7.6.17 → 7.7.0
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 +6 -0
- package/README.md +2 -0
- package/package.json +1 -1
- package/request.js +15 -1
- package/sync.js +62 -25
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,12 @@ 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.7.0](https://github.com/locize/locize-cli/compare/v7.6.17...v7.7.0) - 2021-12-08
|
|
9
|
+
|
|
10
|
+
- sync: optimize api requests on bigger projects
|
|
11
|
+
- retry on very short dns resolution errors
|
|
12
|
+
|
|
13
|
+
|
|
8
14
|
## [7.6.17](https://github.com/locize/locize-cli/compare/v7.6.16...v7.6.17) - 2021-09-21
|
|
9
15
|
|
|
10
16
|
- check skipEmpty flag when downloading translations
|
package/README.md
CHANGED
|
@@ -91,6 +91,8 @@ locize download --project-id my-project-id-93e1-442a-ab35-24331fa294ba --ver lat
|
|
|
91
91
|
By using the sync command, you can keep your existing code setup and synchronize the translations with locize.
|
|
92
92
|
An example on how this could look like can be seen in [this tutorial](https://github.com/locize/react-tutorial#step-1---keep-existing-code-setup-but-synchronize-with-locize).
|
|
93
93
|
|
|
94
|
+
**⚠️ Since the remote source are the published translations, make sure the desired version is set to standard publish mode, or alternatively [publish](#publish-version) that version before you execute the cli command. ⚠️**
|
|
95
|
+
|
|
94
96
|
### Step 1: Go near to your translation files
|
|
95
97
|
|
|
96
98
|
```sh
|
package/package.json
CHANGED
package/request.js
CHANGED
|
@@ -22,5 +22,19 @@ module.exports = (url, options, callback) => {
|
|
|
22
22
|
} else {
|
|
23
23
|
return { res };
|
|
24
24
|
}
|
|
25
|
-
}).then((ret) => callback(null, ret.res, ret.obj)).catch(
|
|
25
|
+
}).then((ret) => callback(null, ret.res, ret.obj)).catch((err) => {
|
|
26
|
+
if (err && err.message && err.message.indexOf('ENOTFOUND') > -1) {
|
|
27
|
+
setTimeout(() => {
|
|
28
|
+
fetch(url, options).then((res) => {
|
|
29
|
+
if (res.headers.get('content-type') && res.headers.get('content-type').indexOf('json') > 0) {
|
|
30
|
+
return new Promise((resolve, reject) => res.json().then((obj) => resolve({ res, obj })).catch(reject));
|
|
31
|
+
} else {
|
|
32
|
+
return { res };
|
|
33
|
+
}
|
|
34
|
+
}).then((ret) => callback(null, ret.res, ret.obj)).catch(callback);
|
|
35
|
+
}, 3000);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
callback(err);
|
|
39
|
+
});
|
|
26
40
|
};
|
package/sync.js
CHANGED
|
@@ -198,7 +198,7 @@ const downloadAll = (opt, remoteLanguages, omitRef, manipulate, cb) => {
|
|
|
198
198
|
});
|
|
199
199
|
};
|
|
200
200
|
|
|
201
|
-
const update = (opt, lng, ns, cb) => {
|
|
201
|
+
const update = (opt, lng, ns, shouldOmit, cb) => {
|
|
202
202
|
var data = {};
|
|
203
203
|
if (!opt.skipDelete) {
|
|
204
204
|
ns.diff.toRemove.forEach((k) => data[k] = null);
|
|
@@ -215,7 +215,7 @@ const update = (opt, lng, ns, cb) => {
|
|
|
215
215
|
var payloadKeysLimit = 1000;
|
|
216
216
|
|
|
217
217
|
function send(d, clb, isRetrying) {
|
|
218
|
-
request(opt.apiPath + '/update/' + opt.projectId + '/' + opt.version + '/' + lng + '/' + ns.namespace, {
|
|
218
|
+
request(opt.apiPath + '/update/' + opt.projectId + '/' + opt.version + '/' + lng + '/' + ns.namespace + (shouldOmit ? '?omitstatsgeneration=true' : ''), {
|
|
219
219
|
method: 'post',
|
|
220
220
|
body: d,
|
|
221
221
|
headers: {
|
|
@@ -321,6 +321,20 @@ const handleSync = (opt, remoteLanguages, localNamespaces, cb) => {
|
|
|
321
321
|
compareNamespaces(opt, localNamespaces, (err, compared) => {
|
|
322
322
|
if (err) return handleError(err);
|
|
323
323
|
|
|
324
|
+
const onlyToUpdate = compared.filter((ns) => ns.diff.toAdd.concat(opt.skipDelete ? [] : ns.diff.toRemove).concat(ns.diff.toUpdate).length > 0);
|
|
325
|
+
|
|
326
|
+
const lngsInReqs = [];
|
|
327
|
+
const nsInReqs = [];
|
|
328
|
+
onlyToUpdate.forEach((n) => {
|
|
329
|
+
if (lngsInReqs.indexOf(n.language) < 0) {
|
|
330
|
+
lngsInReqs.push(n.language);
|
|
331
|
+
}
|
|
332
|
+
if (nsInReqs.indexOf(n.namespace) < 0) {
|
|
333
|
+
nsInReqs.push(n.namespace);
|
|
334
|
+
}
|
|
335
|
+
});
|
|
336
|
+
const shouldOmit = lngsInReqs.length > 5 || nsInReqs.length > 5;
|
|
337
|
+
|
|
324
338
|
var wasThereSomethingToUpdate = false;
|
|
325
339
|
async.eachLimit(compared, Math.round(require('os').cpus().length / 2), (ns, clb) => {
|
|
326
340
|
if (!cb) {
|
|
@@ -364,40 +378,63 @@ const handleSync = (opt, remoteLanguages, localNamespaces, cb) => {
|
|
|
364
378
|
if (!somethingToUpdate) console.log(colors.grey(`nothing to update for ${ns.language}/${ns.namespace}`));
|
|
365
379
|
if (!wasThereSomethingToUpdate && somethingToUpdate) wasThereSomethingToUpdate = true;
|
|
366
380
|
}
|
|
367
|
-
update(opt, ns.language, ns, (err) => {
|
|
381
|
+
update(opt, ns.language, ns, shouldOmit, (err) => {
|
|
368
382
|
if (err) return clb(err);
|
|
369
383
|
if (ns.diff.toRemove.length === 0 || ns.language !== opt.referenceLanguage) return clb();
|
|
370
384
|
const nsOnlyRemove = cloneDeep(ns);
|
|
371
385
|
nsOnlyRemove.diff.toAdd = [];
|
|
372
386
|
nsOnlyRemove.diff.toUpdate = [];
|
|
373
|
-
async.eachLimit(remoteLanguages, Math.round(require('os').cpus().length / 2), (lng, clb) => update(opt, lng, nsOnlyRemove, clb), clb);
|
|
387
|
+
async.eachLimit(remoteLanguages, Math.round(require('os').cpus().length / 2), (lng, clb) => update(opt, lng, nsOnlyRemove, shouldOmit, clb), clb);
|
|
374
388
|
});
|
|
375
389
|
}, (err) => {
|
|
376
390
|
if (err) return handleError(err);
|
|
377
|
-
|
|
378
391
|
if (!cb) console.log(colors.grey('syncing...'));
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
+
|
|
393
|
+
function down() {
|
|
394
|
+
setTimeout(() => { // wait a bit before downloading... just to have a chance to get the newly published files
|
|
395
|
+
downloadAll(opt, remoteLanguages, false, opt.skipDelete ? (lng, namespace, ns) => {
|
|
396
|
+
const found = compared.find((n) => n.namespace === namespace && n.language === lng);
|
|
397
|
+
if (found && found.diff) {
|
|
398
|
+
if (found.diff.toAddLocally && found.diff.toAddLocally.length > 0) {
|
|
399
|
+
found.diff.toAddLocally.forEach((k) => {
|
|
400
|
+
delete ns[k];
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
if (found.diff.toRemove && found.diff.toRemove.length > 0) {
|
|
404
|
+
found.diff.toRemove.forEach((k) => {
|
|
405
|
+
delete ns[k];
|
|
406
|
+
});
|
|
407
|
+
}
|
|
392
408
|
}
|
|
409
|
+
} : undefined, (err) => {
|
|
410
|
+
if (err) return handleError(err);
|
|
411
|
+
if (!cb) console.log(colors.green('FINISHED'));
|
|
412
|
+
if (cb) cb(null);
|
|
413
|
+
});
|
|
414
|
+
}, wasThereSomethingToUpdate && !opt.dry ? 5000 : 0);
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
if (!shouldOmit) return down();
|
|
418
|
+
if (opt.dry) return down();
|
|
419
|
+
|
|
420
|
+
// optimize stats generation...
|
|
421
|
+
request(opt.apiPath + '/stats/project/regenerate/' + opt.projectId + '/' + opt.version + (lngsInReqs.length === 1 ? `/${lngsInReqs[0]}` : '') + (nsInReqs.length === 1 ? `?namespace=${nsInReqs[0]}` : ''), {
|
|
422
|
+
method: 'post',
|
|
423
|
+
body: {},
|
|
424
|
+
headers: {
|
|
425
|
+
'Authorization': opt.apiKey
|
|
426
|
+
}
|
|
427
|
+
}, (err, res, obj) => {
|
|
428
|
+
if (err) return handleError(err);
|
|
429
|
+
if (res.status >= 300 && res.status !== 412) {
|
|
430
|
+
if (obj && (obj.errorMessage || obj.message)) {
|
|
431
|
+
return handleError(new Error((obj.errorMessage || obj.message)));
|
|
393
432
|
}
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
}, wasThereSomethingToUpdate && !opt.dry ? 5000 : 0);
|
|
400
|
-
}); // wait a bit before downloading... just to have a chance to get the newly published files
|
|
433
|
+
return handleError(new Error(res.statusText + ' (' + res.status + ')'));
|
|
434
|
+
}
|
|
435
|
+
down();
|
|
436
|
+
});
|
|
437
|
+
});
|
|
401
438
|
});
|
|
402
439
|
});
|
|
403
440
|
};
|