locize-cli 10.3.2 → 10.4.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.
@@ -1,40 +1,40 @@
1
- const request = require('./request');
1
+ const request = require('./request')
2
2
 
3
3
  const getRemoteLanguages = (opt, cb) => {
4
- request(opt.apiPath + '/languages/' + opt.projectId + '?ts=' + Date.now(), {
4
+ request(opt.apiPath + '/languages/' + opt.projectId + '?ts=' + Date.now() + (opt.cdnType === 'standard' ? '&cache=no' : ''), {
5
5
  method: 'get'
6
6
  }, (err, res, obj) => {
7
7
  if (err || (obj && (obj.errorMessage || obj.message))) {
8
- if (err) return cb(err);
8
+ if (err) return cb(err)
9
9
  if (obj && (obj.errorMessage || obj.message)) {
10
10
  if (res && res.statusText && res.status) {
11
- return cb(new Error(res.statusText + ' (' + res.status + ') | ' + (obj.errorMessage || obj.message)));
11
+ return cb(new Error(res.statusText + ' (' + res.status + ') | ' + (obj.errorMessage || obj.message)))
12
12
  }
13
- return cb(new Error((obj.errorMessage || obj.message)));
13
+ return cb(new Error((obj.errorMessage || obj.message)))
14
14
  }
15
15
  }
16
- if (res.status >= 300) return cb(new Error(res.statusText + ' (' + res.status + ')'));
16
+ if (res.status >= 300) return cb(new Error(res.statusText + ' (' + res.status + ')'))
17
17
 
18
18
  if (Object.keys(obj).length === 0) {
19
- return cb(new Error('Project with id "' + opt.projectId + '" not found!'));
19
+ return cb(new Error('Project with id "' + opt.projectId + '" not found!'))
20
20
  }
21
21
 
22
- const lngs = Object.keys(obj);
23
- var foundRefLng = null;
22
+ const lngs = Object.keys(obj)
23
+ let foundRefLng = null
24
24
  lngs.forEach((l) => {
25
- if (obj[l].isReferenceLanguage) foundRefLng = l;
26
- });
25
+ if (obj[l].isReferenceLanguage) foundRefLng = l
26
+ })
27
27
  if (!foundRefLng) {
28
- return cb(new Error('Reference language for project with id "' + opt.projectId + '" not found!'));
28
+ return cb(new Error('Reference language for project with id "' + opt.projectId + '" not found!'))
29
29
  }
30
- opt.referenceLanguage = foundRefLng;
30
+ opt.referenceLanguage = foundRefLng
31
31
 
32
32
  // reflng first
33
- lngs.splice(lngs.indexOf(opt.referenceLanguage), 1);
34
- lngs.unshift(opt.referenceLanguage);
33
+ lngs.splice(lngs.indexOf(opt.referenceLanguage), 1)
34
+ lngs.unshift(opt.referenceLanguage)
35
35
 
36
- cb(null, lngs);
37
- });
38
- };
36
+ cb(null, lngs)
37
+ })
38
+ }
39
39
 
40
- module.exports = getRemoteLanguages;
40
+ module.exports = getRemoteLanguages
@@ -1,118 +1,122 @@
1
- const request = require('./request');
2
- const flatten = require('flat');
3
- const sortFlatResources = require('./sortFlatResources');
1
+ const request = require('./request')
2
+ const flatten = require('flat')
3
+ const sortFlatResources = require('./sortFlatResources')
4
4
 
5
- const getRandomDelay = (delayFrom, delayTo) => Math.floor(Math.random() * delayTo) + delayFrom;
5
+ const getRandomDelay = (delayFrom, delayTo) => Math.floor(Math.random() * delayTo) + delayFrom
6
6
 
7
- function onlyKeysFlat(resources, prefix, ret) {
8
- if (!resources) resources;
9
- ret = ret || {};
7
+ function onlyKeysFlat (resources, prefix, ret) {
8
+ ret = ret || {}
9
+ if (!resources) return ret
10
10
  Object.keys(resources).forEach((k) => {
11
11
  if (typeof resources[k] === 'string' || !resources[k] || typeof resources[k].value === 'string') {
12
12
  if (prefix) {
13
- ret[prefix + '.' + k] = resources[k];
13
+ ret[prefix + '.' + k] = resources[k]
14
14
  } else {
15
- ret[k] = resources[k];
15
+ ret[k] = resources[k]
16
16
  }
17
17
  } else {
18
- onlyKeysFlat(resources[k], prefix ? prefix + '.' + k : k, ret);
18
+ onlyKeysFlat(resources[k], prefix ? prefix + '.' + k : k, ret)
19
19
  }
20
- });
21
- return ret;
20
+ })
21
+ return ret
22
22
  }
