locize-cli 7.12.11 → 7.13.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 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
+ ## [7.13.0](https://github.com/locize/locize-cli/compare/v7.12.12...v7.13.0) - 2022-12-08
9
+
10
+ - migrate command will use missing route if replace param is false or not passed and will also automaticaly create languages (make sure to use an api key with admin permissions)
11
+
12
+ ## [7.12.12](https://github.com/locize/locize-cli/compare/v7.12.11...v7.12.12) - 2022-11-24
13
+
14
+ - update android-string-resource dependency to fix wrong plural unescaping
15
+
8
16
  ## [7.12.11](https://github.com/locize/locize-cli/compare/v7.12.10...v7.12.11) - 2022-11-24
9
17
 
10
18
  - update android-string-resource dependency to fix [#80](https://github.com/locize/locize-cli/issues/80)
package/bin/locize CHANGED
@@ -79,6 +79,7 @@ program
79
79
  apiKey: apiKey,
80
80
  projectId: projectId,
81
81
  addPath: addPath,
82
+ apiPath: url.parse(addPath).protocol + '//' + url.parse(addPath).host,
82
83
  path: options.path,
83
84
  language: options.language || config.language || config.lng || process.env.LOCIZE_LANGUAGE || process.env.LOCIZE_LANG || process.env.LOCIZE_LNG,
84
85
  version: version,
package/migrate.js CHANGED
@@ -4,6 +4,7 @@ const flatten = require('flat');
4
4
  const async = require('async');
5
5
  const colors = require('colors');
6
6
  const request = require('./request');
7
+ const getRemoteLanguages = require('./getRemoteLanguages');
7
8
 
8
9
  const getDirectories = (srcpath) => {
9
10
  return fs.readdirSync(srcpath).filter(function(file) {
@@ -66,6 +67,8 @@ const transfer = (opt, ns, cb) => {
66
67
 
67
68
  console.log(colors.yellow(`transfering ${opt.version}/${ns.language}/${ns.namespace}...`));
68
69
 
70
+ if (!opt.replace) url = url.replace('/update/', '/missing/');
71
+
69
72
  request(url + `?replace=${!!opt.replace}`, {
70
73
  method: 'post',
71
74
  body: ns.value,
@@ -74,6 +77,11 @@ const transfer = (opt, ns, cb) => {
74
77
  }
75
78
  }, (err, res, obj) => {
76
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;
84
+ }
77
85
  console.log(colors.red(`transfer failed for ${opt.version}/${ns.language}/${ns.namespace}...`));
78
86
 
79
87
  if (err) return cb(err);
@@ -86,14 +94,56 @@ const transfer = (opt, ns, cb) => {
86
94
  };
87
95
 
88
96
  const upload = (opt, nss, cb) => {
97
+ if (!opt.referenceLanguage) {
98
+ async.eachLimit(
99
+ nss,
100
+ require('os').cpus().length,
101
+ (ns, done) => transfer(opt, ns, done),
102
+ cb
103
+ );
104
+ return;
105
+ }
106
+
107
+ const nssRefLng = nss.filter((n) => n.language === opt.referenceLanguage);
108
+ const nssNonRefLng = nss.filter((n) => n.language !== opt.referenceLanguage);
109
+
89
110
  async.eachLimit(
90
- nss,
111
+ nssRefLng,
91
112
  require('os').cpus().length,
92
113
  (ns, done) => transfer(opt, ns, done),
93
- cb
114
+ (err) => {
115
+ if (err) return cb(err);
116
+ async.eachLimit(
117
+ nssNonRefLng,
118
+ require('os').cpus().length,
119
+ (ns, done) => transfer(opt, ns, done),
120
+ cb
121
+ );
122
+ }
94
123
  );
95
124
  };
96
125
 
126
+ const addLanguage = (opt, l, cb) => {
127
+ var url = opt.apiPath + '/language/' + opt.projectId + '/' + l;
128
+
129
+ request(url, {
130
+ method: 'post',
131
+ headers: {
132
+ 'Authorization': opt.apiKey
133
+ }
134
+ }, (err, res, obj) => {
135
+ if (err || (obj && (obj.errorMessage || obj.message))) {
136
+ console.log(colors.red(`failed to add language ${l}...`));
137
+
138
+ if (err) return cb(err);
139
+ if (obj && (obj.errorMessage || obj.message)) return cb(new Error((obj.errorMessage || obj.message)));
140
+ }
141
+ if (res.status >= 300 && res.status !== 412) return cb(new Error(res.statusText + ' (' + res.status + ')'));
142
+ console.log(colors.green(`added language ${l}...`));
143
+ cb(null);
144
+ });
145
+ };
146
+
97
147
  const migrate = (opt, cb) => {
98
148
  if (opt.format !== 'json') {
99
149
  var err = new Error(`Format ${opt.format} is not accepted!`);
@@ -102,6 +152,8 @@ const migrate = (opt, cb) => {
102
152
  return;
103
153
  }
104
154
 
155
+ opt.apiPath = opt.apiPath || 'https://api.locize.app';
156
+
105
157
  if (opt.language) {
106
158
  const files = getFiles(opt.path);
107
159
 
@@ -142,17 +194,57 @@ const migrate = (opt, cb) => {
142
194
  if (cb) cb(err);
143
195
  return;
144
196
  }
145
- upload(opt, nss, (err) => {
197
+
198
+ getRemoteLanguages(opt, (err, remoteLanguages) => {
146
199
  if (err) {
147
- if (!cb) {
148
- console.error(colors.red(err.stack));
149
- process.exit(1);
150
- }
200
+ if (!cb) { console.error(colors.red(err.stack)); process.exit(1); }
151
201
  if (cb) cb(err);
152
202
  return;
153
203
  }
154
- if (!cb) console.log(colors.green('FINISHED'));
155
- if (cb) cb(null);
204
+
205
+ const localLanguages = [];
206
+ nss.forEach((n) => {
207
+ if (localLanguages.indexOf(n.language) < 0) localLanguages.push(n.language);
208
+ });
209
+
210
+ const notExistingLanguages = localLanguages.filter((l) => remoteLanguages.indexOf(l) < 0);
211
+
212
+ if (notExistingLanguages.length === 0) {
213
+ upload(opt, nss, (err) => {
214
+ if (err) {
215
+ if (!cb) {
216
+ console.error(colors.red(err.stack));
217
+ process.exit(1);
218
+ }
219
+ if (cb) cb(err);
220
+ return;
221
+ }
222
+ if (!cb) console.log(colors.green('FINISHED'));
223
+ if (cb) cb(null);
224
+ });
225
+ return;
226
+ }
227
+
228
+ async.eachLimit(
229
+ notExistingLanguages,
230
+ require('os').cpus().length,
231
+ (l, done) => addLanguage(opt, l, done),
232
+ (err) => {
233
+ upload(opt, nss, (err) => {
234
+ if (err) {
235
+ if (!cb) {
236
+ console.error(colors.red(err.stack));
237
+ process.exit(1);
238
+ }
239
+ if (cb) cb(err);
240
+ return;
241
+ }
242
+ if (!cb) console.log(colors.green('FINISHED'));
243
+ if (cb) cb(null);
244
+ });
245
+ }
246
+ );
247
+ return;
156
248
  });
157
249
  });
158
250
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "locize-cli",
3
- "version": "7.12.11",
3
+ "version": "7.13.0",
4
4
  "description": "locize cli to import locales",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -8,7 +8,7 @@
8
8
  },
9
9
  "dependencies": {
10
10
  "@js.properties/properties": "0.5.4",
11
- "android-string-resource": "2.3.7",
11
+ "android-string-resource": "2.3.8",
12
12
  "async": "3.2.4",
13
13
  "cacheable-lookup": "6.1.0",
14
14
  "colors": "1.4.0",
@@ -33,7 +33,7 @@
33
33
  "xlsx": "0.18.5"
34
34
  },
35
35
  "devDependencies": {
36
- "eslint": "8.28.0",
36
+ "eslint": "8.29.0",
37
37
  "gh-release": "6.0.4",
38
38
  "pkg": "5.8.0"
39
39
  },