@tolgee/cli 2.12.1 → 2.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.
@@ -46,7 +46,7 @@ function askForConfirmation(keys, operation) {
46
46
  }
47
47
  const syncHandler = (config) => function () {
48
48
  return __awaiter(this, void 0, void 0, function* () {
49
- var _a, _b, _c;
49
+ var _a, _b, _c, _d, _e, _f;
50
50
  const opts = this.optsWithGlobals();
51
51
  const rawKeys = yield loading('Analyzing code...', extractKeysOfFiles(opts));
52
52
  const warnCount = dumpWarnings(rawKeys);
@@ -55,11 +55,24 @@ const syncHandler = (config) => function () {
55
55
  process.exit(1);
56
56
  }
57
57
  const localKeys = filterExtractionResult(rawKeys);
58
+ if ((_a = opts.namespaces) === null || _a === void 0 ? void 0 : _a.length) {
59
+ for (const namespace of Object.keys(localKeys)) {
60
+ if (!((_b = opts.namespaces) === null || _b === void 0 ? void 0 : _b.includes(namespace))) {
61
+ localKeys[namespace].clear();
62
+ }
63
+ }
64
+ }
58
65
  const allKeysLoadable = yield opts.client.GET('/v2/projects/{projectId}/all-keys', {
59
66
  params: { path: { projectId: opts.client.getProjectId() } },
60
67
  });
61
68
  handleLoadableError(allKeysLoadable);
62
- const remoteKeys = (_c = (_b = (_a = allKeysLoadable.data) === null || _a === void 0 ? void 0 : _a._embedded) === null || _b === void 0 ? void 0 : _b.keys) !== null && _c !== void 0 ? _c : [];
69
+ let remoteKeys = (_e = (_d = (_c = allKeysLoadable.data) === null || _c === void 0 ? void 0 : _c._embedded) === null || _d === void 0 ? void 0 : _d.keys) !== null && _e !== void 0 ? _e : [];
70
+ if ((_f = opts.namespaces) === null || _f === void 0 ? void 0 : _f.length) {
71
+ remoteKeys = remoteKeys.filter((key) => {
72
+ var _a, _b;
73
+ return (_a = opts.namespaces) === null || _a === void 0 ? void 0 : _a.includes((_b = key.namespace) !== null && _b !== void 0 ? _b : '');
74
+ });
75
+ }
63
76
  const diff = compareKeys(localKeys, remoteKeys);
64
77
  if (!diff.added.length && !diff.removed.length) {
65
78
  console.log(ansi.green('Your code project is in sync with the associated Tolgee project!'));
@@ -127,14 +140,15 @@ const syncHandler = (config) => function () {
127
140
  });
128
141
  };
129
142
  export default (config) => {
130
- var _a, _b, _c, _d, _e, _f;
143
+ var _a, _b, _c, _d, _e, _f, _g;
131
144
  return new Command()
132
145
  .name('sync')
133
146
  .description('Synchronizes the keys in your code project and in the Tolgee project, by creating missing keys and optionally deleting unused ones. For a dry-run, use `tolgee compare`.')
134
147
  .addOption(new Option('-B, --backup <path>', 'Store translation files backup (only translation files, not states, comments, tags, etc.). If something goes wrong, the backup can be used to restore the project to its previous state.').default((_b = (_a = config.sync) === null || _a === void 0 ? void 0 : _a.backup) !== null && _b !== void 0 ? _b : false))
135
148
  .addOption(new Option('--continue-on-warning', 'Set this flag to continue the sync if warnings are detected during string extraction. By default, as warnings may indicate an invalid extraction, the CLI will abort the sync.').default((_d = (_c = config.sync) === null || _c === void 0 ? void 0 : _c.continueOnWarning) !== null && _d !== void 0 ? _d : false))
149
+ .addOption(new Option('-n, --namespaces <namespaces...>', 'Specifies which namespaces should be synchronized.').default((_e = config.sync) === null || _e === void 0 ? void 0 : _e.namespaces))
136
150
  .addOption(new Option('-Y, --yes', 'Skip prompts and automatically say yes to them. You will not be asked for confirmation before creating/deleting keys.').default(false))
137
- .addOption(new Option('--remove-unused', 'Delete unused keys from the Tolgee project.').default((_f = (_e = config.sync) === null || _e === void 0 ? void 0 : _e.removeUnused) !== null && _f !== void 0 ? _f : false))
151
+ .addOption(new Option('--remove-unused', 'Delete unused keys from the Tolgee project (within selected namespaces if specified).').default((_g = (_f = config.sync) === null || _f === void 0 ? void 0 : _f.removeUnused) !== null && _g !== void 0 ? _g : false))
138
152
  .option('--tag-new-keys <tags...>', 'Specify tags that will be added to newly created keys.')
139
153
  .action(syncHandler(config));
140
154
  };
@@ -1,4 +1,3 @@
1
- import { NullNamespace } from '../../extractor/runner.js';
2
1
  import ansi from 'ansi-colors';
3
2
  /**
4
3
  * Prints information about a key, with coloring and formatting.
@@ -30,18 +29,18 @@ export function compareKeys(local, remote) {
30
29
  const result = { added: [], removed: [] };
31
30
  // Deleted keys
32
31
  for (const remoteKey of remote) {
33
- const namespace = remoteKey.namespace || NullNamespace;
32
+ const namespace = remoteKey.namespace || '';
34
33
  const keyExists = (_a = local[namespace]) === null || _a === void 0 ? void 0 : _a.delete(remoteKey.name);
35
34
  if (!keyExists) {
36
35
  result.removed.push({
37
36
  id: remoteKey.id,
38
37
  keyName: remoteKey.name,
39
- namespace: remoteKey.namespace || undefined,
38
+ namespace: remoteKey.namespace || '',
40
39
  });
41
40
  }
42
41
  }
43
42
  // Added keys
44
- const namespaces = [NullNamespace, ...Object.keys(local).sort()];
43
+ const namespaces = [...Object.keys(local).sort()];
45
44
  for (const namespace of namespaces) {
46
45
  if (namespace in local && local[namespace].size) {
47
46
  const keys = local[namespace];
@@ -49,7 +48,7 @@ export function compareKeys(local, remote) {
49
48
  for (const keyName of keyNames) {
50
49
  result.added.push({
51
50
  keyName: keyName,
52
- namespace: namespace === NullNamespace ? undefined : namespace,
51
+ namespace: namespace || '',
53
52
  defaultValue: keys.get(keyName) || undefined,
54
53
  });
55
54
  }
@@ -11,7 +11,6 @@ import { glob } from 'tinyglobby';
11
11
  import { extname } from 'path';
12
12
  import { callWorker } from './worker.js';
13
13
  import { exitWithError } from '../utils/logger.js';
14
- export const NullNamespace = Symbol('namespace.null');
15
14
  function parseVerbose(v) {
16
15
  return Array.isArray(v) ? v : v ? [] : undefined;
17
16
  }
@@ -101,7 +100,7 @@ export function filterExtractionResult(data) {
101
100
  const result = Object.create(null);
102
101
  for (const { keys } of data.values()) {
103
102
  for (const key of keys) {
104
- const namespace = key.namespace || NullNamespace;
103
+ const namespace = key.namespace || '';
105
104
  if (!(namespace in result)) {
106
105
  result[namespace] = new Map();
107
106
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tolgee/cli",
3
- "version": "2.12.1",
3
+ "version": "2.13.0",
4
4
  "type": "module",
5
5
  "description": "A tool to interact with the Tolgee Platform through CLI",
6
6
  "repository": {
package/schema.json CHANGED
@@ -165,8 +165,15 @@
165
165
  "type": "boolean"
166
166
  },
167
167
  "removeUnused": {
168
- "description": "Delete unused keys from the Tolgee project",
168
+ "description": "Delete unused keys from the Tolgee project (within selected namespaces if specified).",
169
169
  "type": "boolean"
170
+ },
171
+ "namespaces": {
172
+ "description": "Specifies which namespaces should be synchronized.",
173
+ "type": "array",
174
+ "items": {
175
+ "type": "string"
176
+ }
170
177
  }
171
178
  }
172
179
  },