23
23
 
24
24
  const pullNamespacePaged = (opt, lng, ns, cb, next, retry) => {
25
- next = next || '';
25
+ next = next || ''
26
26
  request(opt.apiPath + '/pull/' + opt.projectId + '/' + opt.version + '/' + lng + '/' + ns + '?' + 'next=' + next + ((opt.raw || opt.overriddenOnly) ? '&raw=true' : '') + '&ts=' + Date.now(), {
27
27
  method: 'get',
28
28
  headers: {
29
- 'Authorization': opt.apiKey
29
+ Authorization: opt.apiKey
30
30
  }
31
31
  }, (err, res, obj) => {
32
- if (err) return cb(err);
32
+ if (err) return cb(err)
33
33
  if (res.status >= 300) {
34
- retry = retry || 0;
34
+ retry = retry || 0
35
35
  if (retry < 3 && res.status !== 401) {
36
36
  setTimeout(() => {
37
- pullNamespacePaged(opt, lng, ns, cb, next, retry + 1);
38
- }, getRandomDelay(3000, 10000));
39
- return;
37
+ pullNamespacePaged(opt, lng, ns, cb, next, retry + 1)
38
+ }, getRandomDelay(3000, 10000))
39
+ return
40
40
  }
41
41
  if (obj && (obj.errorMessage || obj.message)) {
42
42
  if (res.statusText && res.status) {
43
- return cb(new Error(res.statusText + ' (' + res.status + ') | ' + (obj.errorMessage || obj.message)));
43
+ return cb(new Error(res.statusText + ' (' + res.status + ') | ' + (obj.errorMessage || obj.message)))
44
44
  }
45
- return cb(new Error((obj.errorMessage || obj.message)));
45
+ return cb(new Error((obj.errorMessage || obj.message)))
46
46
  }
47
- return cb(new Error(res.statusText + ' (' + res.status + ')'));
47
+ return cb(new Error(res.statusText + ' (' + res.status + ')'))
48
48
  }
49
49
 
50
50
  if (opt.overriddenOnly && obj) {
51
- const newObj = {};
51
+ const newObj = {}
52
52
  Object.keys(obj).forEach((k) => {
53
53
  if (obj[k].overrides !== undefined) {
54
54
  if (opt.raw) {
55
- newObj[k] = obj[k];
55
+ newObj[k] = obj[k]
56
56
  } else {
57
- newObj[k] = obj[k].value;
57
+ newObj[k] = obj[k].value
58
58
  }
59
59
  }
60
- });
61
- obj = newObj;
60
+ })
61
+ obj = newObj
62
62
  }
63
63
 
64
64
  cb(null, {
65
65
  result: opt.raw ? sortFlatResources(onlyKeysFlat(obj)) : sortFlatResources(flatten(obj)),
66
66
  next: res.headers.get('x-next-page'),
67
67
  lastModified: res.headers.get('last-modified') ? new Date(res.headers.get('last-modified')) : undefined
68
- });
69
- });
70
- };
68
+ })
69
+ })
70
+ }
71
71
 
72
72
  const pullNamespace = (opt, lng, ns, cb) => {
73
- var ret = {};
74
- var lastModified = new Date(2000, 0, 1);
75
- (function nextPage(next) {
73
+ const ret = {}
74
+ let lastModified = new Date(2000, 0, 1);
75
+ (function nextPage (next) {
76
76
  pullNamespacePaged(opt, lng, ns, (err, info) => {
77
- if (err) return cb(err);
77
+ if (err) return cb(err)
78
78
 
79
79
  Object.keys(info.result).forEach((k) => {
80
- ret[k] = info.result[k];
81
- });
80
+ ret[k] = info.result[k]
81
+ })
82
82
 
83
83
  if (info.lastModified && info.lastModified.getTime() > (lastModified ? lastModified.getTime() : 0)) {
84
- lastModified = info.lastModified;
84
+ lastModified = info.lastModified
85
85
  }
86
86
 
87
87
  if (info.next) {
88
- return nextPage(info.next);
88
+ return nextPage(info.next)
89
89
  }
90
- cb(null, ret, lastModified);
91
- }, next);
92
- })();
93
- };
90
+ cb(null, ret, lastModified)
91
+ }, next)
92
+ })()
93
+ }
94
94
 
