gtx-cli 2.5.7 → 2.5.9

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 (81) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/api/downloadFileBatch.js +5 -5
  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.d.ts +2 -1
  7. package/dist/cli/base.js +36 -30
  8. package/dist/cli/commands/setupProject.d.ts +7 -0
  9. package/dist/cli/commands/setupProject.js +50 -0
  10. package/dist/cli/commands/stage.d.ts +0 -2
  11. package/dist/cli/commands/stage.js +13 -61
  12. package/dist/cli/commands/translate.js +3 -5
  13. package/dist/cli/flags.js +2 -3
  14. package/dist/cli/next.js +1 -0
  15. package/dist/cli/react.d.ts +1 -0
  16. package/dist/cli/react.js +26 -15
  17. package/dist/config/generateSettings.js +2 -2
  18. package/dist/config/validateSettings.d.ts +1 -1
  19. package/dist/config/validateSettings.js +4 -4
  20. package/dist/console/logger.d.ts +35 -0
  21. package/dist/console/logger.js +270 -0
  22. package/dist/console/logging.d.ts +6 -11
  23. package/dist/console/logging.js +40 -55
  24. package/dist/formats/files/collectFiles.d.ts +6 -0
  25. package/dist/formats/files/collectFiles.js +49 -0
  26. package/dist/formats/files/fileMapping.js +1 -1
  27. package/dist/formats/files/save.js +2 -2
  28. package/dist/formats/files/translate.js +8 -8
  29. package/dist/formats/files/upload.js +7 -6
  30. package/dist/formats/gt/save.js +4 -3
  31. package/dist/formats/json/flattenJson.js +3 -3
  32. package/dist/formats/json/mergeJson.js +19 -18
  33. package/dist/formats/json/parseJson.js +14 -13
  34. package/dist/formats/json/utils.js +16 -15
  35. package/dist/formats/yaml/mergeYaml.js +6 -5
  36. package/dist/formats/yaml/parseYaml.js +4 -3
  37. package/dist/formats/yaml/utils.js +4 -3
  38. package/dist/fs/clearLocaleDirs.js +6 -6
  39. package/dist/fs/config/downloadedVersions.js +3 -3
  40. package/dist/fs/config/parseFilesConfig.js +2 -2
  41. package/dist/fs/config/setupConfig.js +2 -2
  42. package/dist/fs/config/updateConfig.js +2 -2
  43. package/dist/fs/config/updateVersions.js +3 -3
  44. package/dist/fs/copyFile.js +2 -2
  45. package/dist/fs/createLoadTranslationsFile.d.ts +1 -1
  46. package/dist/fs/createLoadTranslationsFile.js +11 -4
  47. package/dist/fs/determineFramework.js +3 -3
  48. package/dist/fs/findFilepath.js +5 -4
  49. package/dist/hooks/postProcess.js +9 -9
  50. package/dist/next/parse/handleInitGT.js +2 -2
  51. package/dist/react/parse/addVitePlugin/index.js +4 -3
  52. package/dist/react/parse/addVitePlugin/installCompiler.js +2 -2
  53. package/dist/react/parse/addVitePlugin/updateViteConfig.js +9 -12
  54. package/dist/react/parse/createDictionaryUpdates.js +4 -3
  55. package/dist/react/parse/createInlineUpdates.js +2 -2
  56. package/dist/setup/wizard.js +17 -16
  57. package/dist/translation/parse.js +4 -3
  58. package/dist/translation/stage.js +4 -4
  59. package/dist/translation/validate.js +6 -6
  60. package/dist/types/index.d.ts +1 -0
  61. package/dist/utils/addExplicitAnchorIds.js +2 -2
  62. package/dist/utils/constants.d.ts +2 -0
  63. package/dist/utils/constants.js +3 -0
  64. package/dist/utils/credentials.js +4 -3
  65. package/dist/utils/installPackage.js +11 -11
  66. package/dist/utils/packageJson.js +4 -3
  67. package/dist/workflow/BranchStep.js +5 -4
  68. package/dist/workflow/DownloadStep.js +5 -5
  69. package/dist/workflow/EnqueueStep.js +2 -2
  70. package/dist/workflow/PollJobsStep.js +4 -4
  71. package/dist/workflow/SetupStep.d.ts +1 -1
  72. package/dist/workflow/SetupStep.js +4 -3
  73. package/dist/workflow/UploadStep.js +3 -3
  74. package/dist/workflow/UserEditDiffsStep.js +2 -2
  75. package/dist/workflow/download.js +4 -3
  76. package/dist/workflow/setupProject.d.ts +13 -0
  77. package/dist/workflow/setupProject.js +48 -0
  78. package/dist/workflow/stage.js +4 -21
  79. package/package.json +3 -3
  80. package/dist/utils/SpinnerManager.d.ts +0 -30
  81. package/dist/utils/SpinnerManager.js +0 -73
@@ -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 +1 @@
1
- export declare function createLoadTranslationsFile(appDirectory: string, translationsDir?: string): Promise<void>;
1
+ export declare function createLoadTranslationsFile(appDirectory: string, translationsDir: string | undefined, locales: string[]): Promise<void>;
@@ -1,8 +1,8 @@
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
- export async function createLoadTranslationsFile(appDirectory, translationsDir = './public/_gt') {
5
+ export async function createLoadTranslationsFile(appDirectory, translationsDir = './public/_gt', locales) {
6
6
  const usingSrcDirectory = fs.existsSync(path.join(appDirectory, 'src'));
7
7
  // Calculate the relative path from the loadTranslations.js location to the translations directory
8
8
  const loadTranslationsDir = usingSrcDirectory
@@ -28,9 +28,16 @@ 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
+ // Create empty JSON files
33
+ for (const locale of locales) {
34
+ if (fs.existsSync(path.join(translationsDir, `${locale}.json`))) {
35
+ continue;
36
+ }
37
+ await fs.promises.writeFile(path.join(translationsDir, `${locale}.json`), '{}');
38
+ }
32
39
  }
33
40
  else {
34
- logInfo(`Found ${chalk.cyan('loadTranslations.js')} file at ${chalk.cyan(filePath)}. Skipping creation...`);
41
+ logger.info(`Found ${chalk.cyan('loadTranslations.js')} file at ${chalk.cyan(filePath)}. Skipping creation...`);
35
42
  }
36
43
  }
@@ -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
  }
@@ -1,7 +1,7 @@
1
1
  import fs from 'node:fs';
2
2
  import { spawn } from 'node:child_process';
3
3
  import chalk from 'chalk';
4
- import { logMessage, logWarning } from '../console/logging.js';
4
+ import { logger } from '../console/logger.js';
5
5
  export async function detectFormatter() {
6
6
  // Try Prettier
7
7
  try {
@@ -43,11 +43,11 @@ export async function formatFiles(filesUpdated, formatter) {
43
43
  try {
44
44
  const detectedFormatter = formatter || (await detectFormatter());
45
45
  if (!detectedFormatter) {
46
- logWarning(chalk.yellow('No supported formatter detected'));
46
+ logger.warn(chalk.yellow('No supported formatter detected'));
47
47
  return;
48
48
  }
49
49
  if (detectedFormatter === 'prettier') {
50
- logMessage(chalk.dim('Cleaning up with prettier...'));
50
+ logger.message(chalk.dim('Cleaning up with prettier...'));
51
51
  const prettier = await import('prettier');
52
52
  for (const file of filesUpdated) {
53
53
  const config = await prettier.resolveConfig(file);
@@ -61,7 +61,7 @@ export async function formatFiles(filesUpdated, formatter) {
61
61
  return;
62
62
  }
63
63
  if (detectedFormatter === 'biome') {
64
- logMessage(chalk.dim('Cleaning up with biome...'));
64
+ logger.message(chalk.dim('Cleaning up with biome...'));
65
65
  try {
66
66
  await new Promise((resolve, reject) => {
67
67
  const args = [
@@ -74,24 +74,24 @@ export async function formatFiles(filesUpdated, formatter) {
74
74
  stdio: ['ignore', 'inherit', 'inherit'],
75
75
  });
76
76
  child.on('error', (error) => {
77
- logWarning(chalk.yellow('Biome formatting failed: ' + error.message));
77
+ logger.warn(chalk.yellow('Biome formatting failed: ' + error.message));
78
78
  resolve();
79
79
  });
80
80
  child.on('close', (code) => {
81
81
  if (code !== 0) {
82
- logWarning(chalk.yellow(`Biome formatting failed with exit code ${code}`));
82
+ logger.warn(chalk.yellow(`Biome formatting failed with exit code ${code}`));
83
83
  }
84
84
  resolve();
85
85
  });
86
86
  });
87
87
  }
88
88
  catch (error) {
89
- logWarning(chalk.yellow('Biome formatting failed: ' + String(error)));
89
+ logger.warn(chalk.yellow('Biome formatting failed: ' + String(error)));
90
90
  }
91
91
  return;
92
92
  }
93
93
  if (detectedFormatter === 'eslint') {
94
- logMessage(chalk.dim('Cleaning up with eslint...'));
94
+ logger.message(chalk.dim('Cleaning up with eslint...'));
95
95
  const { ESLint } = await import('eslint');
96
96
  const eslint = new ESLint({
97
97
  fix: true,
@@ -105,6 +105,6 @@ export async function formatFiles(filesUpdated, formatter) {
105
105
  }
106
106
  }
107
107
  catch (e) {
108
- logWarning(chalk.yellow('Unable to run code formatter: ' + String(e)));
108
+ logger.warn(chalk.yellow('Unable to run code formatter: ' + String(e)));
109
109
  }
110
110
  }
@@ -6,7 +6,7 @@ import traverseModule from '@babel/traverse';
6
6
  const traverse = traverseModule.default || traverseModule;
7
7
  const generate = generateModule.default || generateModule;
8
8
  import * as t from '@babel/types';
9
- import { logError } from '../../console/logging.js';
9
+ import { logger } from '../../console/logger.js';
10
10
  import { needsCJS } from '../../utils/parse/needsCJS.js';
11
11
  export async function handleInitGT(filepath, errors, warnings, filesUpdated, packageJson, tsconfigJson) {
12
12
  const code = await fs.promises.readFile(filepath, 'utf8');
@@ -151,7 +151,7 @@ export async function handleInitGT(filepath, errors, warnings, filesUpdated, pac
151
151
  filesUpdated.push(filepath);
152
152
  }
153
153
  catch (error) {
154
- logError(`Error parsing file ${filepath}: ${error}`);
154
+ logger.error(`Error parsing file ${filepath}: ${error}`);
155
155
  errors.push(`Failed to parse ${filepath}: ${error}`);
156
156
  }
157
157
  }
@@ -1,7 +1,8 @@
1
1
  import findFilepath from '../../../fs/findFilepath.js';
2
- import { logError } from '../../../console/logging.js';
2
+ import { logger } from '../../../console/logger.js';
3
3
  import { installCompiler } from './installCompiler.js';
4
4
  import { updateViteConfig } from './updateViteConfig.js';
5
+ import { exitSync } from '../../../console/logging.js';
5
6
  const VITE_CONFIG_PATH_BASE = './vite.config.';
6
7
  /**
7
8
  * Adds the gt compiler plugin to the vite config file
@@ -17,13 +18,13 @@ export async function addVitePlugin({ errors, warnings, filesUpdated, packageJso
17
18
  VITE_CONFIG_PATH_BASE + 'cts',
18
19
  ]);
19
20
  if (!viteConfigPath) {
20
- logError(`No ${VITE_CONFIG_PATH_BASE}[js|ts|mjs|mts|cjs|cts] file found. Please add the @generaltranslation/compiler plugin to your vite configuration file:
21
+ logger.error(`No ${VITE_CONFIG_PATH_BASE}[js|ts|mjs|mts|cjs|cts] file found. Please add the @generaltranslation/compiler plugin to your vite configuration file:
21
22
  import { vite as gtCompiler } from '@generaltranslation/compiler';
22
23
  export default defineConfig({
23
24
  plugins: [gtCompiler()],
24
25
  });
25
26
  `);
26
- process.exit(1);
27
+ exitSync(1);
27
28
  }
28
29
  // Install @generaltranslation/compiler if not installed
29
30
  await installCompiler({ packageJson });
@@ -1,4 +1,4 @@
1
- import { createSpinner } from '../../../console/logging.js';
1
+ import { logger } from '../../../console/logger.js';
2
2
  import { installPackage } from '../../../utils/installPackage.js';
3
3
  import { isPackageInstalled } from '../../../utils/packageJson.js';
4
4
  import { getPackageManager } from '../../../utils/packageManager.js';
@@ -12,7 +12,7 @@ export async function installCompiler({ packageJson, }) {
12
12
  return;
13
13
  }
14
14
  // Animation
15
- const spinner = createSpinner();
15
+ const spinner = logger.createSpinner();
16
16
  spinner.start(`Installing @generaltranslation/compiler...`);
17
17
  // Install
18
18
  const packageManager = await getPackageManager();
@@ -1,5 +1,4 @@
1
- import { createSpinner } from '../../../console/logging.js';
2
- import { logError } from '../../../console/logging.js';
1
+ import { logger } from '../../../console/logger.js';
3
2
  import fs from 'node:fs';
4
3
  import chalk from 'chalk';
5
4
  import generateModule from '@babel/generator';
@@ -9,6 +8,7 @@ import { addCompilerImport } from './utils/addCompilerImport.js';
9
8
  import { checkCompilerImport } from './utils/checkCompilerImport.js';
10
9
  import { checkPluginInvocation } from './utils/checkPluginInvocation.js';
11
10
  import { addPluginInvocation } from './utils/addPluginInvocation.js';
11
+ import { exitSync } from '../../../console/logging.js';
12
12
  // Handle CommonJS/ESM interop
13
13
  const generate = generateModule.default || generateModule;
14
14
  /**
@@ -18,7 +18,7 @@ const generate = generateModule.default || generateModule;
18
18
  */
19
19
  export async function updateViteConfig({ errors, warnings, filesUpdated, viteConfigPath, packageJson, tsconfigJson, }) {
20
20
  // Animation
21
- const spinner = createSpinner();
21
+ const spinner = logger.createSpinner();
22
22
  spinner.start(`Adding gt compiler plugin to ${viteConfigPath}...`);
23
23
  // Read the file
24
24
  let code;
@@ -26,9 +26,8 @@ export async function updateViteConfig({ errors, warnings, filesUpdated, viteCon
26
26
  code = await fs.promises.readFile(viteConfigPath, 'utf8');
27
27
  }
28
28
  catch (error) {
29
- logError(`Error: Failed to read ${viteConfigPath}: ${error}`);
30
- process.exit(1);
31
- return;
29
+ logger.error(`Error: Failed to read ${viteConfigPath}: ${error}`);
30
+ exitSync(1);
32
31
  }
33
32
  // Update the ast
34
33
  let updatedCode, success;
@@ -43,9 +42,8 @@ export async function updateViteConfig({ errors, warnings, filesUpdated, viteCon
43
42
  }));
44
43
  }
45
44
  catch (error) {
46
- logError(`Error: Failed to update ${viteConfigPath}: ${error}`);
47
- process.exit(1);
48
- return;
45
+ logger.error(`Error: Failed to update ${viteConfigPath}: ${error}`);
46
+ exitSync(1);
49
47
  }
50
48
  // Write the file
51
49
  try {
@@ -53,9 +51,8 @@ export async function updateViteConfig({ errors, warnings, filesUpdated, viteCon
53
51
  filesUpdated.push(viteConfigPath);
54
52
  }
55
53
  catch (error) {
56
- logError(`Error: Failed to write ${viteConfigPath}: ${error}`);
57
- process.exit(1);
58
- return;
54
+ logger.error(`Error: Failed to write ${viteConfigPath}: ${error}`);
55
+ exitSync(1);
59
56
  }
60
57
  // Animation
61
58
  spinner.stop(success
@@ -6,10 +6,11 @@ import flattenDictionary from '../utils/flattenDictionary.js';
6
6
  import loadJSON from '../../fs/loadJSON.js';
7
7
  import { hashSource } from 'generaltranslation/id';
8
8
  import getEntryAndMetadata from '../utils/getEntryAndMetadata.js';
9
- import { logError } from '../../console/logging.js';
9
+ import { logger } from '../../console/logger.js';
10
10
  import { randomUUID } from 'node:crypto';
11
11
  import { isValidIcu } from '../jsx/evaluateJsx.js';
12
12
  import { warnInvalidIcuSync } from '../../console/index.js';
13
+ import { exitSync } from '../../console/logging.js';
13
14
  export async function createDictionaryUpdates(dictionaryPath, warnings, esbuildConfig) {
14
15
  let dictionary;
15
16
  // ---- HANDLE JSON STRING DICTIONARY ----- //
@@ -32,8 +33,8 @@ export async function createDictionaryUpdates(dictionaryPath, warnings, esbuildC
32
33
  dictionaryModule = await import(tempFilePath);
33
34
  }
34
35
  catch (error) {
35
- logError(`Failed to load the bundled dictionary code: ${error}`);
36
- process.exit(1);
36
+ logger.error(`Failed to load the bundled dictionary code: ${error}`);
37
+ exitSync(1);
37
38
  }
38
39
  finally {
39
40
  // Clean up the temporary file
@@ -3,7 +3,7 @@ import { parse } from '@babel/parser';
3
3
  import { hashSource } from 'generaltranslation/id';
4
4
  import { parseTranslationComponent } from '../jsx/utils/jsxParsing/parseJsx.js';
5
5
  import { parseStrings } from '../jsx/utils/parseStringFunction.js';
6
- import { logError } from '../../console/logging.js';
6
+ import { logger } from '../../console/logger.js';
7
7
  import { matchFiles } from '../../fs/matchFiles.js';
8
8
  import { DEFAULT_SRC_PATTERNS } from '../../config/generateSettings.js';
9
9
  import { getPathsAndAliases } from '../jsx/utils/getPathsAndAliases.js';
@@ -23,7 +23,7 @@ export async function createInlineUpdates(pkg, validate, filePatterns, parsingOp
23
23
  });
24
24
  }
25
25
  catch (error) {
26
- logError(`Error parsing file ${file}: ${error}`);
26
+ logger.error(`Error parsing file ${file}: ${error}`);
27
27
  continue;
28
28
  }
29
29
  // First pass: collect imports and process translation functions