gt 2.14.10 → 2.14.11
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/cli/base.js +21 -7
- package/dist/cli/inline.js +6 -4
- package/dist/config/defaults.d.ts +1 -1
- package/dist/config/defaults.js +1 -1
- package/dist/config/generateSettings.d.ts +5 -1
- package/dist/config/generateSettings.js +12 -16
- package/dist/generated/version.d.ts +1 -1
- package/dist/generated/version.js +1 -1
- package/dist/react/jsx/utils/jsxParsing/parseJsx.d.ts +1 -0
- package/dist/react/jsx/utils/jsxParsing/parseJsx.js +1 -1
- package/dist/react/parse/createInlineUpdates.js +5 -1
- package/dist/types/parsing.d.ts +18 -2
- package/dist/types/parsing.js +12 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# gtx-cli
|
|
2
2
|
|
|
3
|
+
## 2.14.11
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#1196](https://github.com/generaltranslation/gt/pull/1196) [`cf8bee6`](https://github.com/generaltranslation/gt/commit/cf8bee67159eeafccf22ac06861905b0a672f64a) Thanks [@moss-bryophyta](https://github.com/moss-bryophyta)! - Fix CLI silently creating `gt.config.json` when running commands like `gt stage` in directories without a config file. Commands that require a config now exit with a clear error message pointing users to `gt init`. Config creation is only handled by the init/setup wizard.
|
|
8
|
+
|
|
9
|
+
- [#1199](https://github.com/generaltranslation/gt/pull/1199) [`1828cd4`](https://github.com/generaltranslation/gt/commit/1828cd4eafb1f3ea868b437b914c844670d2c50f) Thanks [@ErnestM1234](https://github.com/ErnestM1234)! - chore: enable autoderive for jsx
|
|
10
|
+
|
|
11
|
+
- [#1201](https://github.com/generaltranslation/gt/pull/1201) [`fbb9d26`](https://github.com/generaltranslation/gt/commit/fbb9d268dbee58142e305b9076e44000205d5437) Thanks [@ErnestM1234](https://github.com/ErnestM1234)! - chore: customize autoderive
|
|
12
|
+
|
|
3
13
|
## 2.14.10
|
|
4
14
|
|
|
5
15
|
### Patch Changes
|
package/dist/cli/base.js
CHANGED
|
@@ -126,19 +126,25 @@ export class BaseCLI {
|
|
|
126
126
|
.option('--publish', 'Publish translations to the CDN', false)
|
|
127
127
|
.action(async (initOptions) => {
|
|
128
128
|
displayHeader('Saving local edits...');
|
|
129
|
-
const settings = await generateSettings(initOptions
|
|
129
|
+
const settings = await generateSettings(initOptions, undefined, {
|
|
130
|
+
requireConfig: true,
|
|
131
|
+
});
|
|
130
132
|
await saveLocalEdits(settings);
|
|
131
133
|
logger.endCommand('Saved local edits');
|
|
132
134
|
});
|
|
133
135
|
}
|
|
134
136
|
async handleSetupProject(initOptions) {
|
|
135
|
-
const settings = await generateSettings(initOptions
|
|
137
|
+
const settings = await generateSettings(initOptions, undefined, {
|
|
138
|
+
requireConfig: true,
|
|
139
|
+
});
|
|
136
140
|
// Preprocess shared static assets if configured (move + rewrite sources)
|
|
137
141
|
await processSharedStaticAssets(settings);
|
|
138
142
|
await handleSetupProject(initOptions, settings, this.library);
|
|
139
143
|
}
|
|
140
144
|
async handleStage(initOptions) {
|
|
141
|
-
const settings = await generateSettings(initOptions
|
|
145
|
+
const settings = await generateSettings(initOptions, undefined, {
|
|
146
|
+
requireConfig: true,
|
|
147
|
+
});
|
|
142
148
|
// Preprocess shared static assets if configured (move + rewrite sources)
|
|
143
149
|
await processSharedStaticAssets(settings);
|
|
144
150
|
if (!settings.stageTranslations) {
|
|
@@ -156,7 +162,9 @@ export class BaseCLI {
|
|
|
156
162
|
* @returns The results of the command
|
|
157
163
|
*/
|
|
158
164
|
async handleEnqueue(initOptions) {
|
|
159
|
-
const settings = await generateSettings(initOptions
|
|
165
|
+
const settings = await generateSettings(initOptions, undefined, {
|
|
166
|
+
requireConfig: true,
|
|
167
|
+
});
|
|
160
168
|
await handleEnqueue(initOptions, settings, this.library);
|
|
161
169
|
}
|
|
162
170
|
/**
|
|
@@ -165,11 +173,15 @@ export class BaseCLI {
|
|
|
165
173
|
* @returns The results of the command
|
|
166
174
|
*/
|
|
167
175
|
async handleDownload(initOptions) {
|
|
168
|
-
const settings = await generateSettings(initOptions
|
|
176
|
+
const settings = await generateSettings(initOptions, undefined, {
|
|
177
|
+
requireConfig: true,
|
|
178
|
+
});
|
|
169
179
|
await handleDownload(initOptions, settings, this.library);
|
|
170
180
|
}
|
|
171
181
|
async handleTranslate(initOptions) {
|
|
172
|
-
const settings = await generateSettings(initOptions
|
|
182
|
+
const settings = await generateSettings(initOptions, undefined, {
|
|
183
|
+
requireConfig: true,
|
|
184
|
+
});
|
|
173
185
|
// Preprocess shared static assets if configured (move + rewrite sources)
|
|
174
186
|
await processSharedStaticAssets(settings);
|
|
175
187
|
if (!settings.stageTranslations) {
|
|
@@ -197,7 +209,9 @@ export class BaseCLI {
|
|
|
197
209
|
.command('upload')
|
|
198
210
|
.description('Upload source files and translations to the General Translation platform')).action(async (initOptions) => {
|
|
199
211
|
displayHeader('Starting upload...');
|
|
200
|
-
const settings = await generateSettings(initOptions
|
|
212
|
+
const settings = await generateSettings(initOptions, undefined, {
|
|
213
|
+
requireConfig: true,
|
|
214
|
+
});
|
|
201
215
|
const options = { ...initOptions, ...settings };
|
|
202
216
|
await this.handleUploadCommand(options);
|
|
203
217
|
logger.endCommand('Done!');
|
package/dist/cli/inline.js
CHANGED
|
@@ -10,7 +10,6 @@ import { saveJSON } from '../fs/saveJSON.js';
|
|
|
10
10
|
import loadJSON from '../fs/loadJSON.js';
|
|
11
11
|
import { generateSettings } from '../config/generateSettings.js';
|
|
12
12
|
import { aggregateInlineTranslations } from '../translation/stage.js';
|
|
13
|
-
import { validateConfigExists } from '../config/validateSettings.js';
|
|
14
13
|
import { validateProject } from '../translation/validate.js';
|
|
15
14
|
import { Libraries } from '../types/libraries.js';
|
|
16
15
|
/**
|
|
@@ -66,7 +65,9 @@ export class InlineCLI extends BaseCLI {
|
|
|
66
65
|
});
|
|
67
66
|
}
|
|
68
67
|
async handleGenerateSourceCommand(initOptions) {
|
|
69
|
-
const settings = await generateSettings(initOptions
|
|
68
|
+
const settings = await generateSettings(initOptions, undefined, {
|
|
69
|
+
requireConfig: true,
|
|
70
|
+
});
|
|
70
71
|
const updates = await aggregateInlineTranslations(initOptions, settings, fallbackToGtReact(this.library));
|
|
71
72
|
// Convert updates to the proper data format
|
|
72
73
|
const newData = {};
|
|
@@ -108,8 +109,9 @@ export class InlineCLI extends BaseCLI {
|
|
|
108
109
|
}
|
|
109
110
|
}
|
|
110
111
|
async handleValidate(initOptions, files) {
|
|
111
|
-
|
|
112
|
-
|
|
112
|
+
const settings = await generateSettings(initOptions, undefined, {
|
|
113
|
+
requireConfig: true,
|
|
114
|
+
});
|
|
113
115
|
// First run the base class's handleTranslate method
|
|
114
116
|
const options = { ...initOptions, ...settings };
|
|
115
117
|
// Fallback to gt-react
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BaseParsingFlags, GTParsingFlags } from '../types/parsing.js';
|
|
2
2
|
/**
|
|
3
3
|
* Default parsing flags for GT files
|
|
4
|
-
* @property {boolean} autoderive - Whether to enable autoderive
|
|
4
|
+
* @property {boolean | { jsx?: boolean; strings?: boolean }} autoderive - Whether to enable autoderive. A plain boolean enables/disables both; an object enables selectively.
|
|
5
5
|
* @property {boolean} includeSourceCodeContext - Include surrounding source code lines as context for translations.
|
|
6
6
|
*/
|
|
7
7
|
export declare const GT_PARSING_FLAGS_DEFAULT: GTParsingFlags;
|
package/dist/config/defaults.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Default parsing flags for GT files
|
|
3
|
-
* @property {boolean} autoderive - Whether to enable autoderive
|
|
3
|
+
* @property {boolean | { jsx?: boolean; strings?: boolean }} autoderive - Whether to enable autoderive. A plain boolean enables/disables both; an object enables selectively.
|
|
4
4
|
* @property {boolean} includeSourceCodeContext - Include surrounding source code lines as context for translations.
|
|
5
5
|
*/
|
|
6
6
|
export const GT_PARSING_FLAGS_DEFAULT = {
|
|
@@ -6,6 +6,10 @@ export declare const DEFAULT_PYTHON_SRC_EXCLUDES: string[];
|
|
|
6
6
|
* Generates settings from any
|
|
7
7
|
* @param flags - The CLI flags to generate settings from
|
|
8
8
|
* @param cwd - The current working directory
|
|
9
|
+
* @param options - Additional options
|
|
10
|
+
* @param options.requireConfig - If true, exit with an error when no config file is found
|
|
9
11
|
* @returns The generated settings
|
|
10
12
|
*/
|
|
11
|
-
export declare function generateSettings(flags: Record<string, any>, cwd?: string
|
|
13
|
+
export declare function generateSettings(flags: Record<string, any>, cwd?: string, options?: {
|
|
14
|
+
requireConfig?: boolean;
|
|
15
|
+
}): Promise<Settings>;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { displayProjectId, exitSync, logErrorAndExit, warnApiKeyInConfig, warnDeprecatedField, } from '../console/logging.js';
|
|
2
2
|
import { loadConfig } from '../fs/config/loadConfig.js';
|
|
3
3
|
import { defaultBaseUrl, libraryDefaultLocale, } from 'generaltranslation/internal';
|
|
4
|
-
import fs from 'node:fs';
|
|
5
|
-
import { createOrUpdateConfig } from '../fs/config/setupConfig.js';
|
|
6
4
|
import { resolveFiles } from '../fs/config/parseFilesConfig.js';
|
|
7
5
|
import { validateSettings } from './validateSettings.js';
|
|
8
6
|
import { DEFAULT_GIT_REMOTE_NAME, GT_DASHBOARD_URL, } from '../utils/constants.js';
|
|
@@ -35,9 +33,11 @@ export const DEFAULT_PYTHON_SRC_EXCLUDES = [
|
|
|
35
33
|
* Generates settings from any
|
|
36
34
|
* @param flags - The CLI flags to generate settings from
|
|
37
35
|
* @param cwd - The current working directory
|
|
36
|
+
* @param options - Additional options
|
|
37
|
+
* @param options.requireConfig - If true, exit with an error when no config file is found
|
|
38
38
|
* @returns The generated settings
|
|
39
39
|
*/
|
|
40
|
-
export async function generateSettings(flags, cwd = process.cwd()) {
|
|
40
|
+
export async function generateSettings(flags, cwd = process.cwd(), options) {
|
|
41
41
|
// Load config file
|
|
42
42
|
let gtConfig = {};
|
|
43
43
|
if (flags.config && !flags.config.endsWith('.json')) {
|
|
@@ -53,6 +53,9 @@ export async function generateSettings(flags, cwd = process.cwd()) {
|
|
|
53
53
|
flags.config = config.path;
|
|
54
54
|
}
|
|
55
55
|
else {
|
|
56
|
+
if (options?.requireConfig) {
|
|
57
|
+
return logErrorAndExit('No gt.config.json file found. Run `npx gt init` to create one, or use --config to specify a path.');
|
|
58
|
+
}
|
|
56
59
|
gtConfig = {};
|
|
57
60
|
}
|
|
58
61
|
}
|
|
@@ -111,9 +114,12 @@ export async function generateSettings(flags, cwd = process.cwd()) {
|
|
|
111
114
|
mergedOptions.dashboardUrl = mergedOptions.dashboardUrl || GT_DASHBOARD_URL;
|
|
112
115
|
// Add locales if not provided
|
|
113
116
|
mergedOptions.locales = mergedOptions.locales || [];
|
|
114
|
-
//
|
|
115
|
-
|
|
116
|
-
|
|
117
|
+
// Only set config path if one was actually found or explicitly provided.
|
|
118
|
+
// Do not default to a phantom path — that would cause downstream writes
|
|
119
|
+
// (e.g. updateConfig) to silently create a config file.
|
|
120
|
+
if (!mergedOptions.config) {
|
|
121
|
+
mergedOptions.config = '';
|
|
122
|
+
}
|
|
117
123
|
// Display projectId if present
|
|
118
124
|
if (mergedOptions.projectId)
|
|
119
125
|
displayProjectId(mergedOptions.projectId);
|
|
@@ -252,16 +258,6 @@ export async function generateSettings(flags, cwd = process.cwd()) {
|
|
|
252
258
|
mergedOptions.tag = crypto.randomBytes(4).toString('hex');
|
|
253
259
|
}
|
|
254
260
|
}
|
|
255
|
-
// if there's no existing config file, creates one
|
|
256
|
-
// does not include the API key to avoid exposing it
|
|
257
|
-
if (!fs.existsSync(mergedOptions.config)) {
|
|
258
|
-
await createOrUpdateConfig(mergedOptions.config, {
|
|
259
|
-
projectId: mergedOptions.projectId,
|
|
260
|
-
defaultLocale: mergedOptions.defaultLocale,
|
|
261
|
-
locales: mergedOptions.locales?.length > 0 ? mergedOptions.locales : undefined,
|
|
262
|
-
framework: mergedOptions.framework,
|
|
263
|
-
});
|
|
264
|
-
}
|
|
265
261
|
mergedOptions.configDirectory = path.join(cwd, '.gt');
|
|
266
262
|
validateSettings(mergedOptions);
|
|
267
263
|
// Set up GT instance
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PACKAGE_VERSION = "2.14.
|
|
1
|
+
export declare const PACKAGE_VERSION = "2.14.11";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// This file is auto-generated. Do not edit manually.
|
|
2
|
-
export const PACKAGE_VERSION = '2.14.
|
|
2
|
+
export const PACKAGE_VERSION = '2.14.11';
|
|
@@ -5,6 +5,7 @@ import { parseStrings } from '../jsx/utils/parseStringFunction.js';
|
|
|
5
5
|
import { logger } from '../../console/logger.js';
|
|
6
6
|
import { matchFiles } from '../../fs/matchFiles.js';
|
|
7
7
|
import { DEFAULT_SRC_PATTERNS } from '../../config/generateSettings.js';
|
|
8
|
+
import { resolveAutoderive } from '../../types/parsing.js';
|
|
8
9
|
import { getPathsAndAliases } from '../jsx/utils/getPathsAndAliases.js';
|
|
9
10
|
import { GT_LIBRARIES_UPSTREAM, REACT_LIBRARIES, } from '../../types/libraries.js';
|
|
10
11
|
import { calculateHashes, dedupeUpdates, linkDeriveUpdates, } from '../../extraction/postProcess.js';
|
|
@@ -17,6 +18,7 @@ export async function createInlineUpdates(pkg, validate, filePatterns, parsingFl
|
|
|
17
18
|
const errors = [];
|
|
18
19
|
const warnings = new Set();
|
|
19
20
|
const pkgs = getUpstreamPackages(pkg);
|
|
21
|
+
const autoderive = resolveAutoderive(parsingFlags.autoderive);
|
|
20
22
|
// Use the provided app directory or default to the current directory
|
|
21
23
|
const files = matchFiles(process.cwd(), filePatterns || DEFAULT_SRC_PATTERNS);
|
|
22
24
|
for (const file of files) {
|
|
@@ -47,7 +49,7 @@ export async function createInlineUpdates(pkg, validate, filePatterns, parsingFl
|
|
|
47
49
|
ignoreTaggedTemplates: false,
|
|
48
50
|
ignoreGlobalTaggedTemplates: false,
|
|
49
51
|
// User configurable, otherwise default to AUTO
|
|
50
|
-
autoderiveMethod:
|
|
52
|
+
autoderiveMethod: autoderive.strings ? 'AUTO' : 'DISABLED',
|
|
51
53
|
}, { updates, errors, warnings });
|
|
52
54
|
}
|
|
53
55
|
// Parse <T> components — PASS 1: user-written T
|
|
@@ -64,6 +66,7 @@ export async function createInlineUpdates(pkg, validate, filePatterns, parsingFl
|
|
|
64
66
|
pkgs,
|
|
65
67
|
file,
|
|
66
68
|
includeSourceCodeContext: parsingFlags.includeSourceCodeContext,
|
|
69
|
+
autoderive: autoderive.jsx,
|
|
67
70
|
},
|
|
68
71
|
output: {
|
|
69
72
|
errors,
|
|
@@ -112,6 +115,7 @@ export async function createInlineUpdates(pkg, validate, filePatterns, parsingFl
|
|
|
112
115
|
file,
|
|
113
116
|
includeSourceCodeContext: parsingFlags.includeSourceCodeContext,
|
|
114
117
|
enableAutoJsxInjection: true,
|
|
118
|
+
autoderive: autoderive.jsx,
|
|
115
119
|
},
|
|
116
120
|
output: {
|
|
117
121
|
errors,
|
package/dist/types/parsing.d.ts
CHANGED
|
@@ -30,15 +30,31 @@ export type BaseParsingFlags = Record<string, unknown>;
|
|
|
30
30
|
* parsing features depending on the function being parsed. Parsing flags is for users to override
|
|
31
31
|
* some of these defaults or enable/disable other features.
|
|
32
32
|
*
|
|
33
|
-
* @property {boolean} autoderive - Whether to enable autoderive
|
|
33
|
+
* @property {boolean | { jsx?: boolean; strings?: boolean }} autoderive - Whether to enable autoderive. A plain boolean enables/disables both JSX and strings. An object enables selectively.
|
|
34
34
|
* @property {boolean} includeSourceCodeContext - Include surrounding source code lines as context for translations.
|
|
35
35
|
* @property {boolean} enableAutoJsxInjection - Whether to enable auto-jsx injection for the internal <_T> and <_Var> components.
|
|
36
36
|
*/
|
|
37
37
|
export type GTParsingFlags = BaseParsingFlags & {
|
|
38
|
-
autoderive: boolean
|
|
38
|
+
autoderive: boolean | {
|
|
39
|
+
jsx?: boolean;
|
|
40
|
+
strings?: boolean;
|
|
41
|
+
};
|
|
39
42
|
includeSourceCodeContext: boolean;
|
|
40
43
|
enableAutoJsxInjection: boolean;
|
|
41
44
|
};
|
|
45
|
+
/**
|
|
46
|
+
* Resolves the autoderive config value into separate jsx and strings flags.
|
|
47
|
+
* - `true` enables both (backward compatible)
|
|
48
|
+
* - `false` disables both (backward compatible)
|
|
49
|
+
* - `{ jsx?: boolean; strings?: boolean }` enables selectively (missing keys default to false)
|
|
50
|
+
*/
|
|
51
|
+
export declare function resolveAutoderive(value: boolean | {
|
|
52
|
+
jsx?: boolean;
|
|
53
|
+
strings?: boolean;
|
|
54
|
+
} | undefined): {
|
|
55
|
+
jsx: boolean;
|
|
56
|
+
strings: boolean;
|
|
57
|
+
};
|
|
42
58
|
/**
|
|
43
59
|
* Flags for parsing content with each filetype having its own flags
|
|
44
60
|
* This is really a helper type that helps us map across filetypes
|
package/dist/types/parsing.js
CHANGED
|
@@ -1 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Resolves the autoderive config value into separate jsx and strings flags.
|
|
3
|
+
* - `true` enables both (backward compatible)
|
|
4
|
+
* - `false` disables both (backward compatible)
|
|
5
|
+
* - `{ jsx?: boolean; strings?: boolean }` enables selectively (missing keys default to false)
|
|
6
|
+
*/
|
|
7
|
+
export function resolveAutoderive(value) {
|
|
8
|
+
if (value === undefined || typeof value === 'boolean') {
|
|
9
|
+
return { jsx: !!value, strings: !!value };
|
|
10
|
+
}
|
|
11
|
+
return { jsx: value.jsx ?? false, strings: value.strings ?? false };
|
|
12
|
+
}
|