95
95
  const getRemoteNamespace = (opt, lng, ns, cb) => {
96
- if (opt.unpublished) return pullNamespace(opt, lng, ns, cb);
96
+ if (opt.unpublished) return pullNamespace(opt, lng, ns, cb)
97
97
 
98
- request(opt.apiPath + (opt.isPrivate ? '/private' : '') + '/' + opt.projectId + '/' + opt.version + '/' + lng + '/' + ns + '?ts=' + Date.now(), {
98
+ request(opt.apiPath + (opt.isPrivate ? '/private' : '') + '/' + opt.projectId + '/' + opt.version + '/' + lng + '/' + ns + '?ts=' + Date.now() + (opt.cdnType === 'standard' ? '&cache=no' : ''), {
99
99
  method: 'get',
100
- headers: opt.isPrivate ? {
101
- 'Authorization': opt.apiKey
102
- } : undefined
100
+ headers: opt.isPrivate
101
+ ? {
102
+ Authorization: opt.apiKey
103
+ }
104
+ : undefined
103
105
  }, (err, res, obj) => {
104
- if (err) return cb(err);
106
+ if (err) return cb(err)
107
+ const ignore404 = res.status === 404 && opt.cdnType === 'standard'
108
+ if (ignore404) return cb(null, {}, undefined)
105
109
  if (res.status >= 300) {
106
110
  if (obj && (obj.errorMessage || obj.message)) {
107
111
  if (res.statusText && res.status) {
108
- return cb(new Error(res.statusText + ' (' + res.status + ') | ' + (obj.errorMessage || obj.message)));
112
+ return cb(new Error(res.statusText + ' (' + res.status + ') | ' + (obj.errorMessage || obj.message)))
109
113
  }
110
- return cb(new Error((obj.errorMessage || obj.message)));
114
+ return cb(new Error((obj.errorMessage || obj.message)))
111
115
  }
112
- return cb(new Error(res.statusText + ' (' + res.status + ')'));
116
+ return cb(new Error(res.statusText + ' (' + res.status + ')'))
113
117
  }
114
- cb(null, sortFlatResources(flatten(obj)), res.headers.get('last-modified') ? new Date(res.headers.get('last-modified')) : undefined);
115
- });
116
- };
118
+ cb(null, sortFlatResources(flatten(obj)), res.headers.get('last-modified') ? new Date(res.headers.get('last-modified')) : undefined)
119
+ })
120
+ }
117
121
 
118
- module.exports = getRemoteNamespace;
122
+ module.exports = getRemoteNamespace
package/index.js CHANGED
@@ -6,4 +6,4 @@ module.exports = {
6
6
  sync: require('./sync'),
7
7
  publishVersion: require('./publishVersion'),
8
8
  copyVersion: require('./copyVersion')
9
- };
9
+ }
package/isValidUuid.js CHANGED
@@ -1,2 +1,2 @@
1
- const uuidRegex = /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i;
2
- module.exports = (id) => uuidRegex.test(id);
1
+ const uuidRegex = /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i
2
+ module.exports = (id) => uuidRegex.test(id)
package/mergeBranch.js CHANGED
@@ -1,102 +1,102 @@
1
- const colors = require('colors');
2
- const request = require('./request');
3
- const getBranches = require('./getBranches');
4
- const isValidUuid = require('./isValidUuid');
5
- const getJob = require('./getJob');
1
+ const colors = require('colors')
2
+ const request = require('./request')
3
+ const getBranches = require('./getBranches')
4
+ const isValidUuid = require('./isValidUuid')
5
+ const getJob = require('./getJob')
6
6
 
