locize-cli 10.2.1 → 10.3.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
@@ -6,6 +6,11 @@ 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
8
 
9
+ ## [10.3.0](https://github.com/locize/locize-cli/compare/v10.2.1...v10.3.0) - 2025-08-11
10
+
11
+ - introduce delete-branch command
12
+ - sync/download: try to check if version exists also on dry-run
13
+
9
14
  ## [10.2.1](https://github.com/locize/locize-cli/compare/v10.2.0...v10.2.1) - 2025-08-07
10
15
 
11
16
  - download/sync: check if branch name is empty string
package/README.md CHANGED
@@ -363,6 +363,12 @@ locize download --branch featureXYZ --api-key my-api-key-d9de-4f55-9855-a9ef0ed4
363
363
  locize merge-branch featureXYZ --api-key my-api-key-d9de-4f55-9855-a9ef0ed44672 --project-id my-project-id-93e1-442a-ab35-24331fa294ba --delete true
364
364
  ```
365
365
 
366
+ ### Delete an unmerged branch
367
+
368
+ ```sh
369
+ locize delete-branch featureXYZ --api-key my-api-key-d9de-4f55-9855-a9ef0ed44672 --project-id my-project-id-93e1-442a-ab35-24331fa294ba
370
+ ```
371
+
366
372
 
367
373
  ## Other information
368
374
 
package/bin/locize CHANGED
@@ -28,6 +28,7 @@ const deleteNamespace = require('../deleteNamespace');
28
28
  const formatFn = require('../format');
29
29
  const createBranch = require('../createBranch');
30
30
  const mergeBranch = require('../mergeBranch');
31
+ const deleteBranch = require('../deleteBranch');
31
32
 
32
33
  var config = {};
33
34
  try {
@@ -839,9 +840,9 @@ program
839
840
  .on('--help', () => {
840
841
  console.log(' Examples:');
841
842
  console.log();
842
- console.log(' $ locize creaete-branch featureX');
843
- console.log(' $ locize creaete-branch featureX --ver production');
844
- console.log(' $ locize creaete-branch featureX --api-key <apiKey> --project-id <projectId> --ver <version>');
843
+ console.log(' $ locize create-branch featureX');
844
+ console.log(' $ locize create-branch featureX --ver production');
845
+ console.log(' $ locize create-branch featureX --api-key <apiKey> --project-id <projectId> --ver <version>');
845
846
  console.log();
846
847
  });
847
848
 
@@ -892,6 +893,49 @@ program
892
893
  console.log();
893
894
  });
894
895
 
896
+ program
897
+ .command('delete-branch <branch>')
898
+ .alias('cb')
899
+ .description('delete branch')
900
+ .option('-k, --api-key <apiKey>', 'The api-key that should be used')
901
+ .option('-i, --project-id <projectId>', 'The project-id that should be used')
902
+ .option('-C, --config-path <configPath>', `Specify the path to the optional locize config file (default: ${configInWorkingDirectory} or ${configInHome})`)
903
+ .action((branch, options) => {
904
+ try {
905
+ config = ini.parse(fs.readFileSync(options.configPath, 'utf-8')) || config;
906
+ } catch (e) {}
907
+
908
+ const apiKey = options.apiKey || config.apiKey || process.env.LOCIZE_API_KEY || process.env.LOCIZE_KEY;
909
+ if (!apiKey) {
910
+ console.error(' error: missing required argument `apiKey`');
911
+ process.exit(1);
912
+ return;
913
+ }
914
+
915
+ const projectId = options.projectId || config.projectId || process.env.LOCIZE_PROJECTID || process.env.LOCIZE_PID;
916
+ if (!projectId) {
917
+ console.error(' error: missing required argument `projectId`');
918
+ process.exit(1);
919
+ return;
920
+ }
921
+
922
+ const getPath = options.getPath || config.getPath || options.addPath || config.addPath || getPathUrl;
923
+
924
+ deleteBranch({
925
+ apiKey: apiKey,
926
+ projectId: projectId,
927
+ apiPath: url.parse(getPath).protocol + '//' + url.parse(getPath).host,
928
+ branch: branch
929
+ });
930
+ })
931
+ .on('--help', () => {
932
+ console.log(' Examples:');
933
+ console.log();
934
+ console.log(' $ locize delete-branch featureX');
935
+ console.log(' $ locize delete-branch featureX --api-key <apiKey> --project-id <projectId>');
936
+ console.log();
937
+ });
938
+
895
939
  program.parse(process.argv);
896
940
 
897
941
  if (!process.argv.slice(2).length) {
@@ -0,0 +1,97 @@
1
+ const colors = require('colors');
2
+ const request = require('./request');
3
+ const getBranches = require('./getBranches');
4
+ const getJob = require('./getJob');
5
+ const isValidUuid = require('./isValidUuid');
6
+
7
+ const handleError = (err, cb) => {
8
+ if (!cb && err) {
9
+ console.error(colors.red(err.stack));
10
+ process.exit(1);
11
+ }
12
+ if (cb) cb(err);
13
+ };
14
+
15
+ const deleteBranch = (opt, cb) => {
16
+ request(opt.apiPath + '/branch/' + opt.branch, {
17
+ method: 'delete',
18
+ headers: {
19
+ 'Authorization': opt.apiKey
20
+ }
21
+ }, (err, res, obj) => {
22
+ if (err || (obj && (obj.errorMessage || obj.message))) {
23
+ if (!cb) console.log(colors.red('deleting branch failed...'));
24
+
25
+ if (err) {
26
+ if (!cb) { console.error(colors.red(err.message)); process.exit(1); }
27
+ if (cb) cb(err);
28
+ return;
29
+ }
30
+ if (obj && (obj.errorMessage || obj.message)) {
31
+ if (!cb) { console.error(colors.red((obj.errorMessage || obj.message))); process.exit(1); }
32
+ if (cb) cb(new Error((obj.errorMessage || obj.message)));
33
+ return;
34
+ }
35
+ }
36
+ if (res.status === 404) {
37
+ if (!cb) { console.error(colors.yellow(res.statusText + ' (' + res.status + ')')); process.exit(1); }
38
+ if (cb) cb(null, null);
39
+ return;
40
+ }
41
+ if (res.status >= 300) {
42
+ if (!cb) { console.error(colors.red(res.statusText + ' (' + res.status + ')')); process.exit(1); }
43
+ if (cb) cb(new Error(res.statusText + ' (' + res.status + ')'));
44
+ return;
45
+ }
46
+
47
+ if (!obj || !obj.jobId) {
48
+ if (!cb) { console.error(colors.red('No jobId! Something went wrong!')); process.exit(1); }
49
+ if (cb) cb(new Error('No jobId! Something went wrong!'));
50
+ return;
51
+ }
52
+
53
+ (function waitForJob() {
54
+ getJob({
55
+ apiPath: opt.apiPath,
56
+ apiKey: opt.apiKey,
57
+ projectId: opt.branch
58
+ }, obj.jobId, (err, job) => {
59
+ if (err) {
60
+ if (!cb) { console.error(colors.red(err.message)); process.exit(1); }
61
+ if (cb) cb(err);
62
+ return;
63
+ }
64
+
65
+ if (job && !job.timeouted) {
66
+ setTimeout(waitForJob, 2000);
67
+ return;
68
+ }
69
+
70
+ if (job && job.timeouted) {
71
+ if (!cb) { console.error(colors.red('Job timeouted!')); process.exit(1); }
72
+ if (cb) cb(new Error('Job timeouted!'));
73
+ return;
74
+ }
75
+
76
+ if (!cb) console.log(colors.green(`deleting branch "${opt.branch}" succesfully requested`));
77
+ if (cb) cb(null);
78
+ });
79
+ })();
80
+ });
81
+ };
82
+
83
+ module.exports = (opt, cb) => {
84
+ getBranches(opt, (err, branches) => {
85
+ if (err) return handleError(err, cb);
86
+
87
+ let b;
88
+ if (isValidUuid(opt.branch)) b = branches.find((br) => br.id === opt.branch);
89
+ if (!b) b = branches.find((br) => br.name === opt.branch);
90
+ if (!b) {
91
+ return handleError(new Error(`Branch ${opt.branch} not found!`), cb);
92
+ }
93
+ opt.branch = b.id;
94
+
95
+ deleteBranch(opt, cb);
96
+ });
97
+ };
package/download.js CHANGED
@@ -417,15 +417,27 @@ const continueToDownload = (opt, cb) => {
417
417
  return;
418
418
  }
419
419
 
420
- obj = filterDownloads(opt, obj || []);
421
- handleDownload(opt, url, err, res, obj, cb);
420
+ if (obj.length > 0) {
421
+ obj = filterDownloads(opt, obj || []);
422
+ return handleDownload(opt, url, err, res, obj, cb);
423
+ }
424
+
425
+ getProjectStats(opt, (err, res) => {
426
+ if (err) return handleError(err, cb);
427
+ if (!res) return handleError(new Error('Nothing found!'), cb);
428
+ if (!res[opt.version]) return handleError(new Error(`Version "${opt.version}" not found!`), cb);
429
+
430
+ obj = filterDownloads(opt, obj || []);
431
+ return handleDownload(opt, url, err, res, obj, cb);
432
+ });
422
433
  });
423
434
  return;
424
435
  }
425
436
 
426
437
  getProjectStats(opt, (err, res) => {
427
438
  if (err) return handleError(err, cb);
428
- if (!res || !res[opt.version]) return handleError(new Error('Nothing found!'), cb);
439
+ if (!res) return handleError(new Error('Nothing found!'), cb);
440
+ if (!res[opt.version]) return handleError(new Error(`Version "${opt.version}" not found!`), cb);
429
441
 
430
442
  const toDownload = [];
431
443
  const lngsToCheck = opt.language ? [opt.language] : Object.keys(res[opt.version]);
package/mergeBranch.js CHANGED
@@ -48,7 +48,11 @@ const mergeBranch = (opt, cb) => {
48
48
  }
49
49
 
50
50
  (function waitForJob() {
51
- getJob(opt, obj.jobId, (err, job) => {
51
+ getJob({
52
+ apiPath: opt.apiPath,
53
+ apiKey: opt.apiKey,
54
+ projectId: opt.branch
55
+ }, obj.jobId, (err, job) => {
52
56
  if (err) {
53
57
  if (!cb) { console.error(colors.red(err.message)); process.exit(1); }
54
58
  if (cb) cb(err);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "locize-cli",
3
- "version": "10.2.1",
3
+ "version": "10.3.0",
4
4
  "description": "locize cli to import locales",
5
5
  "main": "index.js",
6
6
  "bin": {
package/sync.js CHANGED
@@ -53,13 +53,24 @@ const getDownloads = (opt, cb) => {
53
53
  }
54
54
  return cb(new Error(res.statusText + ' (' + res.status + ')'));
55
55
  }
56
- if (opt.skipEmpty) obj = obj.filter((d) => d.size > 2);
57
- cb(null, obj);
56
+ if (obj.length > 0) {
57
+ if (opt.skipEmpty) obj = obj.filter((d) => d.size > 2);
58
+ return cb(null, obj);
59
+ }
60
+
61
+ getProjectStats(opt, (err, res) => {
62
+ if (err) return handleError(err, cb);
63
+ if (!res) return handleError(new Error('Nothing found!'), cb);
64
+ if (!res[opt.version]) return handleError(new Error(`Version "${opt.version}" not found!`), cb);
65
+
66
+ return cb(null, obj);
67
+ });
58
68
  });
59
69
  } else {
60
70
  getProjectStats(opt, (err, res) => {
61
71
  if (err) return handleError(err, cb);
62
- if (!res || !res[opt.version]) return handleError(new Error('Nothing found!'), cb);
72
+ if (!res) return handleError(new Error('Nothing found!'), cb);
73
+ if (!res[opt.version]) return handleError(new Error(`Version "${opt.version}" not found!`), cb);
63
74
 
64
75
  const toDownload = [];
65
76
  const lngsToCheck = opt.language ? [opt.language] : (opt.languages && opt.languages.length > 0) ? opt.languages : Object.keys(res[opt.version]);