locize-cli 10.1.0 → 10.1.1

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,10 @@ 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
+ ## [10.1.1](https://github.com/locize/locize-cli/compare/v10.1.0...v10.1.1) - 2025-07-12
9
+
10
+ - create-branch: nicer feedback, if branch already exists
11
+
8
12
  ## [10.1.0](https://github.com/locize/locize-cli/compare/v10.0.3...v10.1.0) - 2025-07-10
9
13
 
10
14
  - introduce branching features
package/createBranch.js CHANGED
@@ -1,40 +1,60 @@
1
1
  const colors = require('colors');
2
2
  const request = require('./request');
3
+ const getBranches = require('./getBranches');
4
+
5
+ const handleError = (err, cb) => {
6
+ if (!cb && err) {
7
+ console.error(colors.red(err.stack));
8
+ process.exit(1);
9
+ }
10
+ if (cb) cb(err);
11
+ };
3
12
 
4
13
  const createBranch = (opt, cb) => {
5
- request(opt.apiPath + '/branch/create/' + opt.projectId + '/' + opt.version, {
6
- method: 'post',
7
- headers: {
8
- 'Authorization': opt.apiKey
9
- },
10
- body: { name: opt.branch }
11
- }, (err, res, obj) => {
12
- if (err || (obj && (obj.errorMessage || obj.message))) {
13
- if (!cb) console.log(colors.red('creating branch failed...'));
14
+ getBranches(opt, (err, branches) => {
15
+ if (err) return handleError(err, cb);
16
+
17
+ const b = branches.find((br) => br.name === opt.branch);
18
+ if (b) {
19
+ if (!cb) console.log(colors.green('creating branch "' + b.name + '" (' + b.id + ') not necessary, because already existing'));
20
+ if (cb) cb(null, b);
21
+ return;
22
+ }
23
+
24
+ request(opt.apiPath + '/branch/create/' + opt.projectId + '/' + opt.version, {
25
+ method: 'post',
26
+ headers: {
27
+ 'Authorization': opt.apiKey
28
+ },
29
+ body: { name: opt.branch }
30
+ }, (err, res, obj) => {
31
+ if (err || (obj && (obj.errorMessage || obj.message))) {
32
+ if (!cb) console.log(colors.red('creating branch failed...'));
14
33
 
15
- if (err) {
16
- if (!cb) { console.error(colors.red(err.message)); process.exit(1); }
17
- if (cb) cb(err);
34
+ if (err) {
35
+ if (!cb) { console.error(colors.red(err.message)); process.exit(1); }
36
+ if (cb) cb(err);
37
+ return;
38
+ }
39
+ if (obj && (obj.errorMessage || obj.message)) {
40
+ if (!cb) { console.error(colors.red((obj.errorMessage || obj.message))); process.exit(1); }
41
+ if (cb) cb(new Error((obj.errorMessage || obj.message)));
42
+ return;
43
+ }
44
+ }
45
+ if (res.status === 404) {
46
+ if (!cb) { console.error(colors.yellow(res.statusText + ' (' + res.status + ')')); process.exit(1); }
47
+ if (cb) cb(null, null);
18
48
  return;
19
49
  }
20
- if (obj && (obj.errorMessage || obj.message)) {
21
- if (!cb) { console.error(colors.red((obj.errorMessage || obj.message))); process.exit(1); }
22
- if (cb) cb(new Error((obj.errorMessage || obj.message)));
50
+ if (res.status >= 300) {
51
+ if (!cb) { console.error(colors.red(res.statusText + ' (' + res.status + ')')); process.exit(1); }
52
+ if (cb) cb(new Error(res.statusText + ' (' + res.status + ')'));
23
53
  return;
24
54
  }
25
- }
26
- if (res.status === 404) {
27
- if (!cb) { console.error(colors.yellow(res.statusText + ' (' + res.status + ')')); process.exit(1); }
28
- if (cb) cb(null, null);
29
- return;
30
- }
31
- if (res.status >= 300) {
32
- if (!cb) { console.error(colors.red(res.statusText + ' (' + res.status + ')')); process.exit(1); }
33
- if (cb) cb(new Error(res.statusText + ' (' + res.status + ')'));
34
- return;
35
- }
36
- if (!cb) console.log(colors.green('creating branch "' + obj.name + '" (' + obj.id + ') successful'));
37
- if (cb) cb(null, obj);
55
+ if (!cb) console.log(colors.green('creating branch "' + obj.name + '" (' + obj.id + ') successful'));
56
+ if (cb) cb(null, obj);
57
+ });
38
58
  });
39
59
  };
40
60
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "locize-cli",
3
- "version": "10.1.0",
3
+ "version": "10.1.1",
4
4
  "description": "locize cli to import locales",
5
5
  "main": "index.js",
6
6
  "bin": {