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.
- package/CHANGELOG.md +10 -0
- package/dist/api/checkFileTranslations.d.ts +23 -0
- package/dist/api/checkFileTranslations.js +236 -0
- package/dist/api/downloadFileBatch.d.ts +20 -0
- package/dist/api/downloadFileBatch.js +113 -0
- package/dist/api/sendFiles.d.ts +17 -0
- package/dist/api/sendFiles.js +115 -0
- package/dist/api/uploadFiles.d.ts +27 -0
- package/dist/api/uploadFiles.js +40 -0
- package/dist/cli/base.d.ts +32 -0
- package/dist/cli/base.js +335 -0
- package/dist/cli/commands/stage.d.ts +5 -0
- package/dist/cli/commands/stage.js +100 -0
- package/dist/cli/commands/translate.d.ts +6 -0
- package/dist/cli/commands/translate.js +63 -0
- package/dist/cli/flags.d.ts +3 -0
- package/dist/cli/flags.js +38 -0
- package/dist/cli/next.d.ts +11 -0
- package/dist/cli/next.js +20 -0
- package/dist/cli/react.d.ts +18 -0
- package/dist/cli/react.js +175 -0
- package/dist/config/generateSettings.d.ts +9 -0
- package/dist/config/generateSettings.js +176 -0
- package/dist/config/optionPresets.d.ts +2 -0
- package/dist/config/optionPresets.js +56 -0
- package/dist/config/resolveConfig.d.ts +4 -0
- package/dist/config/resolveConfig.js +19 -0
- package/dist/config/utils.d.ts +2 -0
- package/dist/config/utils.js +4 -0
- package/dist/config/validateSettings.d.ts +3 -0
- package/dist/config/validateSettings.js +32 -0
- package/dist/console/colors.d.ts +5 -0
- package/dist/console/colors.js +16 -0
- package/dist/console/index.d.ts +21 -0
- package/dist/console/index.js +24 -0
- package/dist/console/logging.d.ts +53 -0
- package/dist/console/logging.js +185 -0
- package/dist/formats/files/fileMapping.d.ts +11 -0
- package/dist/formats/files/fileMapping.js +82 -0
- package/dist/formats/files/save.d.ts +5 -0
- package/dist/formats/files/save.js +17 -0
- package/dist/formats/files/supportedFiles.d.ts +10 -0
- package/dist/formats/files/supportedFiles.js +18 -0
- package/dist/formats/files/translate.d.ts +4 -0
- package/dist/formats/files/translate.js +119 -0
- package/dist/formats/files/upload.d.ts +13 -0
- package/dist/formats/files/upload.js +136 -0
- package/dist/formats/gt/save.d.ts +9 -0
- package/dist/formats/gt/save.js +26 -0
- package/dist/formats/json/flattenJson.d.ts +14 -0
- package/dist/formats/json/flattenJson.js +64 -0
- package/dist/formats/json/mergeJson.d.ts +13 -0
- package/dist/formats/json/mergeJson.js +257 -0
- package/dist/formats/json/parseJson.d.ts +2 -0
- package/dist/formats/json/parseJson.js +108 -0
- package/dist/formats/json/utils.d.ts +47 -0
- package/dist/formats/json/utils.js +149 -0
- package/dist/formats/utils.d.ts +2 -0
- package/dist/formats/utils.js +24 -0
- package/dist/formats/yaml/mergeYaml.d.ts +5 -0
- package/dist/formats/yaml/mergeYaml.js +55 -0
- package/dist/formats/yaml/parseYaml.d.ts +5 -0
- package/dist/formats/yaml/parseYaml.js +23 -0
- package/dist/formats/yaml/utils.d.ts +2 -0
- package/dist/formats/yaml/utils.js +22 -0
- package/dist/fs/config/loadConfig.d.ts +1 -0
- package/dist/fs/config/loadConfig.js +9 -0
- package/dist/fs/config/parseFilesConfig.d.ts +27 -0
- package/dist/fs/config/parseFilesConfig.js +129 -0
- package/dist/fs/config/setupConfig.d.ts +17 -0
- package/dist/fs/config/setupConfig.js +50 -0
- package/dist/fs/config/updateConfig.d.ts +10 -0
- package/dist/fs/config/updateConfig.js +36 -0
- package/dist/fs/config/updateVersions.d.ts +10 -0
- package/dist/fs/config/updateVersions.js +30 -0
- package/dist/fs/copyFile.d.ts +7 -0
- package/dist/fs/copyFile.js +39 -0
- package/dist/fs/createLoadTranslationsFile.d.ts +1 -0
- package/dist/fs/createLoadTranslationsFile.js +36 -0
- package/dist/fs/determineFramework.d.ts +5 -0
- package/dist/fs/determineFramework.js +46 -0
- package/dist/fs/findFilepath.d.ts +36 -0
- package/dist/fs/findFilepath.js +89 -0
- package/dist/fs/getPackageResource.d.ts +1 -0
- package/dist/fs/getPackageResource.js +6 -0
- package/dist/fs/index.d.ts +1 -0
- package/dist/fs/index.js +1 -0
- package/dist/fs/loadJSON.d.ts +6 -0
- package/dist/fs/loadJSON.js +17 -0
- package/dist/fs/matchFiles.d.ts +1 -0
- package/dist/fs/matchFiles.js +8 -0
- package/dist/fs/saveJSON.d.ts +1 -0
- package/dist/fs/saveJSON.js +7 -0
- package/dist/fs/utils.d.ts +1 -0
- package/dist/fs/utils.js +16 -0
- package/dist/hooks/postProcess.d.ts +4 -0
- package/dist/hooks/postProcess.js +110 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +20 -0
- package/dist/main.d.ts +2 -0
- package/dist/main.js +9 -0
- package/dist/next/config/parseNextConfig.d.ts +10 -0
- package/dist/next/config/parseNextConfig.js +53 -0
- package/dist/next/jsx/utils.d.ts +7 -0
- package/dist/next/jsx/utils.js +42 -0
- package/dist/next/parse/handleInitGT.d.ts +7 -0
- package/dist/next/parse/handleInitGT.js +208 -0
- package/dist/next/parse/wrapContent.d.ts +11 -0
- package/dist/next/parse/wrapContent.js +163 -0
- package/dist/react/config/createESBuildConfig.d.ts +2 -0
- package/dist/react/config/createESBuildConfig.js +119 -0
- package/dist/react/data-_gt/addGTIdentifierToSyntaxTree.d.ts +8 -0
- package/dist/react/data-_gt/addGTIdentifierToSyntaxTree.js +111 -0
- package/dist/react/jsx/evaluateJsx.d.ts +17 -0
- package/dist/react/jsx/evaluateJsx.js +85 -0
- package/dist/react/jsx/trimJsxStringChildren.d.ts +7 -0
- package/dist/react/jsx/trimJsxStringChildren.js +95 -0
- package/dist/react/jsx/utils/constants.d.ts +10 -0
- package/dist/react/jsx/utils/constants.js +31 -0
- package/dist/react/jsx/utils/parseAst.d.ts +30 -0
- package/dist/react/jsx/utils/parseAst.js +277 -0
- package/dist/react/jsx/utils/parseJsx.d.ts +21 -0
- package/dist/react/jsx/utils/parseJsx.js +244 -0
- package/dist/react/jsx/utils/parseStringFunction.d.ts +16 -0
- package/dist/react/jsx/utils/parseStringFunction.js +411 -0
- package/dist/react/jsx/utils/validateStringFunction.d.ts +7 -0
- package/dist/react/jsx/utils/validateStringFunction.js +31 -0
- package/dist/react/jsx/wrapJsx.d.ts +51 -0
- package/dist/react/jsx/wrapJsx.js +387 -0
- package/dist/react/parse/createDictionaryUpdates.d.ts +3 -0
- package/dist/react/parse/createDictionaryUpdates.js +169 -0
- package/dist/react/parse/createInlineUpdates.d.ts +6 -0
- package/dist/react/parse/createInlineUpdates.js +122 -0
- package/dist/react/parse/wrapContent.d.ts +11 -0
- package/dist/react/parse/wrapContent.js +162 -0
- package/dist/react/utils/flattenDictionary.d.ts +20 -0
- package/dist/react/utils/flattenDictionary.js +75 -0
- package/dist/react/utils/getEntryAndMetadata.d.ts +5 -0
- package/dist/react/utils/getEntryAndMetadata.js +11 -0
- package/dist/react/utils/getVariableName.d.ts +25 -0
- package/dist/react/utils/getVariableName.js +37 -0
- package/dist/setup/userInput.d.ts +4 -0
- package/dist/setup/userInput.js +29 -0
- package/dist/setup/wizard.d.ts +2 -0
- package/dist/setup/wizard.js +127 -0
- package/dist/translation/parse.d.ts +15 -0
- package/dist/translation/parse.js +76 -0
- package/dist/translation/stage.d.ts +2 -0
- package/dist/translation/stage.js +44 -0
- package/dist/translation/validate.d.ts +2 -0
- package/dist/translation/validate.js +50 -0
- package/dist/types/data/json.d.ts +6 -0
- package/dist/types/data/json.js +1 -0
- package/dist/types/data.d.ts +30 -0
- package/dist/types/data.js +1 -0
- package/dist/types/files.d.ts +1 -0
- package/dist/types/files.js +1 -0
- package/dist/types/index.d.ts +173 -0
- package/dist/types/index.js +1 -0
- package/dist/utils/addExplicitAnchorIds.d.ts +24 -0
- package/dist/utils/addExplicitAnchorIds.js +260 -0
- package/dist/utils/constants.d.ts +2 -0
- package/dist/utils/constants.js +2 -0
- package/dist/utils/credentials.d.ts +12 -0
- package/dist/utils/credentials.js +119 -0
- package/dist/utils/flattenJsonFiles.d.ts +2 -0
- package/dist/utils/flattenJsonFiles.js +36 -0
- package/dist/utils/gt.d.ts +2 -0
- package/dist/utils/gt.js +2 -0
- package/dist/utils/hash.d.ts +6 -0
- package/dist/utils/hash.js +11 -0
- package/dist/utils/headers.d.ts +1 -0
- package/dist/utils/headers.js +14 -0
- package/dist/utils/installPackage.d.ts +3 -0
- package/dist/utils/installPackage.js +77 -0
- package/dist/utils/localizeStaticImports.d.ts +15 -0
- package/dist/utils/localizeStaticImports.js +341 -0
- package/dist/utils/localizeStaticUrls.d.ts +19 -0
- package/dist/utils/localizeStaticUrls.js +432 -0
- package/dist/utils/packageInfo.d.ts +3 -0
- package/dist/utils/packageInfo.js +17 -0
- package/dist/utils/packageJson.d.ts +6 -0
- package/dist/utils/packageJson.js +76 -0
- package/dist/utils/packageManager.d.ts +28 -0
- package/dist/utils/packageManager.js +269 -0
- package/dist/utils/processAnchorIds.d.ts +6 -0
- package/dist/utils/processAnchorIds.js +47 -0
- package/dist/utils/sanitizeFileContent.d.ts +6 -0
- package/dist/utils/sanitizeFileContent.js +29 -0
- package/dist/utils/validateMdx.d.ts +10 -0
- package/dist/utils/validateMdx.js +25 -0
- 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 @@
|
|
|
1
|
+
export {};
|
package/dist/fs/index.js
ADDED
|
@@ -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 @@
|
|
|
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;
|
package/dist/fs/utils.js
ADDED
|
@@ -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,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
|
+
}
|
package/dist/index.d.ts
ADDED
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
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
|
+
}
|