locize-cli 7.12.4 → 7.12.7
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 +12 -0
- package/getRemoteNamespace.js +60 -2
- package/package.json +3 -3
- package/sync.js +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,18 @@ 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.7](https://github.com/locize/locize-cli/compare/v7.12.6...v7.12.7) - 2022-09-09
|
|
9
|
+
|
|
10
|
+
- fix for #75
|
|
11
|
+
|
|
12
|
+
## [7.12.6](https://github.com/locize/locize-cli/compare/v7.12.5...v7.12.6) - 2022-08-26
|
|
13
|
+
|
|
14
|
+
- internal optimization of unpublished download workflow
|
|
15
|
+
|
|
16
|
+
## [7.12.5](https://github.com/locize/locize-cli/compare/v7.12.4...v7.12.5) - 2022-08-25
|
|
17
|
+
|
|
18
|
+
- update dependencies
|
|
19
|
+
|
|
8
20
|
## [7.12.4](https://github.com/locize/locize-cli/compare/v7.12.3...v7.12.4) - 2022-07-20
|
|
9
21
|
|
|
10
22
|
- optimize update handling
|
package/getRemoteNamespace.js
CHANGED
|
@@ -2,10 +2,68 @@ const request = require('./request');
|
|
|
2
2
|
const flatten = require('flat');
|
|
3
3
|
const sortFlatResources = require('./sortFlatResources');
|
|
4
4
|
|
|
5
|
+
const getRandomDelay = (delayFrom, delayTo) => Math.floor(Math.random() * delayTo) + delayFrom;
|
|
6
|
+
|
|
7
|
+
const pullNamespacePaged = (opt, lng, ns, cb, next, retry) => {
|
|
8
|
+
next = next || '';
|
|
9
|
+
request(opt.apiPath + '/pull/' + opt.projectId + '/' + opt.version + '/' + lng + '/' + ns + '?' + 'next=' + next + '&ts=' + Date.now(), {
|
|
10
|
+
method: 'get',
|
|
11
|
+
headers: {
|
|
12
|
+
'Authorization': opt.apiKey
|
|
13
|
+
}
|
|
14
|
+
}, (err, res, obj) => {
|
|
15
|
+
if (err) return cb(err);
|
|
16
|
+
if (res.status >= 300) {
|
|
17
|
+
retry = retry || 0;
|
|
18
|
+
if (retry < 3 && res.status !== 401) {
|
|
19
|
+
setTimeout(() => {
|
|
20
|
+
pullNamespacePaged(opt, lng, ns, cb, next, retry + 1);
|
|
21
|
+
}, getRandomDelay(3000, 10000));
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (obj && (obj.errorMessage || obj.message)) {
|
|
25
|
+
return cb(new Error((obj.errorMessage || obj.message)));
|
|
26
|
+
}
|
|
27
|
+
return cb(new Error(res.statusText + ' (' + res.status + ')'));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
cb(null, {
|
|
31
|
+
result: sortFlatResources(flatten(obj)),
|
|
32
|
+
next: res.headers.get('x-next-page'),
|
|
33
|
+
lastModified: res.headers.get('last-modified') ? new Date(res.headers.get('last-modified')) : undefined
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const pullNamespace = (opt, lng, ns, cb) => {
|
|
39
|
+
var ret = {};
|
|
40
|
+
var lastModified = new Date(2000, 0, 1);
|
|
41
|
+
(function nextPage(next) {
|
|
42
|
+
pullNamespacePaged(opt, lng, ns, (err, info) => {
|
|
43
|
+
if (err) return cb(err);
|
|
44
|
+
|
|
45
|
+
Object.keys(info.result).forEach((k) => {
|
|
46
|
+
ret[k] = info.result[k];
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
if (info.lastModified.getTime() > lastModified.getTime()) {
|
|
50
|
+
lastModified = info.lastModified;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (info.next) {
|
|
54
|
+
return nextPage(info.next);
|
|
55
|
+
}
|
|
56
|
+
cb(null, ret, lastModified);
|
|
57
|
+
}, next);
|
|
58
|
+
})();
|
|
59
|
+
};
|
|
60
|
+
|
|
5
61
|
const getRemoteNamespace = (opt, lng, ns, cb) => {
|
|
6
|
-
|
|
62
|
+
if (opt.unpublished) return pullNamespace(opt, lng, ns, cb);
|
|
63
|
+
|
|
64
|
+
request(opt.apiPath + (opt.isPrivate ? '/private' : '') + '/' + opt.projectId + '/' + opt.version + '/' + lng + '/' + ns + '?ts=' + Date.now(), {
|
|
7
65
|
method: 'get',
|
|
8
|
-
headers:
|
|
66
|
+
headers: opt.isPrivate ? {
|
|
9
67
|
'Authorization': opt.apiKey
|
|
10
68
|
} : undefined
|
|
11
69
|
}, (err, res, obj) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "locize-cli",
|
|
3
|
-
"version": "7.12.
|
|
3
|
+
"version": "7.12.7",
|
|
4
4
|
"description": "locize cli to import locales",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"fluent_conv": "3.1.0",
|
|
20
20
|
"gettext-converter": "1.2.3",
|
|
21
21
|
"https-proxy-agent": "5.0.1",
|
|
22
|
-
"ini": "3.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",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"xlsx": "0.18.5"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"eslint": "8.
|
|
36
|
+
"eslint": "8.22.0",
|
|
37
37
|
"gh-release": "6.0.4",
|
|
38
38
|
"pkg": "5.8.0"
|
|
39
39
|
},
|
package/sync.js
CHANGED
|
@@ -110,7 +110,7 @@ const compareNamespace = (local, remote, lastModifiedLocal, lastModifiedRemote)
|
|
|
110
110
|
}
|
|
111
111
|
if (
|
|
112
112
|
remote[k] && (
|
|
113
|
-
(typeof local[k] === 'object' && local[k].value && remote[k] !== local[k].value) ||
|
|
113
|
+
(typeof local[k] === 'object' && local[k] && local[k].value && remote[k] !== local[k].value) ||
|
|
114
114
|
(typeof local[k] !== 'object' && remote[k] !== local[k])
|
|
115
115
|
)
|
|
116
116
|
) {
|