7
7
  const mergeBranch = (opt, cb) => {
8
- const queryParams = new URLSearchParams();
8
+ const queryParams = new URLSearchParams()
9
9
  if (opt.delete) {
10
- queryParams.append('delete', 'true');
10
+ queryParams.append('delete', 'true')
11
11
  }
12
- const queryString = queryParams.size > 0 ? '?' + queryParams.toString() : '';
12
+ const queryString = queryParams.size > 0 ? '?' + queryParams.toString() : ''
13
13
  request(opt.apiPath + '/branch/merge/' + opt.branch + queryString, {
14
14
  method: 'post',
15
15
  headers: {
16
- 'Authorization': opt.apiKey
16
+ Authorization: opt.apiKey
17
17
  }
18
18
  }, (err, res, obj) => {
19
19
  if (err || (obj && (obj.errorMessage || obj.message))) {
20
- if (!cb) console.log(colors.red('merging branch failed...'));
20
+ if (!cb) console.log(colors.red('merging branch failed...'))
21
21
 
22
22
  if (err) {
23
- if (!cb) { console.error(colors.red(err.message)); process.exit(1); }
24
- if (cb) cb(err);
25
- return;
23
+ if (!cb) { console.error(colors.red(err.message)); process.exit(1) }
24
+ if (cb) cb(err)
25
+ return
26
26
  }
27
27
  if (obj && (obj.errorMessage || obj.message)) {
28
- if (!cb) { console.error(colors.red((obj.errorMessage || obj.message))); process.exit(1); }
29
- if (cb) cb(new Error((obj.errorMessage || obj.message)));
30
- return;
28
+ if (!cb) { console.error(colors.red((obj.errorMessage || obj.message))); process.exit(1) }
29
+ if (cb) cb(new Error((obj.errorMessage || obj.message)))
30
+ return
31
31
  }
32
32
  }
33
33
  if (res.status === 404) {
34
- if (!cb) { console.error(colors.yellow(res.statusText + ' (' + res.status + ')')); process.exit(1); }
35
- if (cb) cb(null, null);
36
- return;
34
+ if (!cb) { console.error(colors.yellow(res.statusText + ' (' + res.status + ')')); process.exit(1) }
35
+ if (cb) cb(null, null)
36
+ return
37
37
  }
38
38
  if (res.status >= 300) {
39
- if (!cb) { console.error(colors.red(res.statusText + ' (' + res.status + ')')); process.exit(1); }
40
- if (cb) cb(new Error(res.statusText + ' (' + res.status + ')'));
41
- return;
39
+ if (!cb) { console.error(colors.red(res.statusText + ' (' + res.status + ')')); process.exit(1) }
40
+ if (cb) cb(new Error(res.statusText + ' (' + res.status + ')'))
41
+ return
42
42
  }
43
43
 
44
44
  if (!obj || !obj.jobId) {
45
- if (!cb) { console.error(colors.red('No jobId! Something went wrong!')); process.exit(1); }
46
- if (cb) cb(new Error('No jobId! Something went wrong!'));
47
- return;
45
+ if (!cb) { console.error(colors.red('No jobId! Something went wrong!')); process.exit(1) }
46
+ if (cb) cb(new Error('No jobId! Something went wrong!'))
47
+ return
48
48
  }
49
49
 
50
- (function waitForJob() {
50
+ (function waitForJob () {
51
51
  getJob({
52
52
  apiPath: opt.apiPath,
53
53
  apiKey: opt.apiKey,
54
54
  projectId: opt.branch
55
55
  }, obj.jobId, (err, job) => {
56
56
  if (err) {
57
- if (!cb) { console.error(colors.red(err.message)); process.exit(1); }
58
- if (cb) cb(err);
59
- return;
57
+ if (!cb) { console.error(colors.red(err.message)); process.exit(1) }
58
+ if (cb) cb(err)
59
+ return
60
60
  }
61
61
 
62
62
  if (job && !job.timeouted) {
63
- setTimeout(waitForJob, 2000);
64
- return;
63
+ setTimeout(waitForJob, 2000)
64
+ return
65
65
  }
66
66
 
67
67
  if (job && job.timeouted) {
68
- if (!cb) { console.error(colors.red('Job timeouted!')); process.exit(1); }
69
- if (cb) cb(new Error('Job timeouted!'));
70
- return;
68
+ if (!cb) { console.error(colors.red('Job timeouted!')); process.exit(1) }
69
+ if (cb) cb(new Error('Job timeouted!'))
70
+ return
71
71
  }
72
72
 
73
- if (!cb) console.log(colors.green('merging branch successful'));
74
- if (cb) cb(null);
75
- });
76
- })();
77
- });
78
- };
73
+ if (!cb) console.log(colors.green('merging branch successful'))
74
+ if (cb) cb(null)
75
+ })
76
+ })()
77
+ })
78
+ }
79
79
 
80
80
  const handleError = (err, cb) => {
81
81
  if (!cb && err) {
82
- console.error(colors.red(err.stack));
83
- process.exit(1);
82
+ console.error(colors.red(err.stack))
83
+ process.exit(1)
84
84
  }
85
- if (cb) cb(err);
86
- };
85
+ if (cb) cb(err)
86
+ }
87
87
 
88
88
  module.exports = (opt, cb) => {
89
89
  getBranches(opt, (err, branches) => {
90
- if (err) return handleError(err, cb);
90
+ if (err) return handleError(err, cb)
91
91
 
92
- let b;
93
- if (isValidUuid(opt.branch)) b = branches.find((br) => br.id === opt.branch);
94
- if (!b) b = branches.find((br) => br.name === opt.branch);
92
+ let b
93
+ if (isValidUuid(opt.branch)) b = branches.find((br) => br.id === opt.branch)
94
+ if (!b) b = branches.find((br) => br.name === opt.branch)
95
95
  if (!b) {
96
- return handleError(new Error(`Branch ${opt.branch} not found!`), cb);
96
+ return handleError(new Error(`Branch ${opt.branch} not found!`), cb)
97
97
  }
98
- opt.branch = b.id;
98
+ opt.branch = b.id
99
99
 
100
- mergeBranch(opt, cb);
101
- });
102
- };
100
+ mergeBranch(opt, cb)
101
+ })
102
+ }