@tolgee/cli 2.8.4 → 2.10.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.
Files changed (56) hide show
  1. package/dist/cli.js +116 -94
  2. package/dist/client/ApiClient.js +40 -32
  3. package/dist/client/ExportClient.js +24 -11
  4. package/dist/client/ImportClient.js +25 -16
  5. package/dist/client/TolgeeClient.js +1 -5
  6. package/dist/client/errorFromLoadable.js +3 -2
  7. package/dist/client/getApiKeyInformation.js +16 -6
  8. package/dist/commands/extract/check.js +38 -27
  9. package/dist/commands/extract/print.js +46 -35
  10. package/dist/commands/login.js +39 -26
  11. package/dist/commands/pull.js +60 -43
  12. package/dist/commands/push.js +167 -117
  13. package/dist/commands/sync/compare.js +43 -31
  14. package/dist/commands/sync/sync.js +118 -99
  15. package/dist/commands/sync/syncUtils.js +2 -1
  16. package/dist/commands/tag.js +52 -38
  17. package/dist/config/credentials.js +110 -93
  18. package/dist/config/tolgeerc.js +51 -35
  19. package/dist/extractor/extractor.js +45 -31
  20. package/dist/extractor/parser/extractComment.js +1 -1
  21. package/dist/extractor/parser/generateReport.js +8 -6
  22. package/dist/extractor/parser/iterator.js +2 -1
  23. package/dist/extractor/parser/mergerMachine.js +2 -11
  24. package/dist/extractor/parser/nodeUtils.js +1 -1
  25. package/dist/extractor/parser/parser.js +4 -2
  26. package/dist/extractor/parser/rules/tNsSourceGeneral.js +1 -1
  27. package/dist/extractor/parser/tree/getTranslateProps.js +21 -16
  28. package/dist/extractor/parser/tree/getValue.js +1 -1
  29. package/dist/extractor/parser/tree/parseTag.js +1 -1
  30. package/dist/extractor/parserNgx/ParserNgx.js +1 -3
  31. package/dist/extractor/parserNgx/ngxMapper.js +2 -1
  32. package/dist/extractor/parserNgx/ngxTreeTransform.js +3 -2
  33. package/dist/extractor/parserNgx/rules/translatePipe.js +1 -1
  34. package/dist/extractor/parserReact/ParserReact.js +1 -3
  35. package/dist/extractor/parserSvelte/ParserSvelte.js +1 -3
  36. package/dist/extractor/parserVue/ParserVue.js +1 -3
  37. package/dist/extractor/parserVue/tokenMergers/hyphenPropsMerger.js +1 -4
  38. package/dist/extractor/parserVue/vueTreeTransform.js +13 -2
  39. package/dist/extractor/runner.js +53 -39
  40. package/dist/extractor/tokenizer.js +50 -35
  41. package/dist/extractor/visualizers/printTokens.js +2 -1
  42. package/dist/extractor/visualizers/visualizeRules.js +4 -7
  43. package/dist/extractor/warnings.js +3 -2
  44. package/dist/extractor/worker.js +29 -16
  45. package/dist/options.js +2 -1
  46. package/dist/utils/apiKeyList.js +31 -19
  47. package/dist/utils/ask.js +35 -21
  48. package/dist/utils/checkPathNotAFile.js +22 -11
  49. package/dist/utils/filesTemplate.js +147 -0
  50. package/dist/utils/mapExportFormat.js +2 -0
  51. package/dist/utils/mapImportFormat.js +1 -1
  52. package/dist/utils/moduleLoader.js +37 -23
  53. package/dist/utils/prepareDir.js +20 -9
  54. package/dist/utils/valueToArray.js +8 -0
  55. package/package.json +2 -2
  56. package/schema.json +20 -4
@@ -1,3 +1,12 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
1
10
  import { Command } from 'commander';
2
11
  import ansi from 'ansi-colors';
3
12
  import { compareKeys, printKey } from './syncUtils.js';
@@ -5,39 +14,42 @@ import { extractKeysOfFiles, filterExtractionResult, } from '../../extractor/run
5
14
  import { dumpWarnings } from '../../extractor/warnings.js';
6
15
  import { loading } from '../../utils/logger.js';
7
16
  import { handleLoadableError } from '../../client/TolgeeClient.js';
8
- const asyncHandler = (config) => async function () {
9
- const opts = this.optsWithGlobals();
10
- const rawKeys = await loading('Analyzing code...', extractKeysOfFiles(opts));
11
- dumpWarnings(rawKeys);
12
- const localKeys = filterExtractionResult(rawKeys);
13
- const loadable = await opts.client.GET('/v2/projects/{projectId}/all-keys', { params: { path: { projectId: opts.client.getProjectId() } } });
14
- handleLoadableError(loadable);
15
- const remoteKeys = loadable.data._embedded.keys ?? [];
16
- const diff = compareKeys(localKeys, remoteKeys);
17
- if (!diff.added.length && !diff.removed.length) {
18
- console.log(ansi.green('Your code project is in sync with the associated Tolgee project!'));
19
- process.exit(0);
20
- }
21
- console.log('Your code project and Tolgee project are out of sync.');
22
- if (diff.added.length) {
23
- const key = diff.added.length === 1 ? 'key' : 'keys';
24
- console.log(ansi.green.bold(`${diff.added.length} new ${key} found`));
25
- for (const key of diff.added) {
26
- printKey(key, false);
17
+ const asyncHandler = (config) => function () {
18
+ return __awaiter(this, void 0, void 0, function* () {
19
+ var _a;
20
+ const opts = this.optsWithGlobals();
21
+ const rawKeys = yield loading('Analyzing code...', extractKeysOfFiles(opts));
22
+ dumpWarnings(rawKeys);
23
+ const localKeys = filterExtractionResult(rawKeys);
24
+ const loadable = yield opts.client.GET('/v2/projects/{projectId}/all-keys', { params: { path: { projectId: opts.client.getProjectId() } } });
25
+ handleLoadableError(loadable);
26
+ const remoteKeys = (_a = loadable.data._embedded.keys) !== null && _a !== void 0 ? _a : [];
27
+ const diff = compareKeys(localKeys, remoteKeys);
28
+ if (!diff.added.length && !diff.removed.length) {
29
+ console.log(ansi.green('Your code project is in sync with the associated Tolgee project!'));
30
+ process.exit(0);
31
+ }
32
+ console.log('Your code project and Tolgee project are out of sync.');
33
+ if (diff.added.length) {
34
+ const key = diff.added.length === 1 ? 'key' : 'keys';
35
+ console.log(ansi.green.bold(`${diff.added.length} new ${key} found`));
36
+ for (const key of diff.added) {
37
+ printKey(key, false);
38
+ }
39
+ // Line break
40
+ console.log('');
27
41
  }
28
- // Line break
29
- console.log('');
30
- }
31
- if (diff.removed.length) {
32
- const key = diff.removed.length === 1 ? 'key' : 'keys';
33
- console.log(ansi.red.bold(`${diff.removed.length} unused ${key}`));
34
- for (const key of diff.removed) {
35
- printKey(key, true);
42
+ if (diff.removed.length) {
43
+ const key = diff.removed.length === 1 ? 'key' : 'keys';
44
+ console.log(ansi.red.bold(`${diff.removed.length} unused ${key}`));
45
+ for (const key of diff.removed) {
46
+ printKey(key, true);
47
+ }
48
+ // Line break
49
+ console.log('');
36
50
  }
37
- // Line break
38
- console.log('');
39
- }
40
- console.log('Run `tolgee sync` to synchronize the projects.');
51
+ console.log('Run `tolgee sync` to synchronize the projects.');
52
+ });
41
53
  };
42
54
  export default (config) => new Command()
43
55
  .name('compare')
@@ -1,3 +1,12 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
1
10
  import { Command, Option } from 'commander';
2
11
  import ansi from 'ansi-colors';
3
12
  import { extractKeysOfFiles, filterExtractionResult, } from '../../extractor/runner.js';
@@ -8,114 +17,124 @@ import { unzipBuffer } from '../../utils/zip.js';
8
17
  import { askBoolean } from '../../utils/ask.js';
9
18
  import { loading, exitWithError } from '../../utils/logger.js';
10
19
  import { handleLoadableError, } from '../../client/TolgeeClient.js';
11
- async function backup(client, dest) {
12
- const loadable = await client.export.export({
13
- format: 'JSON',
14
- supportArrays: false,
15
- filterState: ['UNTRANSLATED', 'TRANSLATED', 'REVIEWED'],
16
- structureDelimiter: '',
20
+ function backup(client, dest) {
21
+ return __awaiter(this, void 0, void 0, function* () {
22
+ const loadable = yield client.export.export({
23
+ format: 'JSON',
24
+ supportArrays: false,
25
+ filterState: ['UNTRANSLATED', 'TRANSLATED', 'REVIEWED'],
26
+ structureDelimiter: '',
27
+ });
28
+ handleLoadableError(loadable);
29
+ const blob = loadable.data;
30
+ yield unzipBuffer(blob, dest);
17
31
  });
18
- handleLoadableError(loadable);
19
- const blob = loadable.data;
20
- await unzipBuffer(blob, dest);
21
32
  }
22
- async function askForConfirmation(keys, operation) {
23
- if (!process.stdout.isTTY) {
24
- exitWithError('You must run this command interactively, or specify --yes to proceed.');
25
- }
26
- const str = `The following keys will be ${operation}:`;
27
- console.log(operation === 'created' ? ansi.bold.green(str) : ansi.bold.red(str));
28
- keys.forEach((k) => printKey(k, operation === 'deleted'));
29
- const shouldContinue = await askBoolean('Does this look correct?', true);
30
- if (!shouldContinue) {
31
- exitWithError('Aborting.');
32
- }
33
- }
34
- const syncHandler = (config) => async function () {
35
- const opts = this.optsWithGlobals();
36
- const rawKeys = await loading('Analyzing code...', extractKeysOfFiles(opts));
37
- const warnCount = dumpWarnings(rawKeys);
38
- if (!opts.continueOnWarning && warnCount) {
39
- console.log(ansi.bold.red('Aborting as warnings have been emitted.'));
40
- process.exit(1);
41
- }
42
- const localKeys = filterExtractionResult(rawKeys);
43
- const allKeysLoadable = await opts.client.GET('/v2/projects/{projectId}/all-keys', {
44
- params: { path: { projectId: opts.client.getProjectId() } },
45
- });
46
- handleLoadableError(allKeysLoadable);
47
- const remoteKeys = allKeysLoadable.data?._embedded?.keys ?? [];
48
- const diff = compareKeys(localKeys, remoteKeys);
49
- if (!diff.added.length && !diff.removed.length) {
50
- console.log(ansi.green('Your code project is in sync with the associated Tolgee project!'));
51
- process.exit(0);
52
- }
53
- // Load project settings. We're interested in the default locale here.
54
- const projectLoadable = await opts.client.GET('/v2/projects/{projectId}', {
55
- params: { path: { projectId: opts.client.getProjectId() } },
33
+ function askForConfirmation(keys, operation) {
34
+ return __awaiter(this, void 0, void 0, function* () {
35
+ if (!process.stdout.isTTY) {
36
+ exitWithError('You must run this command interactively, or specify --yes to proceed.');
37
+ }
38
+ const str = `The following keys will be ${operation}:`;
39
+ console.log(operation === 'created' ? ansi.bold.green(str) : ansi.bold.red(str));
40
+ keys.forEach((k) => printKey(k, operation === 'deleted'));
41
+ const shouldContinue = yield askBoolean('Does this look correct?', true);
42
+ if (!shouldContinue) {
43
+ exitWithError('Aborting.');
44
+ }
56
45
  });
57
- handleLoadableError(projectLoadable);
58
- const baseLanguage = projectLoadable.data.baseLanguage;
59
- if (!baseLanguage) {
60
- // I'm highly unsure how we could reach this state, but this is what the OAI spec tells me ¯\_(ツ)_/¯
61
- exitWithError('Your project does not have a base language!');
62
- }
63
- // Prepare backup
64
- if (opts.backup) {
65
- await prepareDir(opts.backup, opts.yes);
66
- await loading('Backing up Tolgee project', backup(opts.client, opts.backup));
67
- }
68
- // Create new keys
69
- if (diff.added.length) {
70
- if (!opts.yes) {
71
- await askForConfirmation(diff.added, 'created');
46
+ }
47
+ const syncHandler = (config) => function () {
48
+ return __awaiter(this, void 0, void 0, function* () {
49
+ var _a, _b, _c;
50
+ const opts = this.optsWithGlobals();
51
+ const rawKeys = yield loading('Analyzing code...', extractKeysOfFiles(opts));
52
+ const warnCount = dumpWarnings(rawKeys);
53
+ if (!opts.continueOnWarning && warnCount) {
54
+ console.log(ansi.bold.red('Aborting as warnings have been emitted.'));
55
+ process.exit(1);
72
56
  }
73
- const keys = diff.added.map((key) => ({
74
- name: key.keyName,
75
- namespace: key.namespace,
76
- translations: key.defaultValue
77
- ? { [baseLanguage.tag]: key.defaultValue }
78
- : {},
79
- tags: opts.tagNewKeys,
80
- }));
81
- const loadable = await loading('Creating missing keys...', opts.client.POST('/v2/projects/{projectId}/keys/import', {
57
+ const localKeys = filterExtractionResult(rawKeys);
58
+ const allKeysLoadable = yield opts.client.GET('/v2/projects/{projectId}/all-keys', {
82
59
  params: { path: { projectId: opts.client.getProjectId() } },
83
- body: { keys },
84
- }));
85
- handleLoadableError(loadable);
86
- }
87
- if (opts.removeUnused) {
88
- // Delete unused keys.
89
- if (diff.removed.length) {
60
+ });
61
+ 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 : [];
63
+ const diff = compareKeys(localKeys, remoteKeys);
64
+ if (!diff.added.length && !diff.removed.length) {
65
+ console.log(ansi.green('Your code project is in sync with the associated Tolgee project!'));
66
+ process.exit(0);
67
+ }
68
+ // Load project settings. We're interested in the default locale here.
69
+ const projectLoadable = yield opts.client.GET('/v2/projects/{projectId}', {
70
+ params: { path: { projectId: opts.client.getProjectId() } },
71
+ });
72
+ handleLoadableError(projectLoadable);
73
+ const baseLanguage = projectLoadable.data.baseLanguage;
74
+ if (!baseLanguage) {
75
+ // I'm highly unsure how we could reach this state, but this is what the OAI spec tells me ¯\_(ツ)_/¯
76
+ exitWithError('Your project does not have a base language!');
77
+ }
78
+ // Prepare backup
79
+ if (opts.backup) {
80
+ yield prepareDir(opts.backup, opts.yes);
81
+ yield loading('Backing up Tolgee project', backup(opts.client, opts.backup));
82
+ }
83
+ // Create new keys
84
+ if (diff.added.length) {
90
85
  if (!opts.yes) {
91
- await askForConfirmation(diff.removed, 'deleted');
86
+ yield askForConfirmation(diff.added, 'created');
92
87
  }
93
- const ids = await diff.removed.map((k) => k.id);
94
- const loadable = await loading('Deleting unused keys...', opts.client.DELETE('/v2/projects/{projectId}/keys', {
88
+ const keys = diff.added.map((key) => ({
89
+ name: key.keyName,
90
+ namespace: key.namespace,
91
+ translations: key.defaultValue
92
+ ? { [baseLanguage.tag]: key.defaultValue }
93
+ : {},
94
+ tags: opts.tagNewKeys,
95
+ }));
96
+ const loadable = yield loading('Creating missing keys...', opts.client.POST('/v2/projects/{projectId}/keys/import', {
95
97
  params: { path: { projectId: opts.client.getProjectId() } },
96
- body: { ids },
98
+ body: { keys },
97
99
  }));
98
100
  handleLoadableError(loadable);
99
101
  }
100
- }
101
- console.log(ansi.bold.green('Sync complete!'));
102
- console.log(ansi.green(`+ ${diff.added.length} string${diff.added.length === 1 ? '' : 's'}`));
103
- if (opts.removeUnused) {
104
- console.log(ansi.red(`- ${diff.removed.length} string${diff.removed.length === 1 ? '' : 's'}`));
105
- }
106
- else {
107
- console.log(ansi.italic(`${diff.removed.length} unused key${diff.removed.length === 1 ? '' : 's'} could be deleted.`));
108
- }
109
- if (opts.backup) {
110
- console.log(ansi.blueBright(`A backup of the project prior to the synchronization has been dumped in ${opts.backup}.`));
111
- }
102
+ if (opts.removeUnused) {
103
+ // Delete unused keys.
104
+ if (diff.removed.length) {
105
+ if (!opts.yes) {
106
+ yield askForConfirmation(diff.removed, 'deleted');
107
+ }
108
+ const ids = yield diff.removed.map((k) => k.id);
109
+ const loadable = yield loading('Deleting unused keys...', opts.client.DELETE('/v2/projects/{projectId}/keys', {
110
+ params: { path: { projectId: opts.client.getProjectId() } },
111
+ body: { ids },
112
+ }));
113
+ handleLoadableError(loadable);
114
+ }
115
+ }
116
+ console.log(ansi.bold.green('Sync complete!'));
117
+ console.log(ansi.green(`+ ${diff.added.length} string${diff.added.length === 1 ? '' : 's'}`));
118
+ if (opts.removeUnused) {
119
+ console.log(ansi.red(`- ${diff.removed.length} string${diff.removed.length === 1 ? '' : 's'}`));
120
+ }
121
+ else {
122
+ console.log(ansi.italic(`${diff.removed.length} unused key${diff.removed.length === 1 ? '' : 's'} could be deleted.`));
123
+ }
124
+ if (opts.backup) {
125
+ console.log(ansi.blueBright(`A backup of the project prior to the synchronization has been dumped in ${opts.backup}.`));
126
+ }
127
+ });
128
+ };
129
+ export default (config) => {
130
+ var _a, _b, _c, _d, _e, _f;
131
+ return new Command()
132
+ .name('sync')
133
+ .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
+ .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
+ .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))
136
+ .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))
138
+ .option('--tag-new-keys <tags...>', 'Specify tags that will be added to newly created keys.')
139
+ .action(syncHandler(config));
112
140
  };
113
- export default (config) => new Command()
114
- .name('sync')
115
- .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`.')
116
- .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(config.sync?.backup ?? false))
117
- .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(config.sync?.continueOnWarning ?? false))
118
- .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))
119
- .addOption(new Option('--remove-unused', 'Delete unused keys from the Tolgee project.').default(config.sync?.removeUnused ?? false))
120
- .option('--tag-new-keys <tags...>', 'Specify tags that will be added to newly created keys.')
121
- .action(syncHandler(config));
@@ -26,11 +26,12 @@ export function printKey(key, deletion) {
26
26
  * @returns A list of added and removed keys.
27
27
  */
28
28
  export function compareKeys(local, remote) {
29
+ var _a;
29
30
  const result = { added: [], removed: [] };
30
31
  // Deleted keys
31
32
  for (const remoteKey of remote) {
32
33
  const namespace = remoteKey.namespace || NullNamespace;
33
- const keyExists = local[namespace]?.delete(remoteKey.name);
34
+ const keyExists = (_a = local[namespace]) === null || _a === void 0 ? void 0 : _a.delete(remoteKey.name);
34
35
  if (!keyExists) {
35
36
  result.removed.push({
36
37
  id: remoteKey.id,
@@ -1,45 +1,59 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
1
10
  import { Command, Option } from 'commander';
2
11
  import { handleLoadableError } from '../client/TolgeeClient.js';
3
12
  import { exitWithError, loading, success } from '../utils/logger.js';
4
13
  import { extractKeysOfFiles } from '../extractor/runner.js';
5
- const tagHandler = (config) => async function () {
6
- const opts = this.optsWithGlobals();
7
- let extractedKeys;
8
- if (opts.filterExtracted || opts.filterNotExtracted) {
9
- if (opts.filterExtracted && opts.filterNotExtracted) {
10
- exitWithError('Use either "--filter-extracted" or "--filter-not-extracted", not both');
14
+ const tagHandler = (config) => function () {
15
+ return __awaiter(this, void 0, void 0, function* () {
16
+ const opts = this.optsWithGlobals();
17
+ let extractedKeys;
18
+ if (opts.filterExtracted || opts.filterNotExtracted) {
19
+ if (opts.filterExtracted && opts.filterNotExtracted) {
20
+ exitWithError('Use either "--filter-extracted" or "--filter-not-extracted", not both');
21
+ }
22
+ const extracted = yield loading('Analyzing code...', extractKeysOfFiles(opts));
23
+ const keys = [...extracted.values()].flatMap((item) => item.keys);
24
+ extractedKeys = keys.map((key) => ({
25
+ name: key.keyName,
26
+ namespace: key.namespace,
27
+ }));
11
28
  }
12
- const extracted = await loading('Analyzing code...', extractKeysOfFiles(opts));
13
- const keys = [...extracted.values()].flatMap((item) => item.keys);
14
- extractedKeys = keys.map((key) => ({
15
- name: key.keyName,
16
- namespace: key.namespace,
29
+ const loadable = yield loading('Tagging...', opts.client.PUT('/v2/projects/{projectId}/tag-complex', {
30
+ params: { path: { projectId: opts.client.getProjectId() } },
31
+ body: {
32
+ filterTag: opts.filterTag,
33
+ filterTagNot: opts.filterNoTag,
34
+ tagFiltered: opts.tag,
35
+ tagOther: opts.tagOther,
36
+ untagFiltered: opts.untag,
37
+ untagOther: opts.untagOther,
38
+ filterKeys: opts.filterExtracted ? extractedKeys : undefined,
39
+ filterKeysNot: opts.filterNotExtracted ? extractedKeys : undefined,
40
+ },
17
41
  }));
18
- }
19
- const loadable = await loading('Tagging...', opts.client.PUT('/v2/projects/{projectId}/tag-complex', {
20
- params: { path: { projectId: opts.client.getProjectId() } },
21
- body: {
22
- filterTag: opts.filterTag,
23
- filterTagNot: opts.filterNoTag,
24
- tagFiltered: opts.tag,
25
- tagOther: opts.tagOther,
26
- untagFiltered: opts.untag,
27
- untagOther: opts.untagOther,
28
- filterKeys: opts.filterExtracted ? extractedKeys : undefined,
29
- filterKeysNot: opts.filterNotExtracted ? extractedKeys : undefined,
30
- },
31
- }));
32
- handleLoadableError(loadable);
33
- success('Done!');
42
+ handleLoadableError(loadable);
43
+ success('Done!');
44
+ });
45
+ };
46
+ export default (config) => {
47
+ var _a, _b, _c, _d, _e, _f, _g, _h;
48
+ return new Command('tag')
49
+ .description('Update tags in your project.')
50
+ .addOption(new Option('--filter-extracted', 'Extract keys from code and filter by it.').default((_a = config.tag) === null || _a === void 0 ? void 0 : _a.filterExtracted))
51
+ .addOption(new Option('--filter-not-extracted', 'Extract keys from code and filter them out.').default((_b = config.tag) === null || _b === void 0 ? void 0 : _b.filterNotExtracted))
52
+ .addOption(new Option('--filter-tag <tags...>', 'Filter only keys with tag. Use * as a wildcard.').default((_c = config.tag) === null || _c === void 0 ? void 0 : _c.filterTag))
53
+ .addOption(new Option('--filter-no-tag <tags...>', 'Filter only keys without tag. Use * as a wildcard.').default((_d = config.tag) === null || _d === void 0 ? void 0 : _d.filterNoTag))
54
+ .addOption(new Option('--tag <tags...>', 'Add tag to filtered keys.').default((_e = config.tag) === null || _e === void 0 ? void 0 : _e.tag))
55
+ .addOption(new Option('--tag-other <tags...>', 'Tag keys which are not filtered.').default((_f = config.tag) === null || _f === void 0 ? void 0 : _f.tagOther))
56
+ .addOption(new Option('--untag <tags...>', 'Remove tag from filtered keys. Use * as a wildcard.').default((_g = config.tag) === null || _g === void 0 ? void 0 : _g.untag))
57
+ .addOption(new Option('--untag-other <tags...>', 'Remove tag from keys which are not filtered. Use * as a wildcard.').default((_h = config.tag) === null || _h === void 0 ? void 0 : _h.untagOther))
58
+ .action(tagHandler(config));
34
59
  };
35
- export default (config) => new Command('tag')
36
- .description('Update tags in your project.')
37
- .addOption(new Option('--filter-extracted', 'Extract keys from code and filter by it.').default(config.tag?.filterExtracted))
38
- .addOption(new Option('--filter-not-extracted', 'Extract keys from code and filter them out.').default(config.tag?.filterNotExtracted))
39
- .addOption(new Option('--filter-tag <tags...>', 'Filter only keys with tag. Use * as a wildcard.').default(config.tag?.filterTag))
40
- .addOption(new Option('--filter-no-tag <tags...>', 'Filter only keys without tag. Use * as a wildcard.').default(config.tag?.filterNoTag))
41
- .addOption(new Option('--tag <tags...>', 'Add tag to filtered keys.').default(config.tag?.tag))
42
- .addOption(new Option('--tag-other <tags...>', 'Tag keys which are not filtered.').default(config.tag?.tagOther))
43
- .addOption(new Option('--untag <tags...>', 'Remove tag from filtered keys. Use * as a wildcard.').default(config.tag?.untag))
44
- .addOption(new Option('--untag-other <tags...>', 'Remove tag from keys which are not filtered. Use * as a wildcard.').default(config.tag?.untagOther))
45
- .action(tagHandler(config));