gtx-cli 2.3.6-alpha.2 → 2.3.6

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 (192) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/api/checkFileTranslations.d.ts +23 -0
  3. package/dist/api/checkFileTranslations.js +236 -0
  4. package/dist/api/downloadFileBatch.d.ts +20 -0
  5. package/dist/api/downloadFileBatch.js +113 -0
  6. package/dist/api/sendFiles.d.ts +17 -0
  7. package/dist/api/sendFiles.js +115 -0
  8. package/dist/api/uploadFiles.d.ts +27 -0
  9. package/dist/api/uploadFiles.js +40 -0
  10. package/dist/cli/base.d.ts +32 -0
  11. package/dist/cli/base.js +335 -0
  12. package/dist/cli/commands/stage.d.ts +5 -0
  13. package/dist/cli/commands/stage.js +100 -0
  14. package/dist/cli/commands/translate.d.ts +6 -0
  15. package/dist/cli/commands/translate.js +63 -0
  16. package/dist/cli/flags.d.ts +3 -0
  17. package/dist/cli/flags.js +38 -0
  18. package/dist/cli/next.d.ts +11 -0
  19. package/dist/cli/next.js +20 -0
  20. package/dist/cli/react.d.ts +18 -0
  21. package/dist/cli/react.js +175 -0
  22. package/dist/config/generateSettings.d.ts +9 -0
  23. package/dist/config/generateSettings.js +176 -0
  24. package/dist/config/optionPresets.d.ts +2 -0
  25. package/dist/config/optionPresets.js +56 -0
  26. package/dist/config/resolveConfig.d.ts +4 -0
  27. package/dist/config/resolveConfig.js +19 -0
  28. package/dist/config/utils.d.ts +2 -0
  29. package/dist/config/utils.js +4 -0
  30. package/dist/config/validateSettings.d.ts +3 -0
  31. package/dist/config/validateSettings.js +32 -0
  32. package/dist/console/colors.d.ts +5 -0
  33. package/dist/console/colors.js +16 -0
  34. package/dist/console/index.d.ts +21 -0
  35. package/dist/console/index.js +24 -0
  36. package/dist/console/logging.d.ts +53 -0
  37. package/dist/console/logging.js +185 -0
  38. package/dist/formats/files/fileMapping.d.ts +11 -0
  39. package/dist/formats/files/fileMapping.js +82 -0
  40. package/dist/formats/files/save.d.ts +5 -0
  41. package/dist/formats/files/save.js +17 -0
  42. package/dist/formats/files/supportedFiles.d.ts +10 -0
  43. package/dist/formats/files/supportedFiles.js +18 -0
  44. package/dist/formats/files/translate.d.ts +4 -0
  45. package/dist/formats/files/translate.js +119 -0
  46. package/dist/formats/files/upload.d.ts +13 -0
  47. package/dist/formats/files/upload.js +136 -0
  48. package/dist/formats/gt/save.d.ts +9 -0
  49. package/dist/formats/gt/save.js +26 -0
  50. package/dist/formats/json/flattenJson.d.ts +14 -0
  51. package/dist/formats/json/flattenJson.js +64 -0
  52. package/dist/formats/json/mergeJson.d.ts +13 -0
  53. package/dist/formats/json/mergeJson.js +257 -0
  54. package/dist/formats/json/parseJson.d.ts +2 -0
  55. package/dist/formats/json/parseJson.js +108 -0
  56. package/dist/formats/json/utils.d.ts +47 -0
  57. package/dist/formats/json/utils.js +149 -0
  58. package/dist/formats/utils.d.ts +2 -0
  59. package/dist/formats/utils.js +24 -0
  60. package/dist/formats/yaml/mergeYaml.d.ts +5 -0
  61. package/dist/formats/yaml/mergeYaml.js +55 -0
  62. package/dist/formats/yaml/parseYaml.d.ts +5 -0
  63. package/dist/formats/yaml/parseYaml.js +23 -0
  64. package/dist/formats/yaml/utils.d.ts +2 -0
  65. package/dist/formats/yaml/utils.js +22 -0
  66. package/dist/fs/config/loadConfig.d.ts +1 -0
  67. package/dist/fs/config/loadConfig.js +9 -0
  68. package/dist/fs/config/parseFilesConfig.d.ts +27 -0
  69. package/dist/fs/config/parseFilesConfig.js +129 -0
  70. package/dist/fs/config/setupConfig.d.ts +17 -0
  71. package/dist/fs/config/setupConfig.js +50 -0
  72. package/dist/fs/config/updateConfig.d.ts +10 -0
  73. package/dist/fs/config/updateConfig.js +36 -0
  74. package/dist/fs/config/updateVersions.d.ts +10 -0
  75. package/dist/fs/config/updateVersions.js +30 -0
  76. package/dist/fs/copyFile.d.ts +7 -0
  77. package/dist/fs/copyFile.js +39 -0
  78. package/dist/fs/createLoadTranslationsFile.d.ts +1 -0
  79. package/dist/fs/createLoadTranslationsFile.js +36 -0
  80. package/dist/fs/determineFramework.d.ts +5 -0
  81. package/dist/fs/determineFramework.js +46 -0
  82. package/dist/fs/findFilepath.d.ts +36 -0
  83. package/dist/fs/findFilepath.js +89 -0
  84. package/dist/fs/getPackageResource.d.ts +1 -0
  85. package/dist/fs/getPackageResource.js +6 -0
  86. package/dist/fs/index.d.ts +1 -0
  87. package/dist/fs/index.js +1 -0
  88. package/dist/fs/loadJSON.d.ts +6 -0
  89. package/dist/fs/loadJSON.js +17 -0
  90. package/dist/fs/matchFiles.d.ts +1 -0
  91. package/dist/fs/matchFiles.js +8 -0
  92. package/dist/fs/saveJSON.d.ts +1 -0
  93. package/dist/fs/saveJSON.js +7 -0
  94. package/dist/fs/utils.d.ts +1 -0
  95. package/dist/fs/utils.js +16 -0
  96. package/dist/hooks/postProcess.d.ts +4 -0
  97. package/dist/hooks/postProcess.js +110 -0
  98. package/dist/index.d.ts +4 -0
  99. package/dist/index.js +20 -0
  100. package/dist/main.d.ts +2 -0
  101. package/dist/main.js +9 -0
  102. package/dist/next/config/parseNextConfig.d.ts +10 -0
  103. package/dist/next/config/parseNextConfig.js +53 -0
  104. package/dist/next/jsx/utils.d.ts +7 -0
  105. package/dist/next/jsx/utils.js +42 -0
  106. package/dist/next/parse/handleInitGT.d.ts +7 -0
  107. package/dist/next/parse/handleInitGT.js +208 -0
  108. package/dist/next/parse/wrapContent.d.ts +11 -0
  109. package/dist/next/parse/wrapContent.js +163 -0
  110. package/dist/react/config/createESBuildConfig.d.ts +2 -0
  111. package/dist/react/config/createESBuildConfig.js +119 -0
  112. package/dist/react/data-_gt/addGTIdentifierToSyntaxTree.d.ts +8 -0
  113. package/dist/react/data-_gt/addGTIdentifierToSyntaxTree.js +111 -0
  114. package/dist/react/jsx/evaluateJsx.d.ts +17 -0
  115. package/dist/react/jsx/evaluateJsx.js +85 -0
  116. package/dist/react/jsx/trimJsxStringChildren.d.ts +7 -0
  117. package/dist/react/jsx/trimJsxStringChildren.js +95 -0
  118. package/dist/react/jsx/utils/constants.d.ts +10 -0
  119. package/dist/react/jsx/utils/constants.js +31 -0
  120. package/dist/react/jsx/utils/parseAst.d.ts +30 -0
  121. package/dist/react/jsx/utils/parseAst.js +277 -0
  122. package/dist/react/jsx/utils/parseJsx.d.ts +21 -0
  123. package/dist/react/jsx/utils/parseJsx.js +244 -0
  124. package/dist/react/jsx/utils/parseStringFunction.d.ts +16 -0
  125. package/dist/react/jsx/utils/parseStringFunction.js +411 -0
  126. package/dist/react/jsx/utils/validateStringFunction.d.ts +7 -0
  127. package/dist/react/jsx/utils/validateStringFunction.js +31 -0
  128. package/dist/react/jsx/wrapJsx.d.ts +51 -0
  129. package/dist/react/jsx/wrapJsx.js +387 -0
  130. package/dist/react/parse/createDictionaryUpdates.d.ts +3 -0
  131. package/dist/react/parse/createDictionaryUpdates.js +169 -0
  132. package/dist/react/parse/createInlineUpdates.d.ts +6 -0
  133. package/dist/react/parse/createInlineUpdates.js +122 -0
  134. package/dist/react/parse/wrapContent.d.ts +11 -0
  135. package/dist/react/parse/wrapContent.js +162 -0
  136. package/dist/react/utils/flattenDictionary.d.ts +20 -0
  137. package/dist/react/utils/flattenDictionary.js +75 -0
  138. package/dist/react/utils/getEntryAndMetadata.d.ts +5 -0
  139. package/dist/react/utils/getEntryAndMetadata.js +11 -0
  140. package/dist/react/utils/getVariableName.d.ts +25 -0
  141. package/dist/react/utils/getVariableName.js +37 -0
  142. package/dist/setup/userInput.d.ts +4 -0
  143. package/dist/setup/userInput.js +29 -0
  144. package/dist/setup/wizard.d.ts +2 -0
  145. package/dist/setup/wizard.js +127 -0
  146. package/dist/translation/parse.d.ts +15 -0
  147. package/dist/translation/parse.js +76 -0
  148. package/dist/translation/stage.d.ts +2 -0
  149. package/dist/translation/stage.js +44 -0
  150. package/dist/translation/validate.d.ts +2 -0
  151. package/dist/translation/validate.js +50 -0
  152. package/dist/types/data/json.d.ts +6 -0
  153. package/dist/types/data/json.js +1 -0
  154. package/dist/types/data.d.ts +30 -0
  155. package/dist/types/data.js +1 -0
  156. package/dist/types/files.d.ts +1 -0
  157. package/dist/types/files.js +1 -0
  158. package/dist/types/index.d.ts +173 -0
  159. package/dist/types/index.js +1 -0
  160. package/dist/utils/addExplicitAnchorIds.d.ts +24 -0
  161. package/dist/utils/addExplicitAnchorIds.js +260 -0
  162. package/dist/utils/constants.d.ts +2 -0
  163. package/dist/utils/constants.js +2 -0
  164. package/dist/utils/credentials.d.ts +12 -0
  165. package/dist/utils/credentials.js +119 -0
  166. package/dist/utils/flattenJsonFiles.d.ts +2 -0
  167. package/dist/utils/flattenJsonFiles.js +36 -0
  168. package/dist/utils/gt.d.ts +2 -0
  169. package/dist/utils/gt.js +2 -0
  170. package/dist/utils/hash.d.ts +6 -0
  171. package/dist/utils/hash.js +11 -0
  172. package/dist/utils/headers.d.ts +1 -0
  173. package/dist/utils/headers.js +14 -0
  174. package/dist/utils/installPackage.d.ts +3 -0
  175. package/dist/utils/installPackage.js +77 -0
  176. package/dist/utils/localizeStaticImports.d.ts +15 -0
  177. package/dist/utils/localizeStaticImports.js +341 -0
  178. package/dist/utils/localizeStaticUrls.d.ts +19 -0
  179. package/dist/utils/localizeStaticUrls.js +432 -0
  180. package/dist/utils/packageInfo.d.ts +3 -0
  181. package/dist/utils/packageInfo.js +17 -0
  182. package/dist/utils/packageJson.d.ts +6 -0
  183. package/dist/utils/packageJson.js +76 -0
  184. package/dist/utils/packageManager.d.ts +28 -0
  185. package/dist/utils/packageManager.js +269 -0
  186. package/dist/utils/processAnchorIds.d.ts +6 -0
  187. package/dist/utils/processAnchorIds.js +47 -0
  188. package/dist/utils/sanitizeFileContent.d.ts +6 -0
  189. package/dist/utils/sanitizeFileContent.js +29 -0
  190. package/dist/utils/validateMdx.d.ts +10 -0
  191. package/dist/utils/validateMdx.js +25 -0
  192. package/package.json +3 -3
@@ -0,0 +1,89 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { logError } from '../console/logging.js';
4
+ /**
5
+ * Resolve the file path from the given file path or default paths.
6
+ * @param {string} filePath - The file path to resolve.
7
+ * @param {string[]} defaultPaths - The default paths to check.
8
+ * @returns {string} - The resolved file path.
9
+ */
10
+ export default function findFilepath(paths, errorMessage = '') {
11
+ return findFilepaths(paths, errorMessage)?.[0] || '';
12
+ }
13
+ /**
14
+ * Resolve the file paths from the given file paths or default paths.
15
+ * @param {string[]} paths - The file paths to resolve.
16
+ * @param {string} errorMessage - The error message to throw if no paths are found.
17
+ * @returns {string[]} - The resolved file paths.
18
+ */
19
+ export function findFilepaths(paths, errorMessage = '') {
20
+ const resolvedPaths = [];
21
+ for (const possiblePath of paths) {
22
+ if (fs.existsSync(possiblePath)) {
23
+ resolvedPaths.push(possiblePath);
24
+ }
25
+ }
26
+ if (errorMessage) {
27
+ logError(errorMessage);
28
+ process.exit(1);
29
+ }
30
+ return resolvedPaths;
31
+ }
32
+ export function getRelativePath(file, srcDirectory) {
33
+ // Create relative path from src directory and remove extension
34
+ return path
35
+ .relative(srcDirectory, file.replace(/\.[^/.]+$/, '') // Remove file extension
36
+ )
37
+ .replace(/\\/g, '.') // Replace Windows backslashes with dots
38
+ .split(/[./]/) // Split on dots or forward slashes
39
+ .filter(Boolean) // Remove empty segments that might cause extra dots
40
+ .map((segment) => segment.replace(/[^a-zA-Z0-9]/g, '_').toLowerCase()) // Convert each segment to snake case
41
+ .join('.'); // Rejoin with dots
42
+ }
43
+ /**
44
+ * Find a file in a directory based on a wildcard pattern.
45
+ * @param {string} filePattern - The wildcard pattern to search for.
46
+ * @param {string} file - The file to search for.
47
+ * @returns {string} - The path to the file.
48
+ */
49
+ export function findFile(filePattern, file) {
50
+ // Handle wildcard pattern by replacing the wildcard with the file parameter
51
+ const resolvedPath = filePattern.replace(/\*/, file);
52
+ if (fs.existsSync(resolvedPath) && fs.statSync(resolvedPath).isFile()) {
53
+ return fs.readFileSync(resolvedPath, 'utf8');
54
+ }
55
+ return '';
56
+ }
57
+ /**
58
+ * Read a file and return the contents.
59
+ * @param {string} filePath - The path to the file to read.
60
+ * @returns {string} - The contents of the file.
61
+ */
62
+ export function readFile(filePath) {
63
+ if (fs.existsSync(filePath) && fs.statSync(filePath).isFile()) {
64
+ return fs.readFileSync(filePath, 'utf8');
65
+ }
66
+ return '';
67
+ }
68
+ /**
69
+ * Find a file in a directory.
70
+ * @param {string} dir - The directory to search in.
71
+ * @param {string} file - The file to search for.
72
+ * @returns {string} - The path to the file.
73
+ */
74
+ export function findFileInDir(dir, file) {
75
+ const resolvedPath = path.join(dir, file);
76
+ try {
77
+ if (fs.existsSync(resolvedPath)) {
78
+ return fs.readFileSync(resolvedPath, 'utf8');
79
+ }
80
+ }
81
+ catch (error) {
82
+ logError('Error finding file in directory: ' + String(error));
83
+ }
84
+ return '';
85
+ }
86
+ export function getRelative(absolutePath) {
87
+ const path2 = path.resolve(absolutePath);
88
+ return path.relative(process.cwd(), path2);
89
+ }
@@ -0,0 +1 @@
1
+ export declare function fromPackageRoot(relative: string): string;
@@ -0,0 +1,6 @@
1
+ import path from 'node:path';
2
+ import { fileURLToPath } from 'node:url';
3
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
4
+ export function fromPackageRoot(relative) {
5
+ return path.resolve(__dirname, `../../`, relative);
6
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -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,17 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ /**
4
+ * Loads a JSON file from a given filepath, returning null if the file is not found or the JSON doesn't parse.
5
+ * @param {string} filepath - The path to the JSON file.
6
+ * @returns {Record<string, any> | null} - The parsed JSON object or null if an error occurs.
7
+ */
8
+ export default function loadJSON(filepath) {
9
+ try {
10
+ const data = fs.readFileSync(path.resolve(filepath), 'utf-8');
11
+ return JSON.parse(data);
12
+ }
13
+ catch (error) {
14
+ // Return null if the file is not found or JSON parsing fails
15
+ return null;
16
+ }
17
+ }
@@ -0,0 +1 @@
1
+ export declare function matchFiles(cwd: string, patterns: string[]): string[];
@@ -0,0 +1,8 @@
1
+ import fg from 'fast-glob';
2
+ export function matchFiles(cwd, patterns) {
3
+ return fg.sync(patterns, {
4
+ cwd,
5
+ absolute: true,
6
+ onlyFiles: true,
7
+ });
8
+ }
@@ -0,0 +1 @@
1
+ export declare function saveJSON(filepath: string, data: Record<string, any>): Promise<void>;
@@ -0,0 +1,7 @@
1
+ import path from 'node:path';
2
+ import fs from 'node:fs';
3
+ export async function saveJSON(filepath, data) {
4
+ // Ensure directory exists
5
+ await fs.promises.mkdir(path.dirname(filepath), { recursive: true });
6
+ await fs.promises.writeFile(filepath, JSON.stringify(data, null, 2));
7
+ }
@@ -0,0 +1 @@
1
+ export declare function resolveProjectId(): string | undefined;
@@ -0,0 +1,16 @@
1
+ export function resolveProjectId() {
2
+ const CANDIDATES = [
3
+ process.env.GT_PROJECT_ID, // any server side, Remix
4
+ process.env.NEXT_PUBLIC_GT_PROJECT_ID, // Next.js
5
+ process.env.VITE_GT_PROJECT_ID, // Vite
6
+ process.env.REACT_APP_GT_PROJECT_ID, // Create React App
7
+ process.env.REDWOOD_ENV_GT_PROJECT_ID, // RedwoodJS
8
+ process.env.GATSBY_GT_PROJECT_ID, // Gatsby
9
+ process.env.EXPO_PUBLIC_GT_PROJECT_ID, // Expo (React Native)
10
+ process.env.RAZZLE_GT_PROJECT_ID, // Razzle
11
+ process.env.UMI_GT_PROJECT_ID, // UmiJS
12
+ process.env.BLITZ_PUBLIC_GT_PROJECT_ID, // Blitz.js
13
+ process.env.PUBLIC_GT_PROJECT_ID, // WMR, Qwik (general "public" convention)
14
+ ];
15
+ return CANDIDATES.find((projectId) => projectId !== undefined);
16
+ }
@@ -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 {};
@@ -0,0 +1,110 @@
1
+ import fs from 'node:fs';
2
+ import { spawn } from 'node:child_process';
3
+ import chalk from 'chalk';
4
+ import { logMessage, logWarning } from '../console/logging.js';
5
+ export async function detectFormatter() {
6
+ // Try Prettier
7
+ try {
8
+ await import('prettier');
9
+ return 'prettier';
10
+ }
11
+ catch { }
12
+ // Try ESLint
13
+ try {
14
+ await import('eslint');
15
+ return 'eslint';
16
+ }
17
+ catch { }
18
+ // Try Biome
19
+ try {
20
+ return await new Promise((resolve, reject) => {
21
+ const child = spawn('npx', ['@biomejs/biome', '--version'], {
22
+ stdio: 'ignore',
23
+ });
24
+ child.on('error', () => {
25
+ resolve(null);
26
+ });
27
+ child.on('close', (code) => {
28
+ if (code === 0) {
29
+ resolve('biome');
30
+ }
31
+ else {
32
+ resolve(null);
33
+ }
34
+ });
35
+ });
36
+ }
37
+ catch { }
38
+ return null;
39
+ }
40
+ export async function formatFiles(filesUpdated, formatter) {
41
+ if (filesUpdated.length === 0)
42
+ return;
43
+ try {
44
+ const detectedFormatter = formatter || (await detectFormatter());
45
+ if (!detectedFormatter) {
46
+ logWarning(chalk.yellow('No supported formatter detected'));
47
+ return;
48
+ }
49
+ if (detectedFormatter === 'prettier') {
50
+ logMessage(chalk.dim('Cleaning up with prettier...'));
51
+ const prettier = await import('prettier');
52
+ for (const file of filesUpdated) {
53
+ const config = await prettier.resolveConfig(file);
54
+ const content = await fs.promises.readFile(file, 'utf-8');
55
+ const formatted = await prettier.format(content, {
56
+ ...config,
57
+ filepath: file,
58
+ });
59
+ await fs.promises.writeFile(file, formatted);
60
+ }
61
+ return;
62
+ }
63
+ if (detectedFormatter === 'biome') {
64
+ logMessage(chalk.dim('Cleaning up with biome...'));
65
+ try {
66
+ await new Promise((resolve, reject) => {
67
+ const args = [
68
+ '@biomejs/biome',
69
+ 'format',
70
+ '--write',
71
+ ...filesUpdated.map((file) => file),
72
+ ];
73
+ const child = spawn('npx', args, {
74
+ stdio: ['ignore', 'inherit', 'inherit'],
75
+ });
76
+ child.on('error', (error) => {
77
+ logWarning(chalk.yellow('Biome formatting failed: ' + error.message));
78
+ resolve();
79
+ });
80
+ child.on('close', (code) => {
81
+ if (code !== 0) {
82
+ logWarning(chalk.yellow(`Biome formatting failed with exit code ${code}`));
83
+ }
84
+ resolve();
85
+ });
86
+ });
87
+ }
88
+ catch (error) {
89
+ logWarning(chalk.yellow('Biome formatting failed: ' + String(error)));
90
+ }
91
+ return;
92
+ }
93
+ if (detectedFormatter === 'eslint') {
94
+ logMessage(chalk.dim('Cleaning up with eslint...'));
95
+ const { ESLint } = await import('eslint');
96
+ const eslint = new ESLint({
97
+ fix: true,
98
+ overrideConfigFile: undefined, // Will use project's .eslintrc
99
+ });
100
+ for (const file of filesUpdated) {
101
+ const results = await eslint.lintFiles([file]);
102
+ await ESLint.outputFixes(results);
103
+ }
104
+ return;
105
+ }
106
+ }
107
+ catch (e) {
108
+ logWarning(chalk.yellow('Unable to run code formatter: ' + String(e)));
109
+ }
110
+ }
@@ -0,0 +1,4 @@
1
+ import { BaseCLI } from './cli/base.js';
2
+ import { Command } from 'commander';
3
+ export declare function main(program: Command): void;
4
+ export { BaseCLI };
package/dist/index.js ADDED
@@ -0,0 +1,20 @@
1
+ import { BaseCLI } from './cli/base.js';
2
+ import { NextCLI } from './cli/next.js';
3
+ import { ReactCLI } from './cli/react.js';
4
+ import { determineLibrary } from './fs/determineFramework.js';
5
+ export function main(program) {
6
+ const { library, additionalModules } = determineLibrary();
7
+ let cli;
8
+ if (library === 'gt-next') {
9
+ cli = new NextCLI(program, library, additionalModules);
10
+ }
11
+ else if (library === 'gt-react') {
12
+ cli = new ReactCLI(program, library, additionalModules);
13
+ }
14
+ else {
15
+ cli = new BaseCLI(program, library, additionalModules);
16
+ }
17
+ cli.init();
18
+ cli.execute();
19
+ }
20
+ export { BaseCLI };
package/dist/main.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/main.js ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env node
2
+ import { main } from './index.js';
3
+ import dotenv from 'dotenv';
4
+ import { program } from 'commander';
5
+ dotenv.config({ path: '.env' });
6
+ dotenv.config({ path: '.env.local', override: true });
7
+ dotenv.config({ path: '.env.production', override: true });
8
+ main(program);
9
+ program.parse();
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Extracts projectId, defaultLocale, and locales from a next.config.js file.
3
+ * @param {string} filePath - The path to the next.config.js file.
4
+ * @returns {object|null} - An object containing the extracted values or null if none found or incorrect types.
5
+ */
6
+ export declare function parseNextConfig(filePath: string): Promise<{
7
+ projectId?: string;
8
+ defaultLocale?: string;
9
+ locales?: string[];
10
+ }>;
@@ -0,0 +1,53 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { gt } from '../../utils/gt.js';
4
+ /**
5
+ * Extracts projectId, defaultLocale, and locales from a next.config.js file.
6
+ * @param {string} filePath - The path to the next.config.js file.
7
+ * @returns {object|null} - An object containing the extracted values or null if none found or incorrect types.
8
+ */
9
+ export async function parseNextConfig(filePath) {
10
+ // Resolve the absolute path
11
+ const absoluteFilePath = path.resolve(filePath);
12
+ // Check if the file exists
13
+ if (!fs.existsSync(absoluteFilePath)) {
14
+ return {};
15
+ }
16
+ // Read the file content
17
+ const fileContent = await fs.promises.readFile(absoluteFilePath, 'utf8');
18
+ // Regular expressions to extract the values
19
+ const defaultLocaleRegex = /defaultLocale:\s*['"]([^'"]+)['"]/;
20
+ const projectIdRegex = /projectId:\s*['"]([^'"]+)['"]/;
21
+ const localesRegex = /locales:\s*\[([^\]]+)\]/;
22
+ // Extract the values
23
+ const defaultLocaleMatch = fileContent.match(defaultLocaleRegex);
24
+ const projectIdMatch = fileContent.match(projectIdRegex);
25
+ const localesMatch = fileContent.match(localesRegex);
26
+ const defaultLocale = defaultLocaleMatch && typeof defaultLocaleMatch[1] === 'string'
27
+ ? defaultLocaleMatch[1]
28
+ : undefined;
29
+ const projectId = projectIdMatch && typeof projectIdMatch[1] === 'string'
30
+ ? projectIdMatch[1]
31
+ : undefined;
32
+ const locales = localesMatch
33
+ ? localesMatch[1]
34
+ .split(',')
35
+ .map((locale) => locale.trim().replace(/['"]/g, ''))
36
+ .filter((locale) => typeof locale === 'string')
37
+ : undefined;
38
+ // Ensure approvedLocales is an array of strings
39
+ const validLocales = locales && locales.every((locale) => gt.isValidLocale(locale))
40
+ ? locales
41
+ : undefined;
42
+ // Return the extracted values if they pass type checks or return null
43
+ if (defaultLocale || projectId || validLocales) {
44
+ return {
45
+ ...(defaultLocale && { defaultLocale }),
46
+ ...(projectId && { projectId }),
47
+ ...(validLocales && { locales: validLocales }),
48
+ };
49
+ }
50
+ else {
51
+ return {};
52
+ }
53
+ }
@@ -0,0 +1,7 @@
1
+ import * as t from '@babel/types';
2
+ import { NodePath } from '@babel/traverse';
3
+ export declare function isHtmlElement(element: t.JSXOpeningElement): boolean;
4
+ export declare function isBodyElement(element: t.JSXOpeningElement): boolean;
5
+ export declare function hasGTProviderChild(element: t.JSXElement): boolean;
6
+ export declare function addDynamicLangAttribute(element: t.JSXOpeningElement): void;
7
+ export declare function makeParentFunctionAsync(path: NodePath): boolean;
@@ -0,0 +1,42 @@
1
+ import * as t from '@babel/types';
2
+ // Helper function to check if is the <html> fragment
3
+ export function isHtmlElement(element) {
4
+ return (t.isJSXIdentifier(element.name) &&
5
+ element.name.name.toLowerCase() === 'html');
6
+ }
7
+ // Helper function to check if is the <body> fragment
8
+ export function isBodyElement(element) {
9
+ return (t.isJSXIdentifier(element.name) &&
10
+ element.name.name.toLowerCase() === 'body');
11
+ }
12
+ // Helper function to check if the <body> element has a <GTProvider> child
13
+ export function hasGTProviderChild(element) {
14
+ return element.children.some((child) => t.isJSXElement(child) &&
15
+ t.isJSXIdentifier(child.openingElement.name) &&
16
+ child.openingElement.name.name === 'GTProvider');
17
+ }
18
+ export function addDynamicLangAttribute(element) {
19
+ // Remove existing lang attribute if present
20
+ const langAttrIndex = element.attributes.findIndex((attr) => t.isJSXAttribute(attr) &&
21
+ t.isJSXIdentifier(attr.name) &&
22
+ attr.name.name === 'lang');
23
+ if (langAttrIndex !== -1) {
24
+ element.attributes.splice(langAttrIndex, 1);
25
+ }
26
+ // Add lang={await getLocale()} attribute
27
+ element.attributes.push(t.jsxAttribute(t.jsxIdentifier('lang'), t.jsxExpressionContainer(t.awaitExpression(t.callExpression(t.identifier('getLocale'), [])))));
28
+ }
29
+ export function makeParentFunctionAsync(path) {
30
+ const functionParent = path.getFunctionParent();
31
+ if (!functionParent)
32
+ return false;
33
+ const node = functionParent.node;
34
+ if ((t.isFunctionDeclaration(node) ||
35
+ t.isFunctionExpression(node) ||
36
+ t.isArrowFunctionExpression(node)) &&
37
+ !node.async) {
38
+ node.async = true;
39
+ return true;
40
+ }
41
+ return false;
42
+ }
@@ -0,0 +1,7 @@
1
+ export declare function handleInitGT(filepath: string, errors: string[], warnings: string[], filesUpdated: string[], packageJson?: {
2
+ type?: string;
3
+ }, tsconfigJson?: {
4
+ compilerOptions?: {
5
+ module?: string;
6
+ };
7
+ }): Promise<void>;