gtx-cli 1.2.15 → 1.2.17

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 (142) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/api/checkFileTranslations.d.ts +19 -0
  3. package/dist/api/checkFileTranslations.js +244 -0
  4. package/dist/api/downloadFile.d.ts +1 -0
  5. package/dist/api/downloadFile.js +83 -0
  6. package/dist/api/downloadFileBatch.d.ts +16 -0
  7. package/dist/api/downloadFileBatch.js +127 -0
  8. package/dist/api/fetchTranslations.d.ts +10 -0
  9. package/dist/api/fetchTranslations.js +35 -0
  10. package/dist/api/sendFiles.d.ts +24 -0
  11. package/dist/api/sendFiles.js +63 -0
  12. package/dist/api/sendUpdates.d.ts +19 -0
  13. package/dist/api/sendUpdates.js +75 -0
  14. package/dist/api/waitForUpdates.d.ts +11 -0
  15. package/dist/api/waitForUpdates.js +96 -0
  16. package/dist/cli/base.d.ts +28 -0
  17. package/dist/cli/base.js +322 -0
  18. package/dist/cli/next.d.ts +10 -0
  19. package/dist/cli/next.js +27 -0
  20. package/dist/cli/react.d.ts +18 -0
  21. package/dist/cli/react.js +305 -0
  22. package/dist/config/generateSettings.d.ts +7 -0
  23. package/dist/config/generateSettings.js +94 -0
  24. package/dist/config/utils.d.ts +2 -0
  25. package/dist/config/utils.js +7 -0
  26. package/dist/config/validateSettings.d.ts +2 -0
  27. package/dist/config/validateSettings.js +23 -0
  28. package/dist/console/colors.d.ts +5 -0
  29. package/dist/console/colors.js +26 -0
  30. package/dist/console/console.d.ts +1 -0
  31. package/dist/console/console.js +20 -0
  32. package/dist/console/errors.d.ts +1 -0
  33. package/dist/console/errors.js +20 -0
  34. package/dist/console/index.d.ts +19 -0
  35. package/dist/console/index.js +48 -0
  36. package/dist/console/logging.d.ts +55 -0
  37. package/dist/console/logging.js +207 -0
  38. package/dist/console/warnings.d.ts +1 -0
  39. package/dist/console/warnings.js +20 -0
  40. package/dist/formats/files/save.d.ts +5 -0
  41. package/dist/formats/files/save.js +23 -0
  42. package/dist/formats/files/supportedFiles.d.ts +8 -0
  43. package/dist/formats/files/supportedFiles.js +17 -0
  44. package/dist/formats/files/translate.d.ts +14 -0
  45. package/dist/formats/files/translate.js +218 -0
  46. package/dist/formats/gt/save.d.ts +10 -0
  47. package/dist/formats/gt/save.js +34 -0
  48. package/dist/fs/config/loadConfig.d.ts +1 -0
  49. package/dist/fs/config/loadConfig.js +15 -0
  50. package/dist/fs/config/parseFilesConfig.d.ts +23 -0
  51. package/dist/fs/config/parseFilesConfig.js +128 -0
  52. package/dist/fs/config/setupConfig.d.ts +15 -0
  53. package/dist/fs/config/setupConfig.js +51 -0
  54. package/dist/fs/config/updateConfig.d.ts +11 -0
  55. package/dist/fs/config/updateConfig.js +41 -0
  56. package/dist/fs/determineFramework.d.ts +5 -0
  57. package/dist/fs/determineFramework.js +52 -0
  58. package/dist/fs/findFilepath.d.ts +36 -0
  59. package/dist/fs/findFilepath.js +101 -0
  60. package/dist/fs/findJsxFilepath.d.ts +7 -0
  61. package/dist/fs/findJsxFilepath.js +36 -0
  62. package/dist/fs/index.d.ts +1 -0
  63. package/dist/fs/index.js +2 -0
  64. package/dist/fs/loadJSON.d.ts +6 -0
  65. package/dist/fs/loadJSON.js +23 -0
  66. package/dist/fs/saveJSON.d.ts +1 -0
  67. package/dist/fs/saveJSON.js +13 -0
  68. package/dist/fs/utils.d.ts +1 -0
  69. package/dist/fs/utils.js +19 -0
  70. package/dist/hooks/postProcess.d.ts +4 -0
  71. package/dist/hooks/postProcess.js +118 -0
  72. package/dist/index.d.ts +3 -0
  73. package/dist/index.js +24 -0
  74. package/dist/main.d.ts +2 -0
  75. package/dist/main.js +12 -0
  76. package/dist/next/config/parseNextConfig.d.ts +10 -0
  77. package/dist/next/config/parseNextConfig.js +59 -0
  78. package/dist/next/jsx/utils.d.ts +7 -0
  79. package/dist/next/jsx/utils.js +82 -0
  80. package/dist/next/parse/handleInitGT.d.ts +1 -0
  81. package/dist/next/parse/handleInitGT.js +153 -0
  82. package/dist/next/parse/wrapContent.d.ts +11 -0
  83. package/dist/next/parse/wrapContent.js +181 -0
  84. package/dist/react/config/createESBuildConfig.d.ts +2 -0
  85. package/dist/react/config/createESBuildConfig.js +125 -0
  86. package/dist/react/data-_gt/addGTIdentifierToSyntaxTree.d.ts +1 -0
  87. package/dist/react/data-_gt/addGTIdentifierToSyntaxTree.js +87 -0
  88. package/dist/react/jsx/evaluateJsx.d.ts +17 -0
  89. package/dist/react/jsx/evaluateJsx.js +133 -0
  90. package/dist/react/jsx/parse/parseStringFunction.d.ts +12 -0
  91. package/dist/react/jsx/parse/parseStringFunction.js +118 -0
  92. package/dist/react/jsx/trimJsxStringChildren.d.ts +7 -0
  93. package/dist/react/jsx/trimJsxStringChildren.js +100 -0
  94. package/dist/react/jsx/utils/parseAst.d.ts +30 -0
  95. package/dist/react/jsx/utils/parseAst.js +319 -0
  96. package/dist/react/jsx/utils/parseJsx.d.ts +13 -0
  97. package/dist/react/jsx/utils/parseJsx.js +250 -0
  98. package/dist/react/jsx/utils/parseStringFunction.d.ts +12 -0
  99. package/dist/react/jsx/utils/parseStringFunction.js +121 -0
  100. package/dist/react/jsx/wrapJsx.d.ts +51 -0
  101. package/dist/react/jsx/wrapJsx.js +411 -0
  102. package/dist/react/parse/createDictionaryUpdates.d.ts +3 -0
  103. package/dist/react/parse/createDictionaryUpdates.js +78 -0
  104. package/dist/react/parse/createInlineUpdates.d.ts +5 -0
  105. package/dist/react/parse/createInlineUpdates.js +135 -0
  106. package/dist/react/parse/wrapContent.d.ts +11 -0
  107. package/dist/react/parse/wrapContent.js +197 -0
  108. package/dist/react/utils/flattenDictionary.d.ts +20 -0
  109. package/dist/react/utils/flattenDictionary.js +79 -0
  110. package/dist/react/utils/getEntryAndMetadata.d.ts +5 -0
  111. package/dist/react/utils/getEntryAndMetadata.js +14 -0
  112. package/dist/react/utils/getVariableName.d.ts +2 -0
  113. package/dist/react/utils/getVariableName.js +17 -0
  114. package/dist/setup/userInput.d.ts +4 -0
  115. package/dist/setup/userInput.js +35 -0
  116. package/dist/setup/wizard.d.ts +2 -0
  117. package/dist/setup/wizard.js +171 -0
  118. package/dist/translation/parse.d.ts +14 -0
  119. package/dist/translation/parse.js +82 -0
  120. package/dist/translation/stage.d.ts +5 -0
  121. package/dist/translation/stage.js +80 -0
  122. package/dist/translation/translate.d.ts +2 -0
  123. package/dist/translation/translate.js +21 -0
  124. package/dist/types/api.d.ts +6 -0
  125. package/dist/types/api.js +2 -0
  126. package/dist/types/data.d.ts +31 -0
  127. package/dist/types/data.js +2 -0
  128. package/dist/types/index.d.ts +101 -0
  129. package/dist/types/index.js +2 -0
  130. package/dist/utils/constants.d.ts +1 -0
  131. package/dist/utils/constants.js +4 -0
  132. package/dist/utils/credentials.d.ts +12 -0
  133. package/dist/utils/credentials.js +128 -0
  134. package/dist/utils/installPackage.d.ts +2 -0
  135. package/dist/utils/installPackage.js +45 -0
  136. package/dist/utils/packageJson.d.ts +5 -0
  137. package/dist/utils/packageJson.js +78 -0
  138. package/dist/utils/packageManager.d.ts +23 -0
  139. package/dist/utils/packageManager.js +261 -0
  140. package/package.json +5 -1
  141. package/.prettierrc +0 -15
  142. package/tsconfig.json +0 -16
