gtx-cli 2.0.23-alpha.0 → 2.0.24
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
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# gtx-cli
|
|
2
2
|
|
|
3
|
+
## 2.0.24
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#552](https://github.com/generaltranslation/gt/pull/552) [`65acf00`](https://github.com/generaltranslation/gt/commit/65acf0085a2b2c89f46b6b4685d94815a16467e6) Thanks [@brian-lou](https://github.com/brian-lou)! - Remove wizard auto-add T components
|
|
8
|
+
|
|
9
|
+
## 2.0.23
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#539](https://github.com/generaltranslation/gt/pull/539) [`b88e468`](https://github.com/generaltranslation/gt/commit/b88e4684be9cd82a7d23e38fc893c2a8b7f0165f) Thanks [@ErnestM1234](https://github.com/ErnestM1234)! - feat: add ability to exclude import paths and url paths from localization
|
|
14
|
+
|
|
3
15
|
## 2.0.22
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/cli/base.d.ts
CHANGED
|
@@ -17,7 +17,8 @@ export type TranslateOptions = {
|
|
|
17
17
|
experimentalHideDefaultLocale?: boolean;
|
|
18
18
|
experimentalFlattenJsonFiles?: boolean;
|
|
19
19
|
experimentalLocalizeStaticImports?: boolean;
|
|
20
|
-
|
|
20
|
+
excludeStaticUrls?: string[];
|
|
21
|
+
excludeStaticImports?: string[];
|
|
21
22
|
};
|
|
22
23
|
export type LoginOptions = {
|
|
23
24
|
keyType?: 'development' | 'production';
|
package/dist/setup/wizard.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { detectFormatter } from '../hooks/postProcess.js';
|
|
2
|
-
import { createSpinner,
|
|
3
|
-
import { logInfo, logError,
|
|
2
|
+
import { createSpinner, promptSelect } from '../console/logging.js';
|
|
3
|
+
import { logInfo, logError, logStep, logWarning } from '../console/logging.js';
|
|
4
4
|
import chalk from 'chalk';
|
|
5
5
|
import { promptConfirm } from '../console/logging.js';
|
|
6
6
|
import findFilepath from '../fs/findFilepath.js';
|
|
7
7
|
import { formatFiles } from '../hooks/postProcess.js';
|
|
8
8
|
import { handleInitGT } from '../next/parse/handleInitGT.js';
|
|
9
9
|
import { getPackageJson, isPackageInstalled } from '../utils/packageJson.js';
|
|
10
|
-
import { wrapContentReact } from '../react/parse/wrapContent.js';
|
|
11
10
|
import { wrapContentNext } from '../next/parse/wrapContent.js';
|
|
12
11
|
import { getPackageManager } from '../utils/packageManager.js';
|
|
13
12
|
import { installPackage } from '../utils/installPackage.js';
|
|
@@ -86,75 +85,28 @@ Please let us know what you would like to see supported at https://github.com/ge
|
|
|
86
85
|
logError('No next.config.[js|ts|mjs|mts] file found.');
|
|
87
86
|
process.exit(1);
|
|
88
87
|
}
|
|
89
|
-
const addGTProvider = await promptConfirm({
|
|
90
|
-
message: 'Do you want the setup wizard to automatically add the GTProvider component?',
|
|
91
|
-
defaultValue: true,
|
|
92
|
-
});
|
|
93
|
-
const addWithGTConfig = await promptConfirm({
|
|
94
|
-
message: `Do you want to automatically add withGTConfig() to your ${nextConfigPath}?`,
|
|
95
|
-
defaultValue: true,
|
|
96
|
-
});
|
|
97
|
-
const includeTId = await promptConfirm({
|
|
98
|
-
message: 'Do you want to include an unique id for each <T> tag?',
|
|
99
|
-
defaultValue: true,
|
|
100
|
-
});
|
|
101
88
|
const mergeOptions = {
|
|
102
89
|
...options,
|
|
103
|
-
disableIds:
|
|
90
|
+
disableIds: true,
|
|
104
91
|
disableFormatting: true,
|
|
105
|
-
skipTs:
|
|
106
|
-
addGTProvider,
|
|
92
|
+
skipTs: true,
|
|
93
|
+
addGTProvider: true,
|
|
107
94
|
};
|
|
108
95
|
const spinner = createSpinner();
|
|
109
96
|
spinner.start('Wrapping JSX content with <T> tags...');
|
|
110
97
|
// Wrap all JSX elements in the src directory with a <T> tag, with unique ids
|
|
111
98
|
const { filesUpdated: filesUpdatedNext } = await wrapContentNext(mergeOptions, 'gt-next', errors, warnings);
|
|
112
99
|
filesUpdated = [...filesUpdated, ...filesUpdatedNext];
|
|
113
|
-
spinner.stop(chalk.green(`Success!
|
|
114
|
-
if
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
logStep(chalk.green(`Added withGTConfig() to your ${nextConfigPath} file.`));
|
|
121
|
-
}
|
|
122
|
-
if (errors.length > 0) {
|
|
123
|
-
logError(chalk.red('Failed to write files:\n') + errors.join('\n'));
|
|
124
|
-
}
|
|
125
|
-
logSuccess(chalk.green(`Success! All JSX content has been wrapped with <T> tags${includeTId ? ' and unique ids.' : '.'}`));
|
|
126
|
-
logMessage(`To translate strings, see the docs on useGT and getGT: https://generaltranslation.com/docs/next/api/strings/getGT`);
|
|
100
|
+
spinner.stop(chalk.green(`Success! Updated ${chalk.bold.cyan(filesUpdated.length)} files:\n`) + filesUpdated.map((file) => `${chalk.green('-')} ${file}`).join('\n'));
|
|
101
|
+
// Read tsconfig.json if it exists
|
|
102
|
+
const tsconfigPath = findFilepath(['tsconfig.json']);
|
|
103
|
+
const tsconfigJson = tsconfigPath ? loadConfig(tsconfigPath) : undefined;
|
|
104
|
+
// Add the withGTConfig() function to the next.config.js file
|
|
105
|
+
await handleInitGT(nextConfigPath, errors, warnings, filesUpdated, packageJson, tsconfigJson);
|
|
106
|
+
logStep(chalk.green(`Added withGTConfig() to your ${nextConfigPath} file.`));
|
|
127
107
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
if (frameworkType === 'next-pages') {
|
|
131
|
-
addGTProvider = await promptConfirm({
|
|
132
|
-
message: 'Do you want the setup wizard to automatically add the GTProvider component?',
|
|
133
|
-
defaultValue: true,
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
const includeTId = await promptConfirm({
|
|
137
|
-
message: 'Do you want to include an unique id for each <T> tag?',
|
|
138
|
-
defaultValue: true,
|
|
139
|
-
});
|
|
140
|
-
const mergeOptions = {
|
|
141
|
-
...options,
|
|
142
|
-
disableIds: !includeTId,
|
|
143
|
-
disableFormatting: true,
|
|
144
|
-
skipTs: false,
|
|
145
|
-
addGTProvider,
|
|
146
|
-
};
|
|
147
|
-
const spinner = createSpinner();
|
|
148
|
-
spinner.start('Wrapping JSX content with <T> tags...');
|
|
149
|
-
// Wrap all JSX elements in the src directory with a <T> tag, with unique ids
|
|
150
|
-
const { filesUpdated: filesUpdatedReact } = await wrapContentReact(mergeOptions, 'gt-react', frameworkType, errors, warnings);
|
|
151
|
-
filesUpdated = [...filesUpdated, ...filesUpdatedReact];
|
|
152
|
-
spinner.stop(chalk.green(`Success! Added <T> tags and updated ${chalk.bold.cyan(filesUpdated.length)} files:\n`) + filesUpdated.map((file) => `${chalk.green('-')} ${file}`).join('\n'));
|
|
153
|
-
if (errors.length > 0) {
|
|
154
|
-
logError(chalk.red('Failed to write files:\n') + errors.join('\n'));
|
|
155
|
-
}
|
|
156
|
-
logSuccess(chalk.green(`Success! All JSX content has been wrapped with <T> tags${includeTId ? ' and unique ids.' : '.'}`));
|
|
157
|
-
logMessage(`To translate strings, see the docs on useGT: https://generaltranslation.com/docs/react/api/strings/useGT`);
|
|
108
|
+
if (errors.length > 0) {
|
|
109
|
+
logError(chalk.red('Failed to write files:\n') + errors.join('\n'));
|
|
158
110
|
}
|
|
159
111
|
if (warnings.length > 0) {
|
|
160
112
|
logWarning(chalk.yellow('Warnings encountered:') +
|
package/dist/types/index.d.ts
CHANGED
|
@@ -108,14 +108,14 @@ export type AdditionalOptions = {
|
|
|
108
108
|
};
|
|
109
109
|
docsUrlPattern?: string;
|
|
110
110
|
docsImportPattern?: string;
|
|
111
|
+
excludeStaticUrls?: string[];
|
|
112
|
+
excludeStaticImports?: string[];
|
|
111
113
|
docsHideDefaultLocaleImport?: boolean;
|
|
112
114
|
copyFiles?: string[];
|
|
113
115
|
experimentalLocalizeStaticImports?: boolean;
|
|
114
116
|
experimentalLocalizeStaticUrls?: boolean;
|
|
115
117
|
experimentalHideDefaultLocale?: boolean;
|
|
116
118
|
experimentalFlattenJsonFiles?: boolean;
|
|
117
|
-
experimentalExcludeStaticUrls?: string[];
|
|
118
|
-
experimentalExcludeStaticImports?: string[];
|
|
119
119
|
};
|
|
120
120
|
export type JsonSchema = {
|
|
121
121
|
preset?: 'mintlify';
|
|
@@ -33,7 +33,7 @@ export default async function localizeStaticImports(settings) {
|
|
|
33
33
|
// Get file content
|
|
34
34
|
const fileContent = await fs.promises.readFile(filePath, 'utf8');
|
|
35
35
|
// Localize the file
|
|
36
|
-
const localizedFile = localizeStaticImportsForFile(fileContent, settings.defaultLocale, locale, settings.options?.docsHideDefaultLocaleImport || false, settings.options?.docsImportPattern, settings.options?.
|
|
36
|
+
const localizedFile = localizeStaticImportsForFile(fileContent, settings.defaultLocale, locale, settings.options?.docsHideDefaultLocaleImport || false, settings.options?.docsImportPattern, settings.options?.excludeStaticImports);
|
|
37
37
|
// Write the localized file to the target path
|
|
38
38
|
await fs.promises.writeFile(filePath, localizedFile);
|
|
39
39
|
}));
|
|
@@ -69,12 +69,18 @@ exclude = []) {
|
|
|
69
69
|
const localizedFile = file.replace(regex, (match, bindings, quoteType, pathContent) => {
|
|
70
70
|
// Check if this path should be excluded from localization
|
|
71
71
|
if (exclude.length > 0) {
|
|
72
|
-
let matchPath =
|
|
72
|
+
let matchPath = '';
|
|
73
|
+
// let matchPath = patternHead;
|
|
73
74
|
if (pathContent) {
|
|
74
75
|
matchPath = hideDefaultLocale
|
|
75
76
|
? `${patternHead}${pathContent}`
|
|
76
77
|
: `${patternHead}${defaultLocale}/${pathContent}`;
|
|
77
78
|
}
|
|
79
|
+
else {
|
|
80
|
+
matchPath = hideDefaultLocale
|
|
81
|
+
? `${patternHead}`
|
|
82
|
+
: `${patternHead}${defaultLocale}`;
|
|
83
|
+
}
|
|
78
84
|
if (exclude.some((pattern) => isMatch(matchPath, pattern))) {
|
|
79
85
|
return match; // Don't localize excluded paths
|
|
80
86
|
}
|
|
@@ -32,8 +32,8 @@ export default async function localizeStaticUrls(settings) {
|
|
|
32
32
|
// Get file content
|
|
33
33
|
const fileContent = await fs.promises.readFile(filePath, 'utf8');
|
|
34
34
|
// Localize the file
|
|
35
|
-
const localizedFile = localizeStaticUrlsForFile(fileContent, settings.defaultLocale, locale, settings.experimentalHideDefaultLocale || false, settings.options?.docsUrlPattern, settings.options?.
|
|
36
|
-
const localizedFileHrefs = localizeStaticHrefsForFile(localizedFile, settings.defaultLocale, locale, settings.experimentalHideDefaultLocale || false, settings.options?.docsUrlPattern, settings.options?.
|
|
35
|
+
const localizedFile = localizeStaticUrlsForFile(fileContent, settings.defaultLocale, locale, settings.experimentalHideDefaultLocale || false, settings.options?.docsUrlPattern, settings.options?.excludeStaticUrls);
|
|
36
|
+
const localizedFileHrefs = localizeStaticHrefsForFile(localizedFile, settings.defaultLocale, locale, settings.experimentalHideDefaultLocale || false, settings.options?.docsUrlPattern, settings.options?.excludeStaticUrls);
|
|
37
37
|
// Write the localized file to the target path
|
|
38
38
|
await fs.promises.writeFile(filePath, localizedFileHrefs);
|
|
39
39
|
}));
|
|
@@ -69,12 +69,17 @@ exclude = []) {
|
|
|
69
69
|
const localizedFile = file.replace(regex, (match, pathContent) => {
|
|
70
70
|
if (exclude.length > 0) {
|
|
71
71
|
// Check if this path should be excluded from localization
|
|
72
|
-
let matchPath =
|
|
72
|
+
let matchPath = '';
|
|
73
73
|
if (pathContent) {
|
|
74
74
|
matchPath = hideDefaultLocale
|
|
75
75
|
? `${patternHead}${pathContent}`
|
|
76
76
|
: `${patternHead}${defaultLocale}/${pathContent}`;
|
|
77
77
|
}
|
|
78
|
+
else {
|
|
79
|
+
matchPath = hideDefaultLocale
|
|
80
|
+
? `${patternHead}`
|
|
81
|
+
: `${patternHead}${defaultLocale}`;
|
|
82
|
+
}
|
|
78
83
|
if (exclude.some((pattern) => isMatch(matchPath, pattern))) {
|
|
79
84
|
return match; // Don't localize excluded paths
|
|
80
85
|
}
|