gtx-cli 2.5.49 → 2.6.0

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,11 @@
1
1
  # gtx-cli
2
2
 
3
+ ## 2.6.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#958](https://github.com/generaltranslation/gt/pull/958) [`c64d5d1`](https://github.com/generaltranslation/gt/commit/c64d5d1bc7fda78294e09b93c4a4e08d576409fc) Thanks [@pie575](https://github.com/pie575)! - CLI New Default Workflow
8
+
3
9
  ## 2.5.49
4
10
 
5
11
  ### Patch Changes
package/README.md CHANGED
@@ -1,67 +1,39 @@
1
1
  <p align="center">
2
- <a href="https://generaltranslation.com" target="_blank">
3
- <img src="https://generaltranslation.com/gt-logo-light.svg" alt="General Translation" width="100" height="100">
2
+ <a href="https://generaltranslation.com/docs/cli">
3
+ <picture>
4
+ <source media="(prefers-color-scheme: dark)" srcset="https://generaltranslation.com/gt-logo-dark.svg">
5
+ <source media="(prefers-color-scheme: light)" srcset="https://generaltranslation.com/gt-logo-light.svg">
6
+ <img alt="General Translation" src="https://generaltranslation.com/gt-logo-light.svg" width="100" height="100">
7
+ </picture>
4
8
  </a>
5
9
  </p>
6
10
 
7
- # gtx-cli: General Purpose CLI Tool for General Translation
11
+ <p align="center">
12
+ <a href="https://generaltranslation.com/docs/cli"><strong>Documentation</strong></a> · <a href="https://github.com/generaltranslation/gt/issues">Report Bug</a>
13
+ </p>
8
14
 
9
- gtx-cli is a command-line tool used to interface with General Translation's AI-powered i18n platform.
15
+ # gtx-cli
10
16
 
11
- See our [docs](https://generaltranslation.com/docs) for more information including guides, examples, and API references.
17
+ Command-line tool for General Translation's i18n platform.
12
18
 
13
19
  ## Installation
14
20
 
15
21
  ```bash
16
- npm install gtx-cli
17
- ```
18
-
19
- ## Usage
20
-
21
- ### Set up
22
-
23
- For more details, check out the [setup command documentation](https://generaltranslation.com/docs/cli/setup).
24
-
25
- If you are using gt-react or gt-next, run this command to automatically insert `<T>` components into your project.
26
-
27
- ```bash
28
- npx gtx-cli setup
22
+ npm install gtx-cli --save-dev
29
23
  ```
30
24
 
31
- ### Init
32
-
33
- For more details, check out the [init command documentation](https://generaltranslation.com/docs/cli/init).
25
+ ## Quick Start
34
26
 
35
- This command sets up your `gt.config.json` file.
36
- You will need to run this command in order to run the translate command.
27
+ Set up your project:
37
28
 
38
29
  ```bash
39
30
  npx gtx-cli init
40
31
  ```
41
32
 
42
- ### Translation
43
-
44
- For more details, check out the [translate command documentation](https://generaltranslation.com/docs/cli/translate).
45
-
46
- Before deploying to production, you need to generate translations.
47
- First, add your [production api keys](https://generaltranslation.com/dashboard):
48
-
49
- ```bash
50
- GT_API_KEY=your-production-api-key
51
- GT_PROJECT_ID=your-project-id
52
- ```
53
-
54
- Next run the translate command.
55
- This will generate translations and either publish them to the CDN or save them in your project depending on your configuration.
33
+ Generate translations:
56
34
 
57
35
  ```bash
58
36
  npx gtx-cli translate
59
37
  ```
60
38
 
61
- ## Documentation
62
-
63
- Full documentation, including guides, examples, and API references, can be found at [General Translation Docs](generaltranslation.com/docs).
64
-
65
- ## Contributing
66
-
67
- We welcome any contributions to our libraries. Please submit a pull request!
39
+ See the [full documentation](https://generaltranslation.com/docs/cli) for guides and API reference.
@@ -1,5 +1,5 @@
1
1
  import { Command } from 'commander';
2
- import { Settings, ReactFrameworkObject, SupportedLibraries, SetupOptions, TranslateFlags } from '../types/index.js';
2
+ import { Settings, SupportedLibraries, TranslateFlags } from '../types/index.js';
3
3
  export type UploadOptions = {
4
4
  config?: string;
5
5
  apiKey?: string;
@@ -28,7 +28,6 @@ export declare class BaseCLI {
28
28
  protected setupInitCommand(): void;
29
29
  protected setupConfigureCommand(): void;
30
30
  protected handleUploadCommand(settings: Settings & UploadOptions): Promise<void>;
31
- protected handleSetupReactCommand(options: SetupOptions, frameworkObject: ReactFrameworkObject): Promise<void>;
32
- protected handleInitCommand(ranReactSetup: boolean): Promise<void>;
31
+ protected handleInitCommand(ranReactSetup: boolean, useDefaults?: boolean): Promise<void>;
33
32
  protected handleLoginCommand(options: LoginOptions): Promise<void>;
34
33
  }
package/dist/cli/base.js CHANGED
@@ -207,18 +207,34 @@ export class BaseCLI {
207
207
  logger.endCommand('Once installed, Locadex will open a PR to your repository. See the docs for more information: https://generaltranslation.com/docs/locadex');
208
208
  }
209
209
  else {
210
+ // Get framework display info for the defaults message
211
+ const frameworkDisplayName = framework.type === 'react'
212
+ ? getFrameworkDisplayName(framework)
213
+ : null;
214
+ const library = framework.type === 'react'
215
+ ? getReactFrameworkLibrary(framework)
216
+ : null;
217
+ // Build defaults description based on detected framework
218
+ const defaultsDescription = framework.type === 'react'
219
+ ? `${library} & GTProvider, ${frameworkDisplayName}, Files saved locally in ./public/_gt`
220
+ : 'Files saved locally in ./public/_gt';
221
+ // Ask if user wants to use defaults
222
+ const useDefaults = await promptConfirm({
223
+ message: `Would you like to use the recommended General Translation defaults? ${chalk.dim(`(${defaultsDescription})`)}`,
224
+ defaultValue: true,
225
+ });
210
226
  let ranReactSetup = false;
211
227
  // so that people can run init in non-js projects
212
228
  if (framework.type === 'react') {
213
- const frameworkDisplayName = getFrameworkDisplayName(framework);
214
- const library = getReactFrameworkLibrary(framework);
215
- const wrap = await promptConfirm({
216
- message: `${frameworkDisplayName} detected. Would you like to install ${library} and add the GTProvider? See the docs for more information: https://generaltranslation.com/docs/react/tutorials/quickstart`,
217
- defaultValue: true,
218
- });
229
+ const wrap = useDefaults
230
+ ? true
231
+ : await promptConfirm({
232
+ message: `Would you like to install ${library} and add the GTProvider? See the docs for more information: https://generaltranslation.com/docs/react/tutorials/quickstart`,
233
+ defaultValue: true,
234
+ });
219
235
  if (wrap) {
220
236
  logger.info(`${chalk.yellow('[EXPERIMENTAL]')} Configuring project...`);
221
- await this.handleSetupReactCommand(options, framework);
237
+ await handleSetupReactCommand(options, framework, useDefaults);
222
238
  logger.endCommand(`Done! Since this wizard is experimental, please review the changes and make modifications as needed.
223
239
  \nNext step: start internationalizing! See the docs for more information: https://generaltranslation.com/docs/react/tutorials/quickstart`);
224
240
  ranReactSetup = true;
@@ -228,7 +244,7 @@ export class BaseCLI {
228
244
  logger.startCommand('Setting up project config...');
229
245
  }
230
246
  // Configure gt.config.json
231
- await this.handleInitCommand(ranReactSetup);
247
+ await this.handleInitCommand(ranReactSetup, useDefaults);
232
248
  logger.endCommand('Done! Check out our docs for more information on how to use General Translation: https://generaltranslation.com/docs');
233
249
  }
234
250
  });
@@ -269,12 +285,9 @@ export class BaseCLI {
269
285
  // Process all file types at once with a single call
270
286
  await upload(sourceFiles, placeholderPaths, transformPaths, dataFormat, settings);
271
287
  }
272
- async handleSetupReactCommand(options, frameworkObject) {
273
- await handleSetupReactCommand(options, frameworkObject);
274
- }
275
288
  // Wizard for configuring gt.config.json
276
- async handleInitCommand(ranReactSetup) {
277
- const { defaultLocale, locales } = await getDesiredLocales();
289
+ async handleInitCommand(ranReactSetup, useDefaults = false) {
290
+ const { defaultLocale, locales } = await getDesiredLocales(); // Locales should still be asked for even if using defaults
278
291
  const packageJson = await searchForPackageJson();
279
292
  const isUsingGTNext = packageJson
280
293
  ? isPackageInstalled('gt-next', packageJson)
@@ -288,6 +301,8 @@ export class BaseCLI {
288
301
  const usingCDN = await (async () => {
289
302
  if (!isUsingGT)
290
303
  return false;
304
+ if (useDefaults)
305
+ return false; // Default to local
291
306
  const selectedValue = await promptSelect({
292
307
  message: `Would you like to save translation files locally or use the General Translation CDN to store them?`,
293
308
  options: [
@@ -300,10 +315,12 @@ export class BaseCLI {
300
315
  })();
301
316
  // Ask where the translations are stored
302
317
  const translationsDir = isUsingGT && !usingCDN
303
- ? await promptText({
304
- message: 'What is the path to the directory where you would like to store your translation files?',
305
- defaultValue: './public/_gt',
306
- })
318
+ ? useDefaults
319
+ ? './public/_gt'
320
+ : await promptText({
321
+ message: 'What is the path to the directory where you would like to store your translation files?',
322
+ defaultValue: './public/_gt',
323
+ })
307
324
  : null;
308
325
  // Determine final translations directory with fallback
309
326
  const finalTranslationsDir = translationsDir?.trim() || './public/_gt';
@@ -317,18 +334,20 @@ See https://generaltranslation.com/en/docs/next/guides/local-tx`);
317
334
  const message = !isUsingGT
318
335
  ? 'What is the format of your language resource files? Select as many as applicable.\nAdditionally, you can translate any other files you have in your project.'
319
336
  : `Do you have any additional files in this project to translate? For example, Markdown files for docs. ${chalk.dim('(To continue without selecting press Enter)')}`;
320
- const fileExtensions = await promptMultiSelect({
321
- message,
322
- options: [
323
- { value: 'json', label: FILE_EXT_TO_EXT_LABEL.json },
324
- { value: 'md', label: FILE_EXT_TO_EXT_LABEL.md },
325
- { value: 'mdx', label: FILE_EXT_TO_EXT_LABEL.mdx },
326
- { value: 'ts', label: FILE_EXT_TO_EXT_LABEL.ts },
327
- { value: 'js', label: FILE_EXT_TO_EXT_LABEL.js },
328
- { value: 'yaml', label: FILE_EXT_TO_EXT_LABEL.yaml },
329
- ],
330
- required: !isUsingGT,
331
- });
337
+ const fileExtensions = useDefaults && isUsingGT
338
+ ? [] // Skip for GT projects when using defaults
339
+ : await promptMultiSelect({
340
+ message,
341
+ options: [
342
+ { value: 'json', label: FILE_EXT_TO_EXT_LABEL.json },
343
+ { value: 'md', label: FILE_EXT_TO_EXT_LABEL.md },
344
+ { value: 'mdx', label: FILE_EXT_TO_EXT_LABEL.mdx },
345
+ { value: 'ts', label: FILE_EXT_TO_EXT_LABEL.ts },
346
+ { value: 'js', label: FILE_EXT_TO_EXT_LABEL.js },
347
+ { value: 'yaml', label: FILE_EXT_TO_EXT_LABEL.yaml },
348
+ ],
349
+ required: !isUsingGT,
350
+ });
332
351
  const files = {};
333
352
  for (const fileExtension of fileExtensions) {
334
353
  const paths = await promptText({
@@ -370,10 +389,12 @@ See https://generaltranslation.com/en/docs/next/guides/local-tx`);
370
389
  }
371
390
  // Set credentials
372
391
  if (!areCredentialsSet()) {
373
- const loginQuestion = await promptConfirm({
374
- message: `Would you like the wizard to automatically generate a ${isUsingGT ? 'development' : 'production'} API key and project ID for you?`,
375
- defaultValue: true,
376
- });
392
+ const loginQuestion = useDefaults
393
+ ? true
394
+ : await promptConfirm({
395
+ message: `Would you like the wizard to automatically generate a ${isUsingGT ? 'development' : 'production'} API key and project ID for you?`,
396
+ defaultValue: true,
397
+ });
377
398
  if (loginQuestion) {
378
399
  const settings = await generateSettings({});
379
400
  const keyType = isUsingGT ? 'development' : 'production';
@@ -1 +1 @@
1
- export declare const PACKAGE_VERSION = "2.5.49";
1
+ export declare const PACKAGE_VERSION = "2.6.0";
@@ -1,2 +1,2 @@
1
1
  // This file is auto-generated. Do not edit manually.
2
- export const PACKAGE_VERSION = '2.5.49';
2
+ export const PACKAGE_VERSION = '2.6.0';
@@ -1,3 +1,3 @@
1
1
  import { SetupOptions } from '../types/index.js';
2
2
  import { ReactFrameworkObject } from '../types/index.js';
3
- export declare function handleSetupReactCommand(options: SetupOptions, frameworkObject: ReactFrameworkObject): Promise<void>;
3
+ export declare function handleSetupReactCommand(options: SetupOptions, frameworkObject: ReactFrameworkObject, useDefaults?: boolean): Promise<void>;
@@ -15,35 +15,39 @@ import { loadConfig } from '../fs/config/loadConfig.js';
15
15
  import { addVitePlugin } from '../react/parse/addVitePlugin/index.js';
16
16
  import { exitSync } from '../console/logging.js';
17
17
  import { getFrameworkDisplayName } from './frameworkUtils.js';
18
- export async function handleSetupReactCommand(options, frameworkObject) {
18
+ export async function handleSetupReactCommand(options, frameworkObject, useDefaults = false) {
19
19
  const frameworkDisplayName = getFrameworkDisplayName(frameworkObject);
20
20
  // Ask user for confirmation using inquirer
21
- const answer = await promptConfirm({
22
- message: chalk.yellow(`This wizard will configure your ${frameworkDisplayName} project for internationalization with GT. If your project is already using a different i18n library, this wizard may cause issues.
21
+ if (!useDefaults) {
22
+ const answer = await promptConfirm({
23
+ message: chalk.yellow(`This wizard will configure your ${frameworkDisplayName} project for internationalization with GT. If your project is already using a different i18n library, this wizard may cause issues.
23
24
 
24
25
  Make sure you have committed or stashed any changes. Do you want to continue?`),
25
- defaultValue: true,
26
- cancelMessage: 'Operation cancelled. You can re-run this wizard with: npx gtx-cli setup',
27
- });
28
- if (!answer) {
29
- logger.info('Operation cancelled. You can re-run this wizard with: npx gtx-cli setup');
30
- exitSync(0);
26
+ defaultValue: true,
27
+ cancelMessage: 'Operation cancelled. You can re-run this wizard with: npx gtx-cli setup',
28
+ });
29
+ if (!answer) {
30
+ logger.info('Operation cancelled. You can re-run this wizard with: npx gtx-cli setup');
31
+ exitSync(0);
32
+ }
31
33
  }
32
- const frameworkType = await promptSelect({
33
- message: 'Which framework are you using?',
34
- options: [
35
- { value: 'next-app', label: chalk.blue('Next.js App Router') },
36
- { value: 'next-pages', label: chalk.green('Next.js Pages Router') },
37
- { value: 'vite', label: chalk.cyan('Vite + React') },
38
- { value: 'gatsby', label: chalk.magenta('Gatsby') },
39
- { value: 'react', label: chalk.yellow('React') },
40
- { value: 'redwood', label: chalk.red('RedwoodJS') },
41
- { value: 'other', label: chalk.dim('Other') },
42
- ],
43
- defaultValue: frameworkObject?.name || 'other',
44
- });
34
+ const frameworkType = useDefaults && frameworkObject?.name
35
+ ? frameworkObject.name
36
+ : await promptSelect({
37
+ message: 'Which framework are you using?',
38
+ options: [
39
+ { value: 'next-app', label: chalk.blue('Next.js App Router') },
40
+ { value: 'next-pages', label: chalk.green('Next.js Pages Router') },
41
+ { value: 'vite', label: chalk.cyan('Vite + React') },
42
+ { value: 'gatsby', label: chalk.magenta('Gatsby') },
43
+ { value: 'react', label: chalk.yellow('React') },
44
+ { value: 'redwood', label: chalk.red('RedwoodJS') },
45
+ { value: 'other', label: chalk.dim('Other') },
46
+ ],
47
+ defaultValue: frameworkObject?.name || 'other',
48
+ });
45
49
  if (frameworkType === 'other') {
46
- logger.error(`Sorry, the wizard doesn't currently support other React frameworks.
50
+ logger.error(`Sorry, the wizard doesn't currently support other React frameworks.
47
51
  Please let us know what you would like to see added at https://github.com/generaltranslation/gt/issues`);
48
52
  exitSync(0);
49
53
  }
@@ -130,10 +134,12 @@ Please let us know what you would like to see added at https://github.com/genera
130
134
  if (!formatter || filesUpdated.length === 0) {
131
135
  return;
132
136
  }
133
- const applyFormatting = await promptConfirm({
134
- message: `Would you like the wizard to auto-format the modified files? ${chalk.dim(`(${formatter})`)}`,
135
- defaultValue: true,
136
- });
137
+ const applyFormatting = useDefaults
138
+ ? true
139
+ : await promptConfirm({
140
+ message: `Would you like the wizard to auto-format the modified files? ${chalk.dim(`(${formatter})`)}`,
141
+ defaultValue: true,
142
+ });
137
143
  // Format updated files if formatters are available
138
144
  if (applyFormatting)
139
145
  await formatFiles(filesUpdated, formatter);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gtx-cli",
3
- "version": "2.5.49",
3
+ "version": "2.6.0",
4
4
  "main": "dist/index.js",
5
5
  "bin": "dist/main.js",
6
6
  "files": [