@@ -0,0 +1,128 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.resolveLocaleFiles = resolveLocaleFiles;
7
+ exports.resolveFiles = resolveFiles;
8
+ const node_path_1 = __importDefault(require("node:path"));
9
+ const fast_glob_1 = __importDefault(require("fast-glob"));
10
+ const supportedFiles_1 = require("../../formats/files/supportedFiles");
11
+ const console_1 = require("../../console");
12
+ const chalk_1 = __importDefault(require("chalk"));
13
+ /**
14
+ * Resolves the files from the files object
15
+ * Replaces [locale] with the actual locale in the files
16
+ *
17
+ * @param files - The files object
18
+ * @param locale - The locale to replace [locale] with
19
+ * @returns The resolved files
20
+ */
21
+ function resolveLocaleFiles(files, locale) {
22
+ const result = {};
23
+ for (const fileType of supportedFiles_1.SUPPORTED_FILE_EXTENSIONS) {
24
+ result[fileType] = files[fileType]?.map((filepath) => filepath.replace(/\[locale\]/g, locale));
25
+ }
26
+ // Replace [locale] with locale in all paths
27
+ result.gt = files.gt?.replace(/\[locale\]/g, locale);
28
+ return result;
29
+ }
30
+ /**
31
+ * Resolves the files from the files object
32
+ * Performs glob pattern expansion on the files
33
+ * Replaces [locale] with the actual locale in the files
34
+ *
35
+ * @param files - The files object
36
+ * @returns The resolved files
37
+ */
38
+ function resolveFiles(files, locale) {
39
+ // Initialize result object with empty arrays for each file type
40
+ const result = {};
41
+ const placeholderResult = {};
42
+ const transformPaths = {};
43
+ // Process GT files
44
+ if (files.gt?.output) {
45
+ placeholderResult.gt = files.gt.output;
46
+ }
47
+ for (const fileType of supportedFiles_1.SUPPORTED_FILE_EXTENSIONS) {
48
+ // ==== TRANSFORMS ==== //
49
+ if (files[fileType]?.transform &&
50
+ !Array.isArray(files[fileType].transform)) {
51
+ transformPaths[fileType] = files[fileType].transform;
52
+ }
53
+ // ==== PLACEHOLDERS ==== //
54
+ if (files[fileType]?.include) {
55
+ const filePaths = expandGlobPatterns(files[fileType].include, files[fileType]?.exclude || [], locale, transformPaths[fileType] || undefined);
56
+ result[fileType] = filePaths.resolvedPaths;
57
+ placeholderResult[fileType] = filePaths.placeholderPaths;
58
+ }
59
+ }
60
+ return {
61
+ resolvedPaths: result,
62
+ placeholderPaths: placeholderResult,
63
+ transformPaths: transformPaths,
64
+ };
65
+ }
66
+ // Helper function to expand glob patterns
67
+ function expandGlobPatterns(includePatterns, excludePatterns, locale, transformPatterns) {
68
+ // Expand glob patterns to include all matching files
69
+ const resolvedPaths = [];
70
+ const placeholderPaths = [];
71
+ // Process include patterns
72
+ for (const pattern of includePatterns) {
73
+ // Track positions where [locale] appears in the original pattern
74
+ // It must be included in the pattern, otherwise the CLI tool will not be able to find the correct output path
75
+ // Warn if it's not included
76
+ if (!pattern.includes('[locale]') && !transformPatterns) {
77
+ (0, console_1.logWarning)(chalk_1.default.yellow(`Pattern "${pattern}" does not include [locale], so the CLI tool may incorrectly save translated files.`));
78
+ }
79
+ const localePositions = [];
80
+ let searchIndex = 0;
81
+ const localeTag = '[locale]';
82
+ while (true) {
83
+ const foundIndex = pattern.indexOf(localeTag, searchIndex);
84
+ if (foundIndex === -1)
85
+ break;
86
+ localePositions.push(foundIndex);
87
+ searchIndex = foundIndex + localeTag.length;
88
+ }
89
+ const expandedPattern = pattern.replace(/\[locale\]/g, locale);
90
+ // Resolve the absolute pattern path
91
+ const absolutePattern = node_path_1.default.resolve(process.cwd(), expandedPattern);
92
+ // Prepare exclude patterns with locale replaced
93
+ const expandedExcludePatterns = excludePatterns.map((p) => node_path_1.default.resolve(process.cwd(), p.replace(/\[locale\]/g, locale)));
94
+ // Use fast-glob to find all matching files, excluding the patterns
95
+ const matches = fast_glob_1.default.sync(absolutePattern, {
96
+ absolute: true,
97
+ ignore: expandedExcludePatterns,
98
+ });
99
+ resolvedPaths.push(...matches);
100
+ // For each match, create a version with [locale] in the correct positions
101
+ matches.forEach((match) => {
102
+ // Convert to relative path to make replacement easier
103
+ const relativePath = node_path_1.default.relative(process.cwd(), match);
104
+ let originalRelativePath = relativePath;
105
+ // Replace locale with [locale] at each tracked position
106
+ if (localePositions.length > 0) {
107
+ // We need to account for path resolution differences
108
+ // This is a simplified approach - we'll replace all instances of the locale
109
+ // but only in path segments where we expect it based on the original pattern
110
+ const pathParts = relativePath.split(node_path_1.default.sep);
111
+ const patternParts = pattern.split(/[\/\\]/); // Handle both slash types
112
+ for (let i = 0; i < pathParts.length; i++) {
113
+ if (i < patternParts.length) {
114
+ if (patternParts[i].includes(localeTag)) {
115
+ // This segment should have the locale replaced
116
+ pathParts[i] = pathParts[i].replace(locale, localeTag);
117
+ }
118
+ }
119
+ }
120
+ originalRelativePath = pathParts.join(node_path_1.default.sep);
121
+ }
122
+ // Convert back to absolute path
123
+ const originalPath = node_path_1.default.resolve(process.cwd(), originalRelativePath);
124
+ placeholderPaths.push(originalPath);
125
+ });
126
+ }
127
+ return { resolvedPaths, placeholderPaths };
128
+ }
@@ -0,0 +1,15 @@
1
+ import { FilesOptions, SupportedFrameworks } from '../../types';
2
+ /**
3
+ * Checks if the config file exists.
4
+ * If yes, make sure make sure projectId is correct
5
+ * If not, creates a new JSON file at the given filepath and writes the provided config object to it.
6
+ * @param {string} configFilepath - The path to the config file.
7
+ * @param {Record<string, any>} configObject - The config object to write if the file does not exist.
8
+ */
9
+ export default function createOrUpdateConfig(configFilepath: string, options: {
10
+ projectId?: string;
11
+ defaultLocale?: string;
12
+ locales?: string[];
13
+ files?: FilesOptions;
14
+ framework?: SupportedFrameworks;
15
+ }): Promise<string>;
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.default = createOrUpdateConfig;
7
+ const node_fs_1 = __importDefault(require("node:fs"));
8
+ const console_1 = require("../../console");
9
+ /**
10
+ * Checks if the config file exists.
11
+ * If yes, make sure make sure projectId is correct
12
+ * If not, creates a new JSON file at the given filepath and writes the provided config object to it.
13
+ * @param {string} configFilepath - The path to the config file.
14
+ * @param {Record<string, any>} configObject - The config object to write if the file does not exist.
15
+ */
16
+ async function createOrUpdateConfig(configFilepath, options) {
17
+ // Filter out empty string values from the config object
18
+ const newContent = {
19
+ ...(options.projectId && { projectId: options.projectId }),
20
+ ...(options.defaultLocale && { defaultLocale: options.defaultLocale }),
21
+ ...(options.files && { files: options.files }),
22
+ ...(options.framework && { framework: options.framework }),
23
+ };
24
+ try {
25
+ // if file exists
26
+ let oldContent = {};
27
+ if (node_fs_1.default.existsSync(configFilepath)) {
28
+ oldContent = JSON.parse(await node_fs_1.default.promises.readFile(configFilepath, 'utf-8'));
29
+ }
30
+ // merge old and new content
31
+ const mergedContent = {
32
+ ...oldContent,
33
+ ...newContent,
34
+ };
35
+ // Add locales to mergedContent if they exist
36
+ if (options.locales) {
37
+ mergedContent.locales = mergedContent.locales
38
+ ? [...new Set([...mergedContent.locales, ...options.locales])]
39
+ : options.locales;
40
+ }
41
+ // write to file
42
+ const mergedJsonContent = JSON.stringify(mergedContent, null, 2);
43
+ await node_fs_1.default.promises.writeFile(configFilepath, mergedJsonContent, 'utf-8');
44
+ // show update in console
45
+ (0, console_1.displayCreatedConfigFile)(configFilepath);
46
+ }
47
+ catch (error) {
48
+ (0, console_1.logError)(`An error occurred while updating ${configFilepath}: ${error}`);
49
+ }
50
+ return configFilepath;
51
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Update the config file version id, locales, and projectId (if necessary)
3
+ * @param {Record<string, any>} configObject - The config object to write if the file does not exist.
4
+ */
5
+ export default function updateConfig({ configFilepath, projectId, _versionId, locales, stageTranslations, }: {
6
+ configFilepath: string;
7
+ projectId?: string;
8
+ _versionId?: string;
9
+ locales?: string[];
10
+ stageTranslations?: boolean;
11
+ }): Promise<void>;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.default = updateConfig;
7
+ const node_fs_1 = __importDefault(require("node:fs"));
8
+ const console_1 = require("../../console/console");
9
+ /**
10
+ * Update the config file version id, locales, and projectId (if necessary)
11
+ * @param {Record<string, any>} configObject - The config object to write if the file does not exist.
12
+ */
13
+ async function updateConfig({ configFilepath, projectId, _versionId, locales, stageTranslations, }) {
14
+ // Filter out empty string values from the config object
15
+ const newContent = {
16
+ ...(projectId && { projectId }),
17
+ ...(_versionId && { _versionId }),
18
+ ...(stageTranslations && { stageTranslations }),
19
+ // ...(locales && { locales }), // Don't override locales
20
+ };
21
+ try {
22
+ // if file exists
23
+ let oldContent = {};
24
+ if (node_fs_1.default.existsSync(configFilepath)) {
25
+ oldContent = JSON.parse(await node_fs_1.default.promises.readFile(configFilepath, 'utf-8'));
26
+ }
27
+ // merge old and new content
28
+ const mergedContent = {
29
+ ...oldContent,
30
+ ...newContent,
31
+ };
32
+ // write to file
33
+ const mergedJsonContent = JSON.stringify(mergedContent, null, 2);
34
+ await node_fs_1.default.promises.writeFile(configFilepath, mergedJsonContent, 'utf-8');
35
+ // show update in console
36
+ (0, console_1.displayUpdatedConfigFile)(configFilepath);
37
+ }
38
+ catch (error) {
39
+ (0, console_1.logError)(`An error occurred while updating ${configFilepath}: ${error}`);
40
+ }
41
+ }
@@ -0,0 +1,5 @@
1
+ import { SupportedLibraries } from '../types';
2
+ export declare function determineLibrary(): {
3
+ library: SupportedLibraries;
4
+ additionalModules: SupportedLibraries[];
5
+ };
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.determineLibrary = determineLibrary;
7
+ const chalk_1 = __importDefault(require("chalk"));
8
+ const node_path_1 = __importDefault(require("node:path"));
9
+ const node_fs_1 = __importDefault(require("node:fs"));
10
+ const console_1 = require("../console");
11
+ function determineLibrary() {
12
+ let library = 'base';
13
+ let additionalModules = [];
14
+ try {
15
+ // Get the current working directory (where the CLI is being run)
16
+ const cwd = process.cwd();
17
+ const packageJsonPath = node_path_1.default.join(cwd, 'package.json');
18
+ // Check if package.json exists
19
+ if (!node_fs_1.default.existsSync(packageJsonPath)) {
20
+ (0, console_1.logError)(chalk_1.default.red('No package.json found in the current directory. Please run this command from the root of your project.'));
21
+ return { library: 'base', additionalModules: [] };
22
+ }
23
+ // Read and parse package.json
24
+ const packageJson = JSON.parse(node_fs_1.default.readFileSync(packageJsonPath, 'utf8'));
25
+ const dependencies = {
26
+ ...packageJson.dependencies,
27
+ ...packageJson.devDependencies,
28
+ };
29
+ // Check for gt-next or gt-react in dependencies
30
+ if (dependencies['gt-next']) {
31
+ library = 'gt-next';
32
+ }
33
+ else if (dependencies['gt-react']) {
34
+ library = 'gt-react';
35
+ }
36
+ else if (dependencies['next-intl']) {
37
+ library = 'next-intl';
38
+ }
39
+ else if (dependencies['i18next']) {
40
+ library = 'i18next';
41
+ }
42
+ if (dependencies['i18next-icu']) {
43
+ additionalModules.push('i18next-icu');
44
+ }
45
+ // Fallback to base if neither is found
46
+ return { library, additionalModules };
47
+ }
48
+ catch (error) {
49
+ (0, console_1.logError)('Error determining framework: ' + String(error));
50
+ return { library: 'base', additionalModules: [] };
51
+ }
52
+ }
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Resolve the file path from the given file path or default paths.
3
+ * @param {string} filePath - The file path to resolve.
4
+ * @param {string[]} defaultPaths - The default paths to check.
5
+ * @returns {string} - The resolved file path.
6
+ */
7
+ export default function findFilepath(paths: string[], errorMessage?: string): string;
8
+ /**
9
+ * Resolve the file paths from the given file paths or default paths.
10
+ * @param {string[]} paths - The file paths to resolve.
11
+ * @param {string} errorMessage - The error message to throw if no paths are found.
12
+ * @returns {string[]} - The resolved file paths.
13
+ */
14
+ export declare function findFilepaths(paths: string[], errorMessage?: string): string[];
15
+ export declare function getRelativePath(file: string, srcDirectory: string): string;
16
+ /**
17
+ * Find a file in a directory based on a wildcard pattern.
18
+ * @param {string} filePattern - The wildcard pattern to search for.
19
+ * @param {string} file - The file to search for.
20
+ * @returns {string} - The path to the file.
21
+ */
22
+ export declare function findFile(filePattern: string, file: string): string;
23
+ /**
24
+ * Read a file and return the contents.
25
+ * @param {string} filePath - The path to the file to read.
26
+ * @returns {string} - The contents of the file.
27
+ */
28
+ export declare function readFile(filePath: string): string;
29
+ /**
30
+ * Find a file in a directory.
31
+ * @param {string} dir - The directory to search in.
32
+ * @param {string} file - The file to search for.
33
+ * @returns {string} - The path to the file.
34
+ */
35
+ export declare function findFileInDir(dir: string, file: string): string;
36
+ export declare function getRelative(absolutePath: string): string;
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.default = findFilepath;
7
+ exports.findFilepaths = findFilepaths;
8
+ exports.getRelativePath = getRelativePath;
9
+ exports.findFile = findFile;
10
+ exports.readFile = readFile;
11
+ exports.findFileInDir = findFileInDir;
12
+ exports.getRelative = getRelative;
13
+ const node_fs_1 = __importDefault(require("node:fs"));
14
+ const node_path_1 = __importDefault(require("node:path"));
15
+ const console_1 = require("../console");
16
+ /**
17
+ * Resolve the file path from the given file path or default paths.
18
+ * @param {string} filePath - The file path to resolve.
19
+ * @param {string[]} defaultPaths - The default paths to check.
20
+ * @returns {string} - The resolved file path.
21
+ */
22
+ function findFilepath(paths, errorMessage = '') {
23
+ return findFilepaths(paths, errorMessage)?.[0] || '';
24
+ }
25
+ /**
26
+ * Resolve the file paths from the given file paths or default paths.
27
+ * @param {string[]} paths - The file paths to resolve.
28
+ * @param {string} errorMessage - The error message to throw if no paths are found.
29
+ * @returns {string[]} - The resolved file paths.
30
+ */
31
+ function findFilepaths(paths, errorMessage = '') {
32
+ const resolvedPaths = [];
33
+ for (const possiblePath of paths) {
34
+ if (node_fs_1.default.existsSync(possiblePath)) {
35
+ resolvedPaths.push(possiblePath);
36
+ }
37
+ }
38
+ if (errorMessage) {
39
+ (0, console_1.logError)(errorMessage);
40
+ process.exit(1);
41
+ }
42
+ return resolvedPaths;
43
+ }
44
+ function getRelativePath(file, srcDirectory) {
45
+ // Create relative path from src directory and remove extension
46
+ return node_path_1.default
47
+ .relative(srcDirectory, file.replace(/\.[^/.]+$/, '') // Remove file extension
48
+ )
49
+ .replace(/\\/g, '.') // Replace Windows backslashes with dots
50
+ .split(/[./]/) // Split on dots or forward slashes
51
+ .filter(Boolean) // Remove empty segments that might cause extra dots
52
+ .map((segment) => segment.replace(/[^a-zA-Z0-9]/g, '_').toLowerCase()) // Convert each segment to snake case
53
+ .join('.'); // Rejoin with dots
54
+ }
55
+ /**
56
+ * Find a file in a directory based on a wildcard pattern.
57
+ * @param {string} filePattern - The wildcard pattern to search for.
58
+ * @param {string} file - The file to search for.
59
+ * @returns {string} - The path to the file.
60
+ */
61
+ function findFile(filePattern, file) {
62
+ // Handle wildcard pattern by replacing the wildcard with the file parameter
63
+ const resolvedPath = filePattern.replace(/\*/, file);
64
+ if (node_fs_1.default.existsSync(resolvedPath) && node_fs_1.default.statSync(resolvedPath).isFile()) {
65
+ return node_fs_1.default.readFileSync(resolvedPath, 'utf8');
66
+ }
67
+ return '';
68
+ }
69
+ /**
70
+ * Read a file and return the contents.
71
+ * @param {string} filePath - The path to the file to read.
72
+ * @returns {string} - The contents of the file.
73
+ */
74
+ function readFile(filePath) {
75
+ if (node_fs_1.default.existsSync(filePath) && node_fs_1.default.statSync(filePath).isFile()) {
76
+ return node_fs_1.default.readFileSync(filePath, 'utf8');
77
+ }
78
+ return '';
79
+ }
80
+ /**
81
+ * Find a file in a directory.
82
+ * @param {string} dir - The directory to search in.
83
+ * @param {string} file - The file to search for.
84
+ * @returns {string} - The path to the file.
85
+ */
86
+ function findFileInDir(dir, file) {
87
+ const resolvedPath = node_path_1.default.join(dir, file);
88
+ try {
89
+ if (node_fs_1.default.existsSync(resolvedPath)) {
90
+ return node_fs_1.default.readFileSync(resolvedPath, 'utf8');
91
+ }
92
+ }
93
+ catch (error) {
94
+ (0, console_1.logError)('Error finding file in directory: ' + String(error));
95
+ }
96
+ return '';
97
+ }
98
+ function getRelative(absolutePath) {
99
+ const path2 = node_path_1.default.resolve(absolutePath);
100
+ return node_path_1.default.relative(process.cwd(), path2);
101
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Recursively scan the directory and collect all files with the specified extensions,
3
+ * excluding files or directories that start with a dot (.)
4
+ * @param dir - The directory to scan
5
+ * @returns An array of file paths
6
+ */
7
+ export declare function getFiles(dir: string): string[];
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getFiles = getFiles;
7
+ const node_fs_1 = __importDefault(require("node:fs"));
8
+ const node_path_1 = __importDefault(require("node:path"));
9
+ // Define the file extensions to look for
10
+ const extensions = ['.js', '.jsx', '.tsx'];
11
+ /**
12
+ * Recursively scan the directory and collect all files with the specified extensions,
13
+ * excluding files or directories that start with a dot (.)
14
+ * @param dir - The directory to scan
15
+ * @returns An array of file paths
16
+ */
17
+ function getFiles(dir) {
18
+ let files = [];
19
+ const items = node_fs_1.default.readdirSync(dir);
20
+ for (const item of items) {
21
+ // Skip hidden files and directories
22
+ if (item.startsWith('.'))
23
+ continue;
24
+ const fullPath = node_path_1.default.join(dir, item);
25
+ const stat = node_fs_1.default.statSync(fullPath);
26
+ if (stat.isDirectory()) {
27
+ // Recursively scan subdirectories
28
+ files = files.concat(getFiles(fullPath));
29
+ }
30
+ else if (extensions.includes(node_path_1.default.extname(item))) {
31
+ // Add files with the specified extensions
32
+ files.push(fullPath);
33
+ }
34
+ }
35
+ return files;
36
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Loads a JSON file from a given filepath, returning null if the file is not found or the JSON doesn't parse.
3
+ * @param {string} filepath - The path to the JSON file.
4
+ * @returns {Record<string, any> | null} - The parsed JSON object or null if an error occurs.
5
+ */
6
+ export default function loadJSON(filepath: string): Record<string, any> | null;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.default = loadJSON;
7
+ const node_fs_1 = __importDefault(require("node:fs"));
8
+ const node_path_1 = __importDefault(require("node:path"));
9
+ /**
10
+ * Loads a JSON file from a given filepath, returning null if the file is not found or the JSON doesn't parse.
11
+ * @param {string} filepath - The path to the JSON file.
12
+ * @returns {Record<string, any> | null} - The parsed JSON object or null if an error occurs.
13
+ */
14
+ function loadJSON(filepath) {
15
+ try {
16
+ const data = node_fs_1.default.readFileSync(node_path_1.default.resolve(filepath), 'utf-8');
17
+ return JSON.parse(data);
18
+ }
19
+ catch (error) {
20
+ // Return null if the file is not found or JSON parsing fails
21
+ return null;
22
+ }
23
+ }
@@ -0,0 +1 @@
1
+ export declare function saveJSON(filepath: string, data: Record<string, any>): Promise<void>;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.saveJSON = saveJSON;
7
+ const node_path_1 = __importDefault(require("node:path"));
8
+ const node_fs_1 = __importDefault(require("node:fs"));
9
+ async function saveJSON(filepath, data) {
10
+ // Ensure directory exists
11
+ await node_fs_1.default.promises.mkdir(node_path_1.default.dirname(filepath), { recursive: true });
12
+ await node_fs_1.default.promises.writeFile(filepath, JSON.stringify(data, null, 2));
13
+ }
@@ -0,0 +1 @@
1
+ export declare function resolveProjectId(): string | undefined;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveProjectId = resolveProjectId;
4
+ function resolveProjectId() {
5
+ const CANDIDATES = [
6
+ process.env.GT_PROJECT_ID, // any server side, Remix
7
+ process.env.NEXT_PUBLIC_GT_PROJECT_ID, // Next.js
8
+ process.env.VITE_GT_PROJECT_ID, // Vite
9
+ process.env.REACT_APP_GT_PROJECT_ID, // Create React App
10
+ process.env.REDWOOD_ENV_GT_PROJECT_ID, // RedwoodJS
11
+ process.env.GATSBY_GT_PROJECT_ID, // Gatsby
12
+ process.env.EXPO_PUBLIC_GT_PROJECT_ID, // Expo (React Native)
13
+ process.env.RAZZLE_GT_PROJECT_ID, // Razzle
14
+ process.env.UMI_GT_PROJECT_ID, // UmiJS
15
+ process.env.BLITZ_PUBLIC_GT_PROJECT_ID, // Blitz.js
16
+ process.env.PUBLIC_GT_PROJECT_ID, // WMR, Qwik (general "public" convention)
17
+ ];
18
+ return CANDIDATES.find((projectId) => projectId !== undefined);
19
+ }
@@ -0,0 +1,4 @@
1
+ type Formatter = 'prettier' | 'biome' | 'eslint';
2
+ export declare function detectFormatter(): Promise<Formatter | null>;
3
+ export declare function formatFiles(filesUpdated: string[], formatter?: Formatter): Promise<void>;
4
+ export {};