gtx-cli 2.5.6 → 2.5.8

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 (67) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/api/downloadFileBatch.js +6 -6
  3. package/dist/api/saveLocalEdits.js +4 -3
  4. package/dist/api/uploadFiles.d.ts +1 -1
  5. package/dist/api/uploadFiles.js +5 -4
  6. package/dist/cli/base.js +17 -16
  7. package/dist/cli/commands/stage.js +8 -7
  8. package/dist/cli/commands/translate.js +3 -5
  9. package/dist/cli/flags.js +2 -3
  10. package/dist/cli/react.js +16 -15
  11. package/dist/config/generateSettings.js +2 -2
  12. package/dist/config/validateSettings.d.ts +1 -1
  13. package/dist/config/validateSettings.js +4 -4
  14. package/dist/console/logger.d.ts +27 -0
  15. package/dist/console/logger.js +255 -0
  16. package/dist/console/logging.d.ts +1 -11
  17. package/dist/console/logging.js +24 -55
  18. package/dist/formats/files/save.js +2 -2
  19. package/dist/formats/files/translate.js +8 -8
  20. package/dist/formats/files/upload.js +7 -6
  21. package/dist/formats/gt/save.js +4 -3
  22. package/dist/formats/json/flattenJson.js +3 -3
  23. package/dist/formats/json/mergeJson.d.ts +1 -1
  24. package/dist/formats/json/mergeJson.js +69 -21
  25. package/dist/formats/json/parseJson.js +14 -13
  26. package/dist/formats/json/utils.js +16 -15
  27. package/dist/formats/yaml/mergeYaml.js +6 -5
  28. package/dist/formats/yaml/parseYaml.js +4 -3
  29. package/dist/formats/yaml/utils.js +4 -3
  30. package/dist/fs/clearLocaleDirs.js +6 -6
  31. package/dist/fs/config/downloadedVersions.js +3 -3
  32. package/dist/fs/config/parseFilesConfig.js +2 -2
  33. package/dist/fs/config/setupConfig.js +2 -2
  34. package/dist/fs/config/updateConfig.js +2 -2
  35. package/dist/fs/config/updateVersions.js +3 -3
  36. package/dist/fs/copyFile.js +2 -2
  37. package/dist/fs/createLoadTranslationsFile.js +3 -3
  38. package/dist/fs/determineFramework.js +3 -3
  39. package/dist/fs/findFilepath.js +5 -4
  40. package/dist/hooks/postProcess.js +9 -9
  41. package/dist/next/parse/handleInitGT.js +2 -2
  42. package/dist/react/parse/addVitePlugin/index.js +4 -3
  43. package/dist/react/parse/addVitePlugin/installCompiler.js +2 -2
  44. package/dist/react/parse/addVitePlugin/updateViteConfig.js +9 -12
  45. package/dist/react/parse/createDictionaryUpdates.js +4 -3
  46. package/dist/react/parse/createInlineUpdates.js +2 -2
  47. package/dist/setup/wizard.js +17 -16
  48. package/dist/translation/parse.js +4 -3
  49. package/dist/translation/stage.js +4 -4
  50. package/dist/translation/validate.js +6 -6
  51. package/dist/types/index.d.ts +1 -0
  52. package/dist/utils/addExplicitAnchorIds.js +2 -2
  53. package/dist/utils/credentials.js +4 -3
  54. package/dist/utils/installPackage.js +11 -11
  55. package/dist/utils/packageJson.js +4 -3
  56. package/dist/workflow/BranchStep.js +5 -4
  57. package/dist/workflow/DownloadStep.js +5 -5
  58. package/dist/workflow/EnqueueStep.js +2 -2
  59. package/dist/workflow/PollJobsStep.js +3 -3
  60. package/dist/workflow/SetupStep.js +2 -2
  61. package/dist/workflow/UploadStep.js +3 -3
  62. package/dist/workflow/UserEditDiffsStep.js +2 -2
  63. package/dist/workflow/download.js +4 -3
  64. package/dist/workflow/stage.js +5 -4
  65. package/package.json +2 -2
  66. package/dist/utils/SpinnerManager.d.ts +0 -30
  67. package/dist/utils/SpinnerManager.js +0 -73
@@ -1,10 +1,11 @@
1
1
  import JSONPointer from 'jsonpointer';
2
- import { exit, logError, logWarning } from '../../console/logging.js';
3
- import { findMatchingItemArray, findMatchingItemObject, generateSourceObjectPointers, getSourceObjectOptionsArray, validateJsonSchema, } from './utils.js';
2
+ import { exitSync } from '../../console/logging.js';
3
+ import { logger } from '../../console/logger.js';
4
+ import { findMatchingItemArray, findMatchingItemObject, generateSourceObjectPointers, getIdentifyingLocaleProperty, getSourceObjectOptionsArray, validateJsonSchema, } from './utils.js';
4
5
  import { JSONPath } from 'jsonpath-plus';
5
6
  import { getLocaleProperties } from 'generaltranslation';
6
7
  import { replaceLocalePlaceholders } from '../utils.js';
7
- export function mergeJson(originalContent, inputPath, options, targets, defaultLocale) {
8
+ export function mergeJson(originalContent, inputPath, options, targets, defaultLocale, localeOrder = []) {
8
9
  const jsonSchema = validateJsonSchema(options, inputPath);
9
10
  if (!jsonSchema) {
10
11
  return targets.map((target) => target.translatedContent);
@@ -14,8 +15,8 @@ export function mergeJson(originalContent, inputPath, options, targets, defaultL
14
15
  originalJson = JSON.parse(originalContent);
15
16
  }
16
17
  catch {
17
- logError(`Invalid JSON file: ${inputPath}`);
18
- exit(1);
18
+ logger.error(`Invalid JSON file: ${inputPath}`);
19
+ return exitSync(1);
19
20
  }
20
21
  // Handle include
21
22
  if (jsonSchema.include) {
@@ -40,8 +41,8 @@ export function mergeJson(originalContent, inputPath, options, targets, defaultL
40
41
  return output;
41
42
  }
42
43
  if (!jsonSchema.composite) {
43
- logError('No composite property found in JSON schema');
44
- exit(1);
44
+ logger.error('No composite property found in JSON schema');
45
+ return exitSync(1);
45
46
  }
46
47
  // Handle composite
47
48
  // Create a deep copy of the original JSON to avoid mutations
@@ -54,13 +55,13 @@ export function mergeJson(originalContent, inputPath, options, targets, defaultL
54
55
  if (sourceObjectOptions.type === 'array') {
55
56
  // Validate type
56
57
  if (!Array.isArray(sourceObjectValue)) {
57
- logError(`Source object value is not an array at path: ${sourceObjectPointer}`);
58
- exit(1);
58
+ logger.error(`Source object value is not an array at path: ${sourceObjectPointer}`);
59
+ return exitSync(1);
59
60
  }
60
61
  // Get source item for default locale
61
62
  const matchingDefaultLocaleItems = findMatchingItemArray(defaultLocale, sourceObjectOptions, sourceObjectPointer, sourceObjectValue);
62
63
  if (!Object.keys(matchingDefaultLocaleItems).length) {
63
- logWarning(`Matching sourceItems not found at path: ${sourceObjectPointer}. Please check your JSON file includes the key field. Skipping this target`);
64
+ logger.warn(`Matching sourceItems not found at path: ${sourceObjectPointer}. Please check your JSON file includes the key field. Skipping this target`);
64
65
  continue;
65
66
  }
66
67
  const matchingDefaultLocaleItemKeys = new Set(Object.keys(matchingDefaultLocaleItems));
@@ -96,14 +97,14 @@ export function mergeJson(originalContent, inputPath, options, targets, defaultL
96
97
  };
97
98
  // 4. Validate that the mergedItems is not empty
98
99
  if (Object.keys(mergedItems).length === 0) {
99
- logWarning(`Translated JSON for locale: ${target.targetLocale} does not have a valid sourceObjectPointer: ${sourceObjectPointer}. Skipping this target`);
100
+ logger.warn(`Translated JSON for locale: ${target.targetLocale} does not have a valid sourceObjectPointer: ${sourceObjectPointer}. Skipping this target`);
100
101
  continue;
101
102
  }
102
103
  for (const [sourceItemPointer, targetItem] of Object.entries(mergedItems)) {
103
104
  // 5. Validate that all the array indecies are still present in the source json
104
105
  if (!matchingDefaultLocaleItemKeys.has(sourceItemPointer)) {
105
- logError(`Array index ${sourceItemPointer} is not present in the source json. It is possible that the source json has been modified since the translation was generated.`);
106
- exit(1);
106
+ logger.error(`Array index ${sourceItemPointer} is not present in the source json. It is possible that the source json has been modified since the translation was generated.`);
107
+ return exitSync(1);
107
108
  }
108
109
  // 6. Override the source item with the translated values
109
110
  const defaultLocaleSourceItem = matchingDefaultLocaleItems[sourceItemPointer].sourceItem;
@@ -129,27 +130,27 @@ export function mergeJson(originalContent, inputPath, options, targets, defaultL
129
130
  }
130
131
  // 8. Check that items to add is >= items to remove (if this happens, something is very wrong)
131
132
  if (itemsToAdd.length < indiciesToRemove.size) {
132
- logError(`Items to add is less than items to remove at path: ${sourceObjectPointer}. Please check your JSON schema key field.`);
133
- exit(1);
133
+ logger.error(`Items to add is less than items to remove at path: ${sourceObjectPointer}. Please check your JSON schema key field.`);
134
+ return exitSync(1);
134
135
  }
135
136
  // 9. Remove all items for the target locale (they can be identified by the key)
136
137
  const filteredSourceObjectValue = sourceObjectValue.filter((_, index) => !indiciesToRemove.has(index));
137
138
  // 10. Add all items to the original JSON
138
139
  filteredSourceObjectValue.push(...itemsToAdd);
139
- JSONPointer.set(mergedJson, sourceObjectPointer, filteredSourceObjectValue);
140
+ JSONPointer.set(mergedJson, sourceObjectPointer, sortByLocaleOrder(filteredSourceObjectValue, sourceObjectOptions, localeOrder, sourceObjectPointer, defaultLocale));
140
141
  }
141
142
  else {
142
143
  // Validate type
143
144
  if (typeof sourceObjectValue !== 'object' || sourceObjectValue === null) {
144
- logError(`Source object value is not an object at path: ${sourceObjectPointer}`);
145
- exit(1);
145
+ logger.error(`Source object value is not an object at path: ${sourceObjectPointer}`);
146
+ return exitSync(1);
146
147
  }
147
148
  // Validate localeProperty
148
149
  const matchingDefaultLocaleItem = findMatchingItemObject(defaultLocale, sourceObjectPointer, sourceObjectOptions, sourceObjectValue);
149
150
  // Validate source item exists
150
151
  if (!matchingDefaultLocaleItem.sourceItem) {
151
- logError(`Source item not found at path: ${sourceObjectPointer}. You must specify a source item where its key matches the default locale`);
152
- exit(1);
152
+ logger.error(`Source item not found at path: ${sourceObjectPointer}. You must specify a source item where its key matches the default locale`);
153
+ return exitSync(1);
153
154
  }
154
155
  const { sourceItem: defaultLocaleSourceItem } = matchingDefaultLocaleItem;
155
156
  // For each target:
@@ -180,7 +181,7 @@ export function mergeJson(originalContent, inputPath, options, targets, defaultL
180
181
  };
181
182
  // 4. Validate that the mergedItems is not empty
182
183
  if (Object.keys(mergedItems).length === 0) {
183
- logWarning(`Translated JSON for locale: ${target.targetLocale} does not have a valid sourceObjectPointer: ${sourceObjectPointer}. Skipping this target`);
184
+ logger.warn(`Translated JSON for locale: ${target.targetLocale} does not have a valid sourceObjectPointer: ${sourceObjectPointer}. Skipping this target`);
184
185
  continue;
185
186
  }
186
187
  // 5. Override the source item with the translated values
@@ -205,6 +206,53 @@ export function mergeJson(originalContent, inputPath, options, targets, defaultL
205
206
  }
206
207
  return [JSON.stringify(mergedJson, null, 2)];
207
208
  }
209
+ function sortByLocaleOrder(items, sourceObjectOptions, localeOrder, sourceObjectPointer, defaultLocale) {
210
+ if (sourceObjectOptions.experimentalSort !== 'locales' ||
211
+ !localeOrder.length ||
212
+ !sourceObjectOptions.key) {
213
+ return items;
214
+ }
215
+ const orderedLocaleList = [
216
+ defaultLocale,
217
+ ...localeOrder.filter((locale) => locale !== defaultLocale),
218
+ ];
219
+ const localeOrderValues = orderedLocaleList.map((locale) => getIdentifyingLocaleProperty(locale, sourceObjectPointer, sourceObjectOptions));
220
+ const itemsWithLocale = items.map((item) => {
221
+ let localeValue;
222
+ try {
223
+ const values = JSONPath({
224
+ json: item,
225
+ path: sourceObjectOptions.key,
226
+ resultType: 'value',
227
+ flatten: true,
228
+ wrap: true,
229
+ });
230
+ const value = values?.[0];
231
+ if (typeof value === 'string') {
232
+ localeValue = value;
233
+ }
234
+ }
235
+ catch {
236
+ /* empty */
237
+ }
238
+ return { item, localeValue };
239
+ });
240
+ const orderedItems = [];
241
+ const remainingItems = [...itemsWithLocale];
242
+ for (const localeValue of localeOrderValues) {
243
+ for (let i = 0; i < remainingItems.length;) {
244
+ const entry = remainingItems[i];
245
+ if (entry.localeValue === localeValue) {
246
+ orderedItems.push(entry.item);
247
+ remainingItems.splice(i, 1);
248
+ continue;
249
+ }
250
+ i += 1;
251
+ }
252
+ }
253
+ remainingItems.forEach((entry) => orderedItems.push(entry.item));
254
+ return orderedItems;
255
+ }
208
256
  /**
209
257
  * Apply transformations to the sourceItem in-place
210
258
  * @param sourceItem - The source item to apply transformations to
@@ -1,6 +1,7 @@
1
1
  import { flattenJsonWithStringFilter } from './flattenJson.js';
2
2
  import { JSONPath } from 'jsonpath-plus';
3
- import { exit, logError } from '../../console/logging.js';
3
+ import { exitSync } from '../../console/logging.js';
4
+ import { logger } from '../../console/logger.js';
4
5
  import { findMatchingItemArray, findMatchingItemObject, generateSourceObjectPointers, validateJsonSchema, } from './utils.js';
5
6
  // Parse a JSON file according to a JSON schema
6
7
  export function parseJson(content, filePath, options, defaultLocale) {
@@ -13,8 +14,8 @@ export function parseJson(content, filePath, options, defaultLocale) {
13
14
  json = JSON.parse(content);
14
15
  }
15
16
  catch {
16
- logError(`Invalid JSON file: ${filePath}`);
17
- exit(1);
17
+ logger.error(`Invalid JSON file: ${filePath}`);
18
+ return exitSync(1);
18
19
  }
19
20
  // Handle include
20
21
  if (jsonSchema.include) {
@@ -22,8 +23,8 @@ export function parseJson(content, filePath, options, defaultLocale) {
22
23
  return JSON.stringify(flattenedJson);
23
24
  }
24
25
  if (!jsonSchema.composite) {
25
- logError('No composite property found in JSON schema');
26
- exit(1);
26
+ logger.error('No composite property found in JSON schema');
27
+ return exitSync(1);
27
28
  }
28
29
  // Construct lvl 1
29
30
  // Create mapping of sourceObjectPointer to SourceObjectOptions
@@ -40,14 +41,14 @@ export function parseJson(content, filePath, options, defaultLocale) {
40
41
  if (sourceObjectOptions.type === 'array') {
41
42
  // Validate type
42
43
  if (!Array.isArray(sourceObjectValue)) {
43
- logError(`Source object value is not an array at path: ${sourceObjectPointer}`);
44
- exit(1);
44
+ logger.error(`Source object value is not an array at path: ${sourceObjectPointer}`);
45
+ return exitSync(1);
45
46
  }
46
47
  // Find matching source items
47
48
  const matchingItems = findMatchingItemArray(defaultLocale, sourceObjectOptions, sourceObjectPointer, sourceObjectValue);
48
49
  if (!Object.keys(matchingItems).length) {
49
- logError(`Matching sourceItem not found at path: ${sourceObjectPointer} for locale: ${defaultLocale}. Please check your JSON schema`);
50
- exit(1);
50
+ logger.error(`Matching sourceItem not found at path: ${sourceObjectPointer} for locale: ${defaultLocale}. Please check your JSON schema`);
51
+ return exitSync(1);
51
52
  }
52
53
  // Construct lvl 3
53
54
  const sourceItemsToTranslate = {};
@@ -87,15 +88,15 @@ export function parseJson(content, filePath, options, defaultLocale) {
87
88
  // Object: use the key in this object with the matching locale property
88
89
  // Validate type
89
90
  if (typeof sourceObjectValue !== 'object' || sourceObjectValue === null) {
90
- logError(`Source object value is not an object at path: ${sourceObjectPointer}`);
91
- exit(1);
91
+ logger.error(`Source object value is not an object at path: ${sourceObjectPointer}`);
92
+ return exitSync(1);
92
93
  }
93
94
  // Validate localeProperty
94
95
  const matchingItem = findMatchingItemObject(defaultLocale, sourceObjectPointer, sourceObjectOptions, sourceObjectValue);
95
96
  // Validate source item exists
96
97
  if (!matchingItem.sourceItem) {
97
- logError(`Source item not found at path: ${sourceObjectPointer}. You must specify a source item where its key matches the default locale`);
98
- exit(1);
98
+ logger.error(`Source item not found at path: ${sourceObjectPointer}. You must specify a source item where its key matches the default locale`);
99
+ return exitSync(1);
99
100
  }
100
101
  const { sourceItem } = matchingItem;
101
102
  // Get the fields to translate from the includes
@@ -1,5 +1,6 @@
1
1
  import { getLocaleProperties } from 'generaltranslation';
2
- import { exit, logError } from '../../console/logging.js';
2
+ import { exitSync } from '../../console/logging.js';
3
+ import { logger } from '../../console/logger.js';
3
4
  import { JSONPath } from 'jsonpath-plus';
4
5
  import { flattenJson } from './flattenJson.js';
5
6
  import path from 'node:path';
@@ -22,8 +23,8 @@ export function findMatchingItemArray(locale, sourceObjectOptions, sourceObjectP
22
23
  wrap: true,
23
24
  });
24
25
  if (!keyCandidates) {
25
- logError(`Source item at path: ${sourceObjectPointer} does not have a key value at path: ${localeKeyJsonPath}`);
26
- exit(1);
26
+ logger.error(`Source item at path: ${sourceObjectPointer} does not have a key value at path: ${localeKeyJsonPath}`);
27
+ return exitSync(1);
27
28
  }
28
29
  else if (keyCandidates.length === 0) {
29
30
  // If no key candidates, skip the item
@@ -31,8 +32,8 @@ export function findMatchingItemArray(locale, sourceObjectOptions, sourceObjectP
31
32
  }
32
33
  else if (keyCandidates.length > 1) {
33
34
  // If multiple key candidates, exit with an error
34
- logError(`Source item at path: ${sourceObjectPointer} has multiple matching keys with path: ${localeKeyJsonPath}`);
35
- exit(1);
35
+ logger.error(`Source item at path: ${sourceObjectPointer} has multiple matching keys with path: ${localeKeyJsonPath}`);
36
+ return exitSync(1);
36
37
  }
37
38
  else if (identifyingLocaleProperty !== keyCandidates[0].value) {
38
39
  // Validate the key is the identifying locale property
@@ -74,8 +75,8 @@ export function getIdentifyingLocaleProperty(locale, sourceObjectPointer, source
74
75
  const localeProperty = sourceObjectOptions.localeProperty || 'code';
75
76
  const identifyingLocaleProperty = getLocaleProperties(locale)[localeProperty];
76
77
  if (!identifyingLocaleProperty) {
77
- logError(`Source object options localeProperty is not a valid locale property at path: ${sourceObjectPointer}`);
78
- exit(1);
78
+ logger.error(`Source object options localeProperty is not a valid locale property at path: ${sourceObjectPointer}`);
79
+ return exitSync(1);
79
80
  }
80
81
  return identifyingLocaleProperty;
81
82
  }
@@ -90,8 +91,8 @@ export function getSourceObjectOptionsArray(locale, sourceObjectPointer, sourceO
90
91
  const identifyingLocaleProperty = getIdentifyingLocaleProperty(locale, sourceObjectPointer, sourceObjectOptions);
91
92
  const localeKeyJsonPath = sourceObjectOptions.key;
92
93
  if (!localeKeyJsonPath) {
93
- logError(`Source object options key is required for array at path: ${sourceObjectPointer}`);
94
- exit(1);
94
+ logger.error(`Source object options key is required for array at path: ${sourceObjectPointer}`);
95
+ return exitSync(1);
95
96
  }
96
97
  return { identifyingLocaleProperty, localeKeyJsonPath };
97
98
  }
@@ -99,8 +100,8 @@ export function getSourceObjectOptionsObject(defaultLocale, sourceObjectPointer,
99
100
  const identifyingLocaleProperty = getIdentifyingLocaleProperty(defaultLocale, sourceObjectPointer, sourceObjectOptions);
100
101
  const jsonPathKey = sourceObjectOptions.key;
101
102
  if (jsonPathKey) {
102
- logError(`Source object options key is not allowed for object at path: ${sourceObjectPointer}`);
103
- exit(1);
103
+ logger.error(`Source object options key is not allowed for object at path: ${sourceObjectPointer}`);
104
+ return exitSync(1);
104
105
  }
105
106
  return { identifyingLocaleProperty };
106
107
  }
@@ -136,13 +137,13 @@ export function validateJsonSchema(options, filePath) {
136
137
  // Validate includes or composite
137
138
  const jsonSchema = options.jsonSchema[matchingGlob];
138
139
  if (jsonSchema.include && jsonSchema.composite) {
139
- logError('include and composite cannot be used together in the same JSON schema');
140
- exit(1);
140
+ logger.error('include and composite cannot be used together in the same JSON schema');
141
+ return exitSync(1);
141
142
  return null;
142
143
  }
143
144
  if (!jsonSchema.include && !jsonSchema.composite) {
144
- logError('No include or composite property found in JSON schema');
145
- exit(1);
145
+ logger.error('No include or composite property found in JSON schema');
146
+ return exitSync(1);
146
147
  return null;
147
148
  }
148
149
  return jsonSchema;
@@ -1,5 +1,6 @@
1
1
  import JSONPointer from 'jsonpointer';
2
- import { exit, logError } from '../../console/logging.js';
2
+ import { exitSync } from '../../console/logging.js';
3
+ import { logger } from '../../console/logger.js';
3
4
  import { validateYamlSchema } from './utils.js';
4
5
  import YAML from 'yaml';
5
6
  import { applyTransformations } from '../json/mergeJson.js';
@@ -13,13 +14,13 @@ export default function mergeYaml(originalContent, inputPath, options, targets,
13
14
  originalYaml = YAML.parse(originalContent);
14
15
  }
15
16
  catch {
16
- logError(`Invalid YAML file: ${inputPath}`);
17
- exit(1);
17
+ logger.error(`Invalid YAML file: ${inputPath}`);
18
+ return exitSync(1);
18
19
  }
19
20
  // Unreachable (validated in validateYamlSchema, included for type check)
20
21
  if (!yamlSchema.include) {
21
- logError('No include property found in YAML schema');
22
- exit(1);
22
+ logger.error('No include property found in YAML schema');
23
+ return exitSync(1);
23
24
  }
24
25
  // Handle include
25
26
  const output = [];
@@ -1,4 +1,5 @@
1
- import { exit, logError } from '../../console/logging.js';
1
+ import { exitSync } from '../../console/logging.js';
2
+ import { logger } from '../../console/logger.js';
2
3
  import YAML from 'yaml';
3
4
  import { validateYamlSchema } from './utils.js';
4
5
  import { flattenJsonWithStringFilter } from '../json/flattenJson.js';
@@ -12,8 +13,8 @@ export default function parseYaml(content, filePath, options) {
12
13
  yaml = YAML.parse(content);
13
14
  }
14
15
  catch {
15
- logError(`Invalid YAML file: ${filePath}`);
16
- exit(1);
16
+ logger.error(`Invalid YAML file: ${filePath}`);
17
+ return exitSync(1);
17
18
  }
18
19
  if (yamlSchema.include) {
19
20
  const flattenedYaml = flattenJsonWithStringFilter(yaml, yamlSchema.include);
@@ -1,4 +1,5 @@
1
- import { logError, exit } from '../../console/logging.js';
1
+ import { exitSync } from '../../console/logging.js';
2
+ import { logger } from '../../console/logger.js';
2
3
  import micromatch from 'micromatch';
3
4
  const { isMatch } = micromatch;
4
5
  import path from 'path';
@@ -15,8 +16,8 @@ export function validateYamlSchema(options, filePath) {
15
16
  // Validate includes
16
17
  const yamlSchema = options.yamlSchema[matchingGlob];
17
18
  if (!yamlSchema.include) {
18
- logError('No include property found in YAML schema');
19
- exit(1);
19
+ logger.error('No include property found in YAML schema');
20
+ return exitSync(1);
20
21
  }
21
22
  return yamlSchema;
22
23
  }
@@ -1,6 +1,6 @@
1
1
  import fs from 'fs/promises';
2
2
  import path from 'node:path';
3
- import { logSuccess, logWarning } from '../console/logging.js';
3
+ import { logger } from '../console/logger.js';
4
4
  import fg from 'fast-glob';
5
5
  import micromatch from 'micromatch';
6
6
  /**
@@ -68,7 +68,7 @@ export async function clearLocaleDirs(filePaths, locales, excludePatterns, cwd =
68
68
  }
69
69
  if (!excludePatterns?.length) {
70
70
  await fs.rm(dir, { recursive: true, force: true });
71
- logSuccess(`Cleared locale directory: ${dir}`);
71
+ logger.success(`Cleared locale directory: ${dir}`);
72
72
  continue;
73
73
  }
74
74
  const filesToDelete = await getFilesToDelete(dir, excludePatterns, locale, cwd);
@@ -80,7 +80,7 @@ export async function clearLocaleDirs(filePaths, locales, excludePatterns, cwd =
80
80
  }
81
81
  catch (error) {
82
82
  if (error.code !== 'ENOENT') {
83
- logWarning(`Failed to delete file ${file}: ${error}`);
83
+ logger.warn(`Failed to delete file ${file}: ${error}`);
84
84
  }
85
85
  }
86
86
  }
@@ -88,15 +88,15 @@ export async function clearLocaleDirs(filePaths, locales, excludePatterns, cwd =
88
88
  await cleanupEmptyDirs(dir);
89
89
  const excludedCount = allFiles.length - filesToDelete.length;
90
90
  if (excludedCount > 0) {
91
- logSuccess(`Cleared locale directory: ${dir} (excluded ${excludedCount} file${excludedCount > 1 ? 's' : ''})`);
91
+ logger.success(`Cleared locale directory: ${dir} (excluded ${excludedCount} file${excludedCount > 1 ? 's' : ''})`);
92
92
  }
93
93
  else {
94
- logSuccess(`Cleared locale directory: ${dir}`);
94
+ logger.success(`Cleared locale directory: ${dir}`);
95
95
  }
96
96
  }
97
97
  catch (error) {
98
98
  if (error.code !== 'ENOENT') {
99
- logWarning(`Failed to clear locale directory ${dir}: ${error}`);
99
+ logger.warn(`Failed to clear locale directory ${dir}: ${error}`);
100
100
  }
101
101
  }
102
102
  }
@@ -1,6 +1,6 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
- import { logError } from '../../console/logging.js';
3
+ import { logger } from '../../console/logger.js';
4
4
  // New lock file name, use old name for deletion of legacy lock file
5
5
  const GT_LOCK_FILE = 'gt-lock.json';
6
6
  const LEGACY_DOWNLOADED_VERSIONS_FILE = 'downloaded-versions.json';
@@ -25,7 +25,7 @@ export function getDownloadedVersions(configDirectory) {
25
25
  return { version: 1, entries: {} };
26
26
  }
27
27
  catch (error) {
28
- logError(`An error occurred while getting downloaded versions: ${error}`);
28
+ logger.error(`An error occurred while getting downloaded versions: ${error}`);
29
29
  return { version: 1, entries: {} };
30
30
  }
31
31
  }
@@ -37,7 +37,7 @@ export function saveDownloadedVersions(configDirectory, lock) {
37
37
  fs.writeFileSync(filepath, JSON.stringify(lock, null, 2));
38
38
  }
39
39
  catch (error) {
40
- logError(`An error occurred while updating ${GT_LOCK_FILE}: ${error}`);
40
+ logger.error(`An error occurred while updating ${GT_LOCK_FILE}: ${error}`);
41
41
  }
42
42
  }
43
43
  export function ensureNestedObject(obj, path) {
@@ -1,7 +1,7 @@
1
1
  import path from 'node:path';
2
2
  import fg from 'fast-glob';
3
3
  import { SUPPORTED_FILE_EXTENSIONS } from '../../formats/files/supportedFiles.js';
4
- import { logWarning } from '../../console/logging.js';
4
+ import { logger } from '../../console/logger.js';
5
5
  import chalk from 'chalk';
6
6
  /**
7
7
  * Resolves the files from the files object
@@ -73,7 +73,7 @@ export function expandGlobPatterns(cwd, includePatterns, excludePatterns, locale
73
73
  if (!pattern.includes('[locale]') &&
74
74
  !transformPatterns &&
75
75
  !compositePatterns?.includes(pattern)) {
76
- logWarning(chalk.yellow(`Pattern "${pattern}" does not include [locale], so the CLI tool may incorrectly save translated files.`));
76
+ logger.warn(chalk.yellow(`Pattern "${pattern}" does not include [locale], so the CLI tool may incorrectly save translated files.`));
77
77
  }
78
78
  const localePositions = [];
79
79
  let searchIndex = 0;
@@ -1,6 +1,6 @@
1
1
  import fs from 'node:fs';
2
2
  import { displayCreatedConfigFile } from '../../console/logging.js';
3
- import { logError } from '../../console/logging.js';
3
+ import { logger } from '../../console/logger.js';
4
4
  import { GT_CONFIG_SCHEMA_URL } from '../../utils/constants.js';
5
5
  /**
6
6
  * Checks if the config file exists.
@@ -44,7 +44,7 @@ export async function createOrUpdateConfig(configFilepath, options) {
44
44
  displayCreatedConfigFile(configFilepath);
45
45
  }
46
46
  catch (error) {
47
- logError(`An error occurred while updating ${configFilepath}: ${error}`);
47
+ logger.error(`An error occurred while updating ${configFilepath}: ${error}`);
48
48
  }
49
49
  return configFilepath;
50
50
  }
@@ -1,6 +1,6 @@
1
1
  import fs from 'node:fs';
2
2
  import { displayUpdatedConfigFile } from '../../console/logging.js';
3
- import { logError } from '../../console/logging.js';
3
+ import { logger } from '../../console/logger.js';
4
4
  /**
5
5
  * Update the config file version id, locales, and projectId (if necessary)
6
6
  * @param {Record<string, any>} configObject - The config object to write if the file does not exist.
@@ -31,6 +31,6 @@ export default async function updateConfig({ configFilepath, projectId, _version
31
31
  displayUpdatedConfigFile(configFilepath);
32
32
  }
33
33
  catch (error) {
34
- logError(`An error occurred while updating ${configFilepath}: ${error}`);
34
+ logger.error(`An error occurred while updating ${configFilepath}: ${error}`);
35
35
  }
36
36
  }
@@ -1,6 +1,6 @@
1
1
  import fs from 'node:fs';
2
2
  import { displayUpdatedVersionsFile } from '../../console/logging.js';
3
- import { logError } from '../../console/logging.js';
3
+ import { logger } from '../../console/logger.js';
4
4
  import path from 'node:path';
5
5
  const STAGED_VERSIONS_FILE = 'staged-versions.json';
6
6
  // Update the versions.json file with the new version ids
@@ -14,7 +14,7 @@ export async function updateVersions({ configDirectory, versionData, }) {
14
14
  displayUpdatedVersionsFile(versionFilepath);
15
15
  }
16
16
  catch (error) {
17
- logError(`An error occurred while updating ${versionFilepath}: ${error}`);
17
+ logger.error(`An error occurred while updating ${versionFilepath}: ${error}`);
18
18
  }
19
19
  }
20
20
  export async function getStagedVersions(configDirectory) {
@@ -24,7 +24,7 @@ export async function getStagedVersions(configDirectory) {
24
24
  return versionData;
25
25
  }
26
26
  catch (error) {
27
- logError(`An error occurred while getting staged versions: ${error}`);
27
+ logger.error(`An error occurred while getting staged versions: ${error}`);
28
28
  return {};
29
29
  }
30
30
  }
@@ -1,6 +1,6 @@
1
1
  import path from 'node:path';
2
2
  import fs from 'node:fs';
3
- import { logError } from '../console/logging.js';
3
+ import { logger } from '../console/logger.js';
4
4
  /**
5
5
  * Copy a file to target locale without translation
6
6
  *
@@ -14,7 +14,7 @@ export default async function copyFile(settings) {
14
14
  const copyFiles = settings.options.copyFiles.reduce((paths, filePathTemplate) => {
15
15
  const sourcePath = path.join(process.cwd(), filePathTemplate.replace('[locale]', settings.defaultLocale));
16
16
  if (!fs.existsSync(sourcePath)) {
17
- logError(`Failed to copy files: File path does not exist: ${sourcePath}`);
17
+ logger.error(`Failed to copy files: File path does not exist: ${sourcePath}`);
18
18
  return paths;
19
19
  }
20
20
  paths[sourcePath] = [];
@@ -1,6 +1,6 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
- import { logInfo } from '../console/logging.js';
3
+ import { logger } from '../console/logger.js';
4
4
  import chalk from 'chalk';
5
5
  export async function createLoadTranslationsFile(appDirectory, translationsDir = './public/_gt') {
6
6
  const usingSrcDirectory = fs.existsSync(path.join(appDirectory, 'src'));
@@ -28,9 +28,9 @@ export default async function loadTranslations(locale) {
28
28
  }
29
29
  `;
30
30
  await fs.promises.writeFile(filePath, loadTranslationsContent);
31
- logInfo(`Created ${chalk.cyan('loadTranslations.js')} file at ${chalk.cyan(filePath)}.`);
31
+ logger.info(`Created ${chalk.cyan('loadTranslations.js')} file at ${chalk.cyan(filePath)}.`);
32
32
  }
33
33
  else {
34
- logInfo(`Found ${chalk.cyan('loadTranslations.js')} file at ${chalk.cyan(filePath)}. Skipping creation...`);
34
+ logger.info(`Found ${chalk.cyan('loadTranslations.js')} file at ${chalk.cyan(filePath)}. Skipping creation...`);
35
35
  }
36
36
  }
@@ -1,7 +1,7 @@
1
1
  import chalk from 'chalk';
2
2
  import path from 'node:path';
3
3
  import fs from 'node:fs';
4
- import { logWarning, logError } from '../console/logging.js';
4
+ import { logger } from '../console/logger.js';
5
5
  export function determineLibrary() {
6
6
  let library = 'base';
7
7
  const additionalModules = [];
@@ -11,7 +11,7 @@ export function determineLibrary() {
11
11
  const packageJsonPath = path.join(cwd, 'package.json');
12
12
  // Check if package.json exists
13
13
  if (!fs.existsSync(packageJsonPath)) {
14
- logWarning(chalk.yellow('No package.json found in the current directory. Please run this command from the root of your project.'));
14
+ logger.warn(chalk.yellow('No package.json found in the current directory. Please run this command from the root of your project.'));
15
15
  return { library: 'base', additionalModules: [] };
16
16
  }
17
17
  // Read and parse package.json
@@ -40,7 +40,7 @@ export function determineLibrary() {
40
40
  return { library, additionalModules };
41
41
  }
42
42
  catch (error) {
43
- logError('Error determining framework: ' + String(error));
43
+ logger.error('Error determining framework: ' + String(error));
44
44
  return { library: 'base', additionalModules: [] };
45
45
  }
46
46
  }
@@ -1,6 +1,7 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
- import { logError } from '../console/logging.js';
3
+ import { logger } from '../console/logger.js';
4
+ import { exitSync } from '../console/logging.js';
4
5
  /**
5
6
  * Resolve the file path from the given file path or default paths.
6
7
  * @param {string} filePath - The file path to resolve.
@@ -24,8 +25,8 @@ export function findFilepaths(paths, errorMessage = '') {
24
25
  }
25
26
  }
26
27
  if (errorMessage) {
27
- logError(errorMessage);
28
- process.exit(1);
28
+ logger.error(errorMessage);
29
+ exitSync(1);
29
30
  }
30
31
  return resolvedPaths;
31
32
  }
@@ -79,7 +80,7 @@ export function findFileInDir(dir, file) {
79
80
  }
80
81
  }
81
82
  catch (error) {
82
- logError('Error finding file in directory: ' + String(error));
83
+ logger.error('Error finding file in directory: ' + String(error));
83
84
  }
84
85
  return '';
85
86
  }