gtx-cli 1.2.23 → 1.2.24-alpha.2

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/LICENSE.md CHANGED
@@ -6,7 +6,7 @@ FSL-1.1-ALv2
6
6
 
7
7
  ## Notice
8
8
 
9
- Copyright 2024 General Translation, Inc.
9
+ Copyright 2025 General Translation, Inc.
10
10
 
11
11
  ## Terms and Conditions
12
12
 
@@ -1,3 +1,4 @@
1
+ import { Command } from 'commander';
1
2
  import { Settings, SupportedLibraries, SetupOptions } from '../types';
2
3
  export type TranslateOptions = {
3
4
  config?: string;
@@ -13,7 +14,8 @@ export type LoginOptions = {
13
14
  export declare class BaseCLI {
14
15
  protected library: SupportedLibraries;
15
16
  protected additionalModules: SupportedLibraries[];
16
- constructor(library: SupportedLibraries, additionalModules?: SupportedLibraries[]);
17
+ protected program: Command;
18
+ constructor(program: Command, library: SupportedLibraries, additionalModules?: SupportedLibraries[]);
17
19
  init(): void;
18
20
  execute(): void;
19
21
  protected setupGTCommand(): void;
package/dist/cli/base.js CHANGED
@@ -37,8 +37,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.BaseCLI = void 0;
40
- const commander_1 = require("commander");
41
- const setupConfig_1 = __importDefault(require("../fs/config/setupConfig"));
40
+ const setupConfig_1 = require("../fs/config/setupConfig");
42
41
  const findFilepath_1 = __importStar(require("../fs/findFilepath"));
43
42
  const console_1 = require("../console");
44
43
  const node_path_1 = __importDefault(require("node:path"));
@@ -57,8 +56,10 @@ const credentials_2 = require("../utils/credentials");
57
56
  class BaseCLI {
58
57
  library;
59
58
  additionalModules;
59
+ program;
60
60
  // Constructor is shared amongst all CLI class types
61
- constructor(library, additionalModules) {
61
+ constructor(program, library, additionalModules) {
62
+ this.program = program;
62
63
  this.library = library;
63
64
  this.additionalModules = additionalModules || [];
64
65
  this.setupInitCommand();
@@ -76,10 +77,9 @@ class BaseCLI {
76
77
  if (process.argv.length <= 2) {
77
78
  process.argv.push('init');
78
79
  }
79
- commander_1.program.parse();
80
80
  }
81
81
  setupGTCommand() {
82
- commander_1.program
82
+ this.program
83
83
  .command('translate')
84
84
  .description('Translate your project using General Translation')
85
85
  .option('-c, --config <path>', 'Filepath to config file, by default gt.config.json', (0, findFilepath_1.default)(['gt.config.json']))
@@ -97,7 +97,7 @@ class BaseCLI {
97
97
  });
98
98
  }
99
99
  setupLoginCommand() {
100
- commander_1.program
100
+ this.program
101
101
  .command('auth')
102
102
  .description('Generate a General Translation API key and project ID')
103
103
  .option('-c, --config <path>', 'Filepath to config file, by default gt.config.json', (0, findFilepath_1.default)(['gt.config.json']))
@@ -130,7 +130,7 @@ class BaseCLI {
130
130
  });
131
131
  }
132
132
  setupInitCommand() {
133
- commander_1.program
133
+ this.program
134
134
  .command('init')
135
135
  .description('Run the setup wizard to configure your project for General Translation')
136
136
  .option('--src <paths...>', "Filepath to directory containing the app's source code, by default ./src || ./app || ./pages || ./components", (0, findFilepath_1.findFilepaths)(['./src', './app', './pages', './components']))
@@ -163,7 +163,7 @@ See the docs for more information: https://generaltranslation.com/docs/react/tut
163
163
  });
164
164
  }
165
165
  setupConfigureCommand() {
166
- commander_1.program
166
+ this.program
167
167
  .command('configure')
168
168
  .description('Configure your project for General Translation. This will create a gt.config.json file in your codebase.')
169
169
  .action(async () => {
@@ -175,7 +175,7 @@ See the docs for more information: https://generaltranslation.com/docs/react/tut
175
175
  });
176
176
  }
177
177
  setupSetupCommand() {
178
- commander_1.program
178
+ this.program
179
179
  .command('setup')
180
180
  .description('Run the setup to configure your Next.js or React project for General Translation')
181
181
  .option('--src <paths...>', "Filepath to directory containing the app's source code, by default ./src || ./app || ./pages || ./components", (0, findFilepath_1.findFilepaths)(['./src', './app', './pages', './components']))
@@ -248,7 +248,7 @@ See the docs for more information: https://generaltranslation.com/docs/react/tut
248
248
  : null;
249
249
  const message = !isUsingGT
250
250
  ? '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.'
251
- : `${chalk_1.default.gray('(Optional)')} Do you have any separate files you would like to translate? For example, extra Markdown files for docs.`;
251
+ : `${chalk_1.default.dim('(Optional)')} Do you have any separate files you would like to translate? For example, extra Markdown files for docs.`;
252
252
  const dataFormats = await (0, console_1.promptMultiSelect)({
253
253
  message,
254
254
  options: [
@@ -281,7 +281,7 @@ See the docs for more information: https://generaltranslation.com/docs/react/tut
281
281
  configFilepath = 'src/gt.config.json';
282
282
  }
283
283
  // Create gt.config.json
284
- await (0, setupConfig_1.default)(configFilepath, {
284
+ await (0, setupConfig_1.createOrUpdateConfig)(configFilepath, {
285
285
  defaultLocale,
286
286
  locales,
287
287
  files: Object.keys(files).length > 0 ? files : undefined,
@@ -1,7 +1,8 @@
1
1
  import { WrapOptions, SupportedFrameworks, SupportedLibraries } from '../types';
2
2
  import { ReactCLI } from './react';
3
+ import { Command } from 'commander';
3
4
  export declare class NextCLI extends ReactCLI {
4
- constructor(library: 'gt-next', additionalModules?: SupportedLibraries[]);
5
+ constructor(command: Command, library: 'gt-next', additionalModules?: SupportedLibraries[]);
5
6
  init(): void;
6
7
  execute(): void;
7
8
  protected wrapContent(options: WrapOptions, framework: SupportedFrameworks, errors: string[], warnings: string[]): Promise<{
package/dist/cli/next.js CHANGED
@@ -1,15 +1,12 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.NextCLI = void 0;
7
4
  const react_1 = require("./react");
8
- const wrapContent_1 = __importDefault(require("../next/parse/wrapContent"));
5
+ const wrapContent_1 = require("../next/parse/wrapContent");
9
6
  const pkg = 'gt-next';
10
7
  class NextCLI extends react_1.ReactCLI {
11
- constructor(library, additionalModules) {
12
- super(library, additionalModules);
8
+ constructor(command, library, additionalModules) {
9
+ super(command, library, additionalModules);
13
10
  }
14
11
  init() {
15
12
  this.setupStageCommand();
@@ -21,7 +18,7 @@ class NextCLI extends react_1.ReactCLI {
21
18
  super.execute();
22
19
  }
23
20
  wrapContent(options, framework, errors, warnings) {
24
- return (0, wrapContent_1.default)(options, pkg, errors, warnings);
21
+ return (0, wrapContent_1.wrapContentNext)(options, pkg, errors, warnings);
25
22
  }
26
23
  }
27
24
  exports.NextCLI = NextCLI;
@@ -1,7 +1,8 @@
1
+ import { Command } from 'commander';
1
2
  import { Options, SupportedFrameworks, WrapOptions, GenerateSourceOptions, SupportedLibraries } from '../types';
2
3
  import { BaseCLI } from './base';
3
4
  export declare class ReactCLI extends BaseCLI {
4
- constructor(library: 'gt-react' | 'gt-next', additionalModules?: SupportedLibraries[]);
5
+ constructor(command: Command, library: 'gt-react' | 'gt-next', additionalModules?: SupportedLibraries[]);
5
6
  init(): void;
6
7
  execute(): void;
7
8
  protected wrapContent(options: WrapOptions, framework: SupportedFrameworks, errors: string[], warnings: string[]): Promise<{
package/dist/cli/react.js CHANGED
@@ -37,15 +37,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.ReactCLI = void 0;
40
- // packages/gt-cli-core/src/BaseCLI.ts
41
- const commander_1 = require("commander");
42
40
  const console_1 = require("../console/console");
43
41
  const loadJSON_1 = __importDefault(require("../fs/loadJSON"));
44
42
  const findFilepath_1 = __importStar(require("../fs/findFilepath"));
45
43
  const chalk_1 = __importDefault(require("chalk"));
46
44
  const postProcess_1 = require("../hooks/postProcess");
47
45
  const base_1 = require("./base");
48
- const wrapContent_1 = __importDefault(require("../react/parse/wrapContent"));
46
+ const wrapContent_1 = require("../react/parse/wrapContent");
49
47
  const generateSettings_1 = require("../config/generateSettings");
50
48
  const saveJSON_1 = require("../fs/saveJSON");
51
49
  const parseFilesConfig_1 = require("../fs/config/parseFilesConfig");
@@ -57,8 +55,8 @@ const updateConfig_1 = __importDefault(require("../fs/config/updateConfig"));
57
55
  const DEFAULT_TIMEOUT = 600;
58
56
  const pkg = 'gt-react';
59
57
  class ReactCLI extends base_1.BaseCLI {
60
- constructor(library, additionalModules) {
61
- super(library, additionalModules);
58
+ constructor(command, library, additionalModules) {
59
+ super(command, library, additionalModules);
62
60
  }
63
61
  init() {
64
62
  this.setupStageCommand();
@@ -70,10 +68,10 @@ class ReactCLI extends base_1.BaseCLI {
70
68
  super.execute();
71
69
  }
72
70
  wrapContent(options, framework, errors, warnings) {
73
- return (0, wrapContent_1.default)(options, pkg, framework, errors, warnings);
71
+ return (0, wrapContent_1.wrapContentReact)(options, pkg, framework, errors, warnings);
74
72
  }
75
73
  setupStageCommand() {
76
- commander_1.program
74
+ this.program
77
75
  .command('stage')
78
76
  .description('Submits the project to the General Translation API for translation. Translations created using this command will require human approval.')
79
77
  .option('-c, --config <path>', 'Filepath to config file, by default gt.config.json', (0, findFilepath_1.default)(['gt.config.json']))
@@ -96,7 +94,7 @@ class ReactCLI extends base_1.BaseCLI {
96
94
  });
97
95
  }
98
96
  setupTranslateCommand() {
99
- commander_1.program
97
+ this.program
100
98
  .command('translate')
101
99
  .description('Scans the project for a dictionary and/or <T> tags, and sends the updates to the General Translation API for translation.')
102
100
  .option('-c, --config <path>', 'Filepath to config file, by default gt.config.json', (0, findFilepath_1.default)(['gt.config.json']))
@@ -119,7 +117,7 @@ class ReactCLI extends base_1.BaseCLI {
119
117
  });
120
118
  }
121
119
  setupGenerateSourceCommand() {
122
- commander_1.program
120
+ this.program
123
121
  .command('generate')
124
122
  .description('Generate a translation file for the source locale. The -t flag must be provided. This command should be used if you are handling your own translations.')
125
123
  .option('--src <paths...>', "Filepath to directory containing the app's source code, by default ./src || ./app || ./pages || ./components")
@@ -136,13 +134,14 @@ class ReactCLI extends base_1.BaseCLI {
136
134
  });
137
135
  }
138
136
  setupScanCommand() {
139
- commander_1.program
137
+ this.program
140
138
  .command('scan')
141
139
  .description('Scans the project and wraps all JSX elements in the src directory with a <T> tag, with unique ids')
142
140
  .option('--src <paths...>', "Filepath to directory containing the app's source code, by default ./src || ./app || ./pages || ./components", (0, findFilepath_1.findFilepaths)(['./src', './app', './pages', './components']))
143
141
  .option('-c, --config <path>', 'Filepath to config file, by default gt.config.json', (0, findFilepath_1.default)(['gt.config.json']))
144
142
  .option('--disable-ids', 'Disable id generation for the <T> tags', false)
145
143
  .option('--disable-formatting', 'Disable formatting of edited files', false)
144
+ .option('--skip-ts', 'Skip wrapping <T> tags in TypeScript files', false)
146
145
  .action(async (options) => {
147
146
  (0, console_1.displayHeader)('Scanning project...');
148
147
  await this.handleScanCommand(options);
@@ -173,7 +172,7 @@ class ReactCLI extends base_1.BaseCLI {
173
172
  .join('\n')));
174
173
  }
175
174
  else {
176
- (0, console_1.logErrorAndExit)(chalk_1.default.red(`CLI tool encountered errors while scanning for translatable content. ${chalk_1.default.gray('To ignore these errors, re-run with --ignore-errors')}\n` +
175
+ (0, console_1.logErrorAndExit)(chalk_1.default.red(`CLI tool encountered errors while scanning for translatable content. ${chalk_1.default.dim('To ignore these errors, re-run with --ignore-errors')}\n` +
177
176
  errors
178
177
  .map((error) => chalk_1.default.red('• Error: ') + chalk_1.default.white(error))
179
178
  .join('\n')));
@@ -9,7 +9,7 @@ const warnings_1 = require("../console/warnings");
9
9
  const loadConfig_1 = __importDefault(require("../fs/config/loadConfig"));
10
10
  const internal_1 = require("generaltranslation/internal");
11
11
  const node_fs_1 = __importDefault(require("node:fs"));
12
- const setupConfig_1 = __importDefault(require("../fs/config/setupConfig"));
12
+ const setupConfig_1 = require("../fs/config/setupConfig");
13
13
  const parseFilesConfig_1 = require("../fs/config/parseFilesConfig");
14
14
  const findFilepath_1 = require("../fs/findFilepath");
15
15
  const validateSettings_1 = require("./validateSettings");
@@ -82,7 +82,7 @@ async function generateSettings(options) {
82
82
  // if there's no existing config file, creates one
83
83
  // does not include the API key to avoid exposing it
84
84
  if (!node_fs_1.default.existsSync(mergedOptions.config)) {
85
- await (0, setupConfig_1.default)(mergedOptions.config, {
85
+ await (0, setupConfig_1.createOrUpdateConfig)(mergedOptions.config, {
86
86
  projectId: mergedOptions.projectId,
87
87
  defaultLocale: mergedOptions.defaultLocale,
88
88
  locales: mergedOptions.locales?.length > 0 ? mergedOptions.locales : undefined,
@@ -22,5 +22,5 @@ function colorizeContent(content) {
22
22
  return chalk_1.default.yellow(content);
23
23
  }
24
24
  function colorizeLine(line) {
25
- return chalk_1.default.gray(line);
25
+ return chalk_1.default.dim(line);
26
26
  }
@@ -12,11 +12,7 @@ export declare function displayProjectId(projectId: string): void;
12
12
  export declare function displayResolvedPaths(resolvedPaths: [string, string][]): void;
13
13
  export declare function displayCreatedConfigFile(configFilepath: string): void;
14
14
  export declare function displayUpdatedConfigFile(configFilepath: string): void;
15
- export declare function createSpinner(indicator?: 'dots' | 'timer'): {
16
- start: (msg?: string) => void;
17
- stop: (msg?: string, code?: number) => void;
18
- message: (msg?: string) => void;
19
- };
15
+ export declare function createSpinner(indicator?: 'dots' | 'timer'): import("@clack/prompts", { with: { "resolution-mode": "import" } }).SpinnerResult;
20
16
  export declare function createOraSpinner(indicator?: 'dots' | 'circleHalves'): Promise<import("ora", { with: { "resolution-mode": "import" } }).Ora>;
21
17
  export declare function promptText({ message, defaultValue, validate, }: {
22
18
  message: string;
@@ -84,20 +84,20 @@ Y8, 88 88
84
84
  function displayInitializingText() {
85
85
  const version = (0, packageJson_1.getCLIVersion)();
86
86
  console.log(`\n${chalk_1.default.bold.blue('General Translation, Inc.')}
87
- ${chalk_1.default.gray('https://generaltranslation.com/docs')}
88
- ${chalk_1.default.gray(`CLI Version: ${version}\n`)}`);
87
+ ${chalk_1.default.dim('https://generaltranslation.com/docs')}
88
+ ${chalk_1.default.dim(`CLI Version: ${version}\n`)}`);
89
89
  }
90
90
  function displayProjectId(projectId) {
91
- logMessage(chalk_1.default.gray(`Project ID: ${chalk_1.default.bold(projectId)}`));
91
+ logMessage(chalk_1.default.dim(`Project ID: ${chalk_1.default.bold(projectId)}`));
92
92
  }
93
93
  function displayResolvedPaths(resolvedPaths) {
94
94
  const paths = resolvedPaths.map(([key, resolvedPath]) => {
95
- return chalk_1.default.gray(`'${chalk_1.default.white(key)}' → '${chalk_1.default.green(resolvedPath)}'`);
95
+ return chalk_1.default.dim(`'${chalk_1.default.white(key)}' → '${chalk_1.default.green(resolvedPath)}'`);
96
96
  });
97
97
  prompts_1.log.step(`Resolved path aliases:\n${paths.join('\n')}`);
98
98
  }
99
99
  function displayCreatedConfigFile(configFilepath) {
100
- prompts_1.log.success(`Created config file ${chalk_1.default.cyan(configFilepath)}`);
100
+ prompts_1.log.step(`Created config file ${chalk_1.default.cyan(configFilepath)}`);
101
101
  }
102
102
  function displayUpdatedConfigFile(configFilepath) {
103
103
  prompts_1.log.success(`Updated config file ${chalk_1.default.cyan(configFilepath)}`);
@@ -118,7 +118,7 @@ async function promptText({ message, defaultValue, validate, }) {
118
118
  placeholder: defaultValue,
119
119
  validate: validate
120
120
  ? (value) => {
121
- const validation = validate(value);
121
+ const validation = validate(value || '');
122
122
  return validation === true ? undefined : validation.toString();
123
123
  }
124
124
  : undefined,
@@ -6,7 +6,7 @@ import { FilesOptions, SupportedFrameworks } from '../../types';
6
6
  * @param {string} configFilepath - The path to the config file.
7
7
  * @param {Record<string, any>} configObject - The config object to write if the file does not exist.
8
8
  */
9
- export default function createOrUpdateConfig(configFilepath: string, options: {
9
+ export declare function createOrUpdateConfig(configFilepath: string, options: {
10
10
  projectId?: string;
11
11
  defaultLocale?: string;
12
12
  locales?: string[];
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.default = createOrUpdateConfig;
6
+ exports.createOrUpdateConfig = createOrUpdateConfig;
7
7
  const node_fs_1 = __importDefault(require("node:fs"));
8
8
  const console_1 = require("../../console");
9
9
  /**
@@ -54,7 +54,7 @@ async function formatFiles(filesUpdated, formatter) {
54
54
  return;
55
55
  }
56
56
  if (detectedFormatter === 'prettier') {
57
- (0, console_1.logMessage)(chalk_1.default.gray('Cleaning up with prettier...'));
57
+ (0, console_1.logMessage)(chalk_1.default.dim('Cleaning up with prettier...'));
58
58
  const prettier = require('prettier');
59
59
  for (const file of filesUpdated) {
60
60
  const config = await prettier.resolveConfig(file);
@@ -68,7 +68,7 @@ async function formatFiles(filesUpdated, formatter) {
68
68
  return;
69
69
  }
70
70
  if (detectedFormatter === 'biome') {
71
- (0, console_1.logMessage)(chalk_1.default.gray('Cleaning up with biome...'));
71
+ (0, console_1.logMessage)(chalk_1.default.dim('Cleaning up with biome...'));
72
72
  try {
73
73
  await new Promise((resolve, reject) => {
74
74
  const { spawn } = require('child_process');
@@ -99,7 +99,7 @@ async function formatFiles(filesUpdated, formatter) {
99
99
  return;
100
100
  }
101
101
  if (detectedFormatter === 'eslint') {
102
- (0, console_1.logMessage)(chalk_1.default.gray('Cleaning up with eslint...'));
102
+ (0, console_1.logMessage)(chalk_1.default.dim('Cleaning up with eslint...'));
103
103
  const { ESLint } = require('eslint');
104
104
  const eslint = new ESLint({
105
105
  fix: true,
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  import { BaseCLI } from './cli/base';
2
- export default function main(): void;
2
+ import { Command } from 'commander';
3
+ export declare function main(program: Command): void;
3
4
  export { BaseCLI };
package/dist/index.js CHANGED
@@ -1,23 +1,23 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BaseCLI = void 0;
4
- exports.default = main;
4
+ exports.main = main;
5
5
  const base_1 = require("./cli/base");
6
6
  Object.defineProperty(exports, "BaseCLI", { enumerable: true, get: function () { return base_1.BaseCLI; } });
7
7
  const next_1 = require("./cli/next");
8
8
  const react_1 = require("./cli/react");
9
9
  const determineFramework_1 = require("./fs/determineFramework");
10
- function main() {
10
+ function main(program) {
11
11
  const { library, additionalModules } = (0, determineFramework_1.determineLibrary)();
12
12
  let cli;
13
13
  if (library === 'gt-next') {
14
- cli = new next_1.NextCLI(library, additionalModules);
14
+ cli = new next_1.NextCLI(program, library, additionalModules);
15
15
  }
16
16
  else if (library === 'gt-react') {
17
- cli = new react_1.ReactCLI(library, additionalModules);
17
+ cli = new react_1.ReactCLI(program, library, additionalModules);
18
18
  }
19
19
  else {
20
- cli = new base_1.BaseCLI(library, additionalModules);
20
+ cli = new base_1.BaseCLI(program, library, additionalModules);
21
21
  }
22
22
  cli.init();
23
23
  cli.execute();
package/dist/main.js CHANGED
@@ -4,9 +4,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  return (mod && mod.__esModule) ? mod : { "default": mod };
5
5
  };
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- const index_1 = __importDefault(require("./index"));
7
+ const index_1 = require("./index");
8
8
  const dotenv_1 = __importDefault(require("dotenv"));
9
+ const commander_1 = require("commander");
9
10
  dotenv_1.default.config({ path: '.env' });
10
11
  dotenv_1.default.config({ path: '.env.local', override: true });
11
12
  dotenv_1.default.config({ path: '.env.production', override: true });
12
- (0, index_1.default)();
13
+ (0, index_1.main)(commander_1.program);
14
+ commander_1.program.parse();
@@ -1 +1 @@
1
- export default function handleInitGT(filepath: string, errors: string[], warnings: string[], filesUpdated: string[]): Promise<void>;
1
+ export declare function handleInitGT(filepath: string, errors: string[], warnings: string[], filesUpdated: string[]): Promise<void>;
@@ -36,7 +36,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
36
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.default = handleInitGT;
39
+ exports.handleInitGT = handleInitGT;
40
40
  const node_fs_1 = __importDefault(require("node:fs"));
41
41
  const parser_1 = require("@babel/parser");
42
42
  const generator_1 = __importDefault(require("@babel/generator"));
@@ -6,6 +6,6 @@ import { WrapOptions } from '../../types';
6
6
  * @param options - The options object
7
7
  * @returns An object containing the updates and errors
8
8
  */
9
- export default function wrapContentNext(options: WrapOptions, pkg: 'gt-next', errors: string[], warnings: string[]): Promise<{
9
+ export declare function wrapContentNext(options: WrapOptions, pkg: 'gt-next', errors: string[], warnings: string[]): Promise<{
10
10
  filesUpdated: string[];
11
11
  }>;
@@ -36,7 +36,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
36
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.default = wrapContentNext;
39
+ exports.wrapContentNext = wrapContentNext;
40
40
  const node_fs_1 = __importDefault(require("node:fs"));
41
41
  const t = __importStar(require("@babel/types"));
42
42
  const parser_1 = require("@babel/parser");
@@ -126,6 +126,10 @@ async function wrapContentNext(options, pkg, errors, warnings) {
126
126
  path.skip();
127
127
  return;
128
128
  }
129
+ // If skip wrapping Ts, skip processing this node
130
+ if (options.skipTs) {
131
+ return;
132
+ }
129
133
  // Check if this JSX element has any JSX element ancestors
130
134
  if (t.isJSXElement(path.parentPath?.node) ||
131
135
  t.isJSXExpressionContainer(path.parentPath?.node)) {
@@ -6,6 +6,6 @@ import { SupportedFrameworks, WrapOptions } from '../../types';
6
6
  * @param options - The options object
7
7
  * @returns An object containing the updates and errors
8
8
  */
9
- export default function wrapContentReact(options: WrapOptions, pkg: 'gt-react', framework: SupportedFrameworks, errors: string[], warnings: string[]): Promise<{
9
+ export declare function wrapContentReact(options: WrapOptions, pkg: 'gt-react', framework: SupportedFrameworks, errors: string[], warnings: string[]): Promise<{
10
10
  filesUpdated: string[];
11
11
  }>;
@@ -36,7 +36,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
36
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.default = wrapContentReact;
39
+ exports.wrapContentReact = wrapContentReact;
40
40
  const node_fs_1 = __importDefault(require("node:fs"));
41
41
  const node_path_1 = __importDefault(require("node:path"));
42
42
  const t = __importStar(require("@babel/types"));
@@ -16,7 +16,7 @@ async function getDesiredLocales() {
16
16
  });
17
17
  // Ask for the locales
18
18
  const locales = await (0, console_1.promptText)({
19
- message: `What locales would you like to translate your project into? ${chalk_1.default.gray('(space-separated list)')}`,
19
+ message: `What locales would you like to translate your project into? ${chalk_1.default.dim('(space-separated list)')}`,
20
20
  defaultValue: 'es zh fr de ja',
21
21
  validate: (input) => {
22
22
  const localeList = input.split(' ');
@@ -11,13 +11,13 @@ const chalk_1 = __importDefault(require("chalk"));
11
11
  const console_3 = require("../console");
12
12
  const findFilepath_1 = __importDefault(require("../fs/findFilepath"));
13
13
  const postProcess_2 = require("../hooks/postProcess");
14
- const handleInitGT_1 = __importDefault(require("../next/parse/handleInitGT"));
14
+ const handleInitGT_1 = require("../next/parse/handleInitGT");
15
15
  const packageJson_1 = require("../utils/packageJson");
16
- const wrapContent_1 = __importDefault(require("../react/parse/wrapContent"));
17
- const wrapContent_2 = __importDefault(require("../next/parse/wrapContent"));
16
+ const wrapContent_1 = require("../react/parse/wrapContent");
17
+ const wrapContent_2 = require("../next/parse/wrapContent");
18
18
  const packageManager_1 = require("../utils/packageManager");
19
19
  const installPackage_1 = require("../utils/installPackage");
20
- const setupConfig_1 = __importDefault(require("../fs/config/setupConfig"));
20
+ const setupConfig_1 = require("../fs/config/setupConfig");
21
21
  async function handleSetupReactCommand(options) {
22
22
  // Ask user for confirmation using inquirer
23
23
  const answer = await (0, console_3.promptConfirm)({
@@ -41,7 +41,7 @@ Make sure you have committed or stashed any changes. Do you want to continue?`),
41
41
  { value: 'gatsby', label: chalk_1.default.magenta('Gatsby') },
42
42
  { value: 'react', label: chalk_1.default.yellow('React') },
43
43
  { value: 'redwood', label: chalk_1.default.red('RedwoodJS') },
44
- { value: 'other', label: chalk_1.default.gray('Other') },
44
+ { value: 'other', label: chalk_1.default.dim('Other') },
45
45
  ],
46
46
  defaultValue: 'next-app',
47
47
  });
@@ -51,7 +51,7 @@ Please let us know what you would like to see supported at https://github.com/ge
51
51
  process.exit(0);
52
52
  }
53
53
  // ----- Create a starter gt.config.json file -----
54
- await (0, setupConfig_1.default)(options.config || 'gt.config.json', {
54
+ await (0, setupConfig_1.createOrUpdateConfig)(options.config || 'gt.config.json', {
55
55
  framework: frameworkType,
56
56
  });
57
57
  const packageJson = await (0, packageJson_1.getPackageJson)();
@@ -103,17 +103,18 @@ Please let us know what you would like to see supported at https://github.com/ge
103
103
  ...options,
104
104
  disableIds: !includeTId,
105
105
  disableFormatting: true,
106
+ skipTs: false,
106
107
  addGTProvider,
107
108
  };
108
109
  const spinner = (0, console_1.createSpinner)();
109
110
  spinner.start('Wrapping JSX content with <T> tags...');
110
111
  // Wrap all JSX elements in the src directory with a <T> tag, with unique ids
111
- const { filesUpdated: filesUpdatedNext } = await (0, wrapContent_2.default)(mergeOptions, 'gt-next', errors, warnings);
112
+ const { filesUpdated: filesUpdatedNext } = await (0, wrapContent_2.wrapContentNext)(mergeOptions, 'gt-next', errors, warnings);
112
113
  filesUpdated = [...filesUpdated, ...filesUpdatedNext];
113
114
  spinner.stop(chalk_1.default.green(`Success! Added <T> tags and updated ${chalk_1.default.bold.cyan(filesUpdated.length)} files:\n`) + filesUpdated.map((file) => `${chalk_1.default.green('-')} ${file}`).join('\n'));
114
115
  if (addWithGTConfig) {
115
116
  // Add the withGTConfig() function to the next.config.js file
116
- await (0, handleInitGT_1.default)(nextConfigPath, errors, warnings, filesUpdated);
117
+ await (0, handleInitGT_1.handleInitGT)(nextConfigPath, errors, warnings, filesUpdated);
117
118
  (0, console_2.logStep)(chalk_1.default.green(`Added withGTConfig() to your ${nextConfigPath} file.`));
118
119
  }
119
120
  if (errors.length > 0) {
@@ -138,12 +139,13 @@ Please let us know what you would like to see supported at https://github.com/ge
138
139
  ...options,
139
140
  disableIds: !includeTId,
140
141
  disableFormatting: true,
142
+ skipTs: false,
141
143
  addGTProvider,
142
144
  };
143
145
  const spinner = (0, console_1.createSpinner)();
144
146
  spinner.start('Wrapping JSX content with <T> tags...');
145
147
  // Wrap all JSX elements in the src directory with a <T> tag, with unique ids
146
- const { filesUpdated: filesUpdatedReact } = await (0, wrapContent_1.default)(mergeOptions, 'gt-react', frameworkType, errors, warnings);
148
+ const { filesUpdated: filesUpdatedReact } = await (0, wrapContent_1.wrapContentReact)(mergeOptions, 'gt-react', frameworkType, errors, warnings);
147
149
  filesUpdated = [...filesUpdated, ...filesUpdatedReact];
148
150
  spinner.stop(chalk_1.default.green(`Success! Added <T> tags and updated ${chalk_1.default.bold.cyan(filesUpdated.length)} files:\n`) + filesUpdated.map((file) => `${chalk_1.default.green('-')} ${file}`).join('\n'));
149
151
  if (errors.length > 0) {
@@ -162,7 +164,7 @@ Please let us know what you would like to see supported at https://github.com/ge
162
164
  return;
163
165
  }
164
166
  const applyFormatting = await (0, console_3.promptConfirm)({
165
- message: `Would you like the wizard to auto-format the modified files? ${chalk_1.default.gray(`(${formatter})`)}`,
167
+ message: `Would you like the wizard to auto-format the modified files? ${chalk_1.default.dim(`(${formatter})`)}`,
166
168
  defaultValue: true,
167
169
  });
168
170
  // Format updated files if formatters are available
@@ -40,7 +40,7 @@ async function stageProject(settings, pkg) {
40
40
  .join('')));
41
41
  }
42
42
  else {
43
- (0, errors_1.logErrorAndExit)(chalk_1.default.red(`Error: CLI tool encountered syntax errors while scanning for translatable content. ${chalk_1.default.gray('To ignore these errors, re-run with --ignore-errors')}\n` +
43
+ (0, errors_1.logErrorAndExit)(chalk_1.default.red(`Error: CLI tool encountered syntax errors while scanning for translatable content. ${chalk_1.default.dim('To ignore these errors, re-run with --ignore-errors')}\n` +
44
44
  errors
45
45
  .map((error) => chalk_1.default.red('• ') + chalk_1.default.white(error) + '\n')
46
46
  .join('')));
@@ -32,6 +32,7 @@ export type Options = {
32
32
  export type WrapOptions = {
33
33
  src: string[];
34
34
  config: string;
35
+ skipTs: boolean;
35
36
  disableIds: boolean;
36
37
  disableFormatting: boolean;
37
38
  addGTProvider: boolean;
@@ -19,7 +19,7 @@ async function retrieveCredentials(settings, keyType) {
19
19
  await import('open').then((open) => open.default(urlToOpen, {
20
20
  wait: false,
21
21
  }));
22
- (0, console_1.logMessage)(`${chalk_1.default.gray(`If the browser window didn't open automatically, please open the following link:`)}\n\n${chalk_1.default.cyan(urlToOpen)}`);
22
+ (0, console_1.logMessage)(`${chalk_1.default.dim(`If the browser window didn't open automatically, please open the following link:`)}\n\n${chalk_1.default.cyan(urlToOpen)}`);
23
23
  const spinner = (0, console_1.createSpinner)('dots');
24
24
  spinner.start('Waiting for response from dashboard...');
25
25
  const credentials = await new Promise(async (resolve, reject) => {
@@ -1,2 +1,3 @@
1
1
  import { PackageManager } from './packageManager';
2
2
  export declare function installPackage(packageName: string, packageManager: PackageManager, asDevDependency?: boolean): Promise<void>;
3
+ export declare function installPackageGlobal(packageName: string, version?: string): Promise<void>;
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.installPackage = installPackage;
7
+ exports.installPackageGlobal = installPackageGlobal;
7
8
  const chalk_1 = __importDefault(require("chalk"));
8
9
  const child_process_1 = require("child_process");
9
10
  const console_1 = require("../console");
@@ -43,3 +44,36 @@ async function installPackage(packageName, packageManager, asDevDependency) {
43
44
  });
44
45
  });
45
46
  }
47
+ async function installPackageGlobal(packageName, version) {
48
+ return new Promise((resolve, reject) => {
49
+ const command = 'npm';
50
+ const args = ['install', '-g', packageName, version ? `@${version}` : ''];
51
+ const childProcess = (0, child_process_1.spawn)(command, args, {
52
+ stdio: ['pipe', 'ignore', 'pipe'],
53
+ });
54
+ let errorOutput = '';
55
+ if (childProcess.stderr) {
56
+ childProcess.stderr.on('data', (data) => {
57
+ errorOutput += data.toString();
58
+ });
59
+ }
60
+ childProcess.on('error', (error) => {
61
+ (0, console_1.logError)(chalk_1.default.red(`Installation error: ${error.message}`));
62
+ (0, console_1.logInfo)(`Please manually install ${packageName} with: npm install -g ${packageName}`);
63
+ reject(error);
64
+ });
65
+ childProcess.on('close', (code) => {
66
+ if (code === 0) {
67
+ resolve();
68
+ }
69
+ else {
70
+ (0, console_1.logError)(chalk_1.default.red(`Installation failed with exit code ${code}`));
71
+ if (errorOutput) {
72
+ (0, console_1.logError)(chalk_1.default.red(`Error details: ${errorOutput}`));
73
+ }
74
+ (0, console_1.logInfo)(`Please manually install ${packageName} with: npm install -g ${packageName}`);
75
+ reject(new Error(`Process exited with code ${code}`));
76
+ }
77
+ });
78
+ });
79
+ }
@@ -0,0 +1,3 @@
1
+ export declare function getPackageInfo(packageName: string): Promise<{
2
+ version: string;
3
+ } | undefined>;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPackageInfo = getPackageInfo;
4
+ const child_process_1 = require("child_process");
5
+ async function getPackageInfo(packageName) {
6
+ try {
7
+ const output = (0, child_process_1.execSync)(`npm list -g ${packageName}`, {
8
+ encoding: 'utf8',
9
+ stdio: 'pipe',
10
+ });
11
+ const match = output.match(new RegExp(`${packageName}@([\\d\\.\\w-]+)`));
12
+ if (match && match[1]) {
13
+ return { version: match[1] };
14
+ }
15
+ return undefined;
16
+ }
17
+ catch (error) {
18
+ return undefined;
19
+ }
20
+ }
@@ -1,4 +1,5 @@
1
1
  export interface PackageManager {
2
+ id: string;
2
3
  name: string;
3
4
  label: string;
4
5
  installCommand: string;
@@ -20,4 +21,4 @@ export declare const PNPM: PackageManager;
20
21
  export declare const NPM: PackageManager;
21
22
  export declare const packageManagers: PackageManager[];
22
23
  export declare function _detectPackageManger(managers?: PackageManager[]): PackageManager | null;
23
- export declare function getPackageManager(): Promise<PackageManager>;
24
+ export declare function getPackageManager(specifiedPackageManager?: string): Promise<PackageManager>;
@@ -42,6 +42,7 @@ const path = __importStar(require("path"));
42
42
  const packageJson_1 = require("./packageJson");
43
43
  const console_1 = require("../console");
44
44
  exports.BUN = {
45
+ id: 'bun',
45
46
  name: 'bun',
46
47
  label: 'Bun',
47
48
  installCommand: 'add',
@@ -71,6 +72,7 @@ exports.BUN = {
71
72
  },
72
73
  };
73
74
  exports.DENO = {
75
+ id: 'deno',
74
76
  name: 'deno',
75
77
  label: 'Deno',
76
78
  installCommand: 'install',
@@ -101,6 +103,7 @@ exports.DENO = {
101
103
  },
102
104
  };
103
105
  exports.YARN_V1 = {
106
+ id: 'yarn_v1',
104
107
  name: 'yarn',
105
108
  label: 'Yarn V1',
106
109
  installCommand: 'add',
@@ -134,6 +137,7 @@ exports.YARN_V1 = {
134
137
  };
135
138
  /** YARN V2/3/4 */
136
139
  exports.YARN_V2 = {
140
+ id: 'yarn_v2',
137
141
  name: 'yarn',
138
142
  label: 'Yarn V2/3/4',
139
143
  installCommand: 'add',
@@ -166,6 +170,7 @@ exports.YARN_V2 = {
166
170
  },
167
171
  };
168
172
  exports.PNPM = {
173
+ id: 'pnpm',
169
174
  name: 'pnpm',
170
175
  label: 'PNPM',
171
176
  installCommand: 'add',
@@ -199,6 +204,7 @@ exports.PNPM = {
199
204
  },
200
205
  };
201
206
  exports.NPM = {
207
+ id: 'npm',
202
208
  name: 'npm',
203
209
  label: 'NPM',
204
210
  installCommand: 'install',
@@ -239,11 +245,18 @@ function _detectPackageManger(managers) {
239
245
  }
240
246
  // Get the package manager for the current project
241
247
  // Uses a global cache to avoid prompting the user multiple times
242
- async function getPackageManager() {
248
+ async function getPackageManager(specifiedPackageManager) {
243
249
  const globalWizard = global;
244
250
  if (globalWizard._gt_wizard_cached_package_manager) {
245
251
  return globalWizard._gt_wizard_cached_package_manager;
246
252
  }
253
+ if (specifiedPackageManager) {
254
+ const packageManager = exports.packageManagers.find((packageManager) => packageManager.id === specifiedPackageManager);
255
+ if (packageManager) {
256
+ globalWizard._gt_wizard_cached_package_manager = packageManager;
257
+ return packageManager;
258
+ }
259
+ }
247
260
  const detectedPackageManager = _detectPackageManger();
248
261
  if (detectedPackageManager) {
249
262
  globalWizard._gt_wizard_cached_package_manager = detectedPackageManager;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gtx-cli",
3
- "version": "1.2.23",
3
+ "version": "1.2.24-alpha.2",
4
4
  "main": "dist/index.js",
5
5
  "bin": "dist/main.js",
6
6
  "files": [
@@ -44,8 +44,14 @@
44
44
  "./api/*": {
45
45
  "import": "./dist/api/*.js"
46
46
  },
47
+ "./setup/*": {
48
+ "import": "./dist/setup/*.js"
49
+ },
47
50
  "./*": {
48
51
  "import": "./dist/*.js"
52
+ },
53
+ "./utils/*": {
54
+ "import": "./dist/utils/*.js"
49
55
  }
50
56
  },
51
57
  "repository": {
@@ -72,7 +78,7 @@
72
78
  "@babel/parser": "^7.25.7",
73
79
  "@babel/plugin-transform-react-jsx": "^7.25.9",
74
80
  "@babel/traverse": "^7.25.7",
75
- "@clack/prompts": "^0.11.0",
81
+ "@clack/prompts": "^1.0.0-alpha.1",
76
82
  "chalk": "^4.1.2",
77
83
  "commander": "^12.1.0",
78
84
  "dotenv": "^16.4.5",