gtx-cli 1.1.1 → 1.1.3

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/dist/cli/base.js CHANGED
@@ -133,7 +133,7 @@ class BaseCLI {
133
133
  else {
134
134
  dataFormat = 'JSX';
135
135
  }
136
- const { resolvedPaths: sourceFiles, placeholderPaths } = settings.files;
136
+ const { resolvedPaths: sourceFiles, placeholderPaths, transformPaths, } = settings.files;
137
137
  // ---- CREATING UPDATES ---- //
138
138
  if (sourceFiles.json) {
139
139
  // Only translate JSON files if not using gt-react or gt-next
@@ -158,10 +158,10 @@ class BaseCLI {
158
158
  }
159
159
  if (sourceFiles.mdx || sourceFiles.md) {
160
160
  if (sourceFiles.mdx) {
161
- yield (0, translate_2.translateFiles)(sourceFiles, placeholderPaths, 'MDX', settings);
161
+ yield (0, translate_2.translateFiles)(sourceFiles, placeholderPaths, transformPaths, 'MDX', settings);
162
162
  }
163
163
  if (sourceFiles.md) {
164
- yield (0, translate_2.translateFiles)(sourceFiles, placeholderPaths, 'MD', settings);
164
+ yield (0, translate_2.translateFiles)(sourceFiles, placeholderPaths, transformPaths, 'MD', settings);
165
165
  }
166
166
  }
167
167
  });
@@ -257,7 +257,7 @@ class BaseCLI {
257
257
  else {
258
258
  const translationsDirWithFormat = path_1.default.join(translationsDir, `[locale].json`);
259
259
  // Create gt.config.json
260
- (0, setupConfig_1.default)(configFilepath, {
260
+ (0, setupConfig_1.default)('gt.config.json', {
261
261
  defaultLocale,
262
262
  locales: locales.split(' '),
263
263
  files: {
package/dist/cli/react.js CHANGED
@@ -279,7 +279,7 @@ class ReactCLI extends base_1.BaseCLI {
279
279
  message: 'What framework are you using?',
280
280
  choices: [
281
281
  { value: 'next', name: chalk_1.default.blue('Next.js') },
282
- { value: 'vite', name: chalk_1.default.green('Vite') },
282
+ { value: 'vite', name: chalk_1.default.green('Vite + React') },
283
283
  { value: 'gatsby', name: chalk_1.default.magenta('Gatsby') },
284
284
  { value: 'react', name: chalk_1.default.yellow('React') },
285
285
  { value: 'redwood', name: chalk_1.default.red('RedwoodJS') },
@@ -376,15 +376,16 @@ class ReactCLI extends base_1.BaseCLI {
376
376
  (0, console_1.displayInitializingText)();
377
377
  const settings = (0, generateSettings_1.generateSettings)(initOptions);
378
378
  // First run the base class's handleTranslate method
379
- try {
380
- yield _super.handleGenericTranslate.call(this, settings);
381
- // If the base class's handleTranslate completes successfully, continue with ReactCLI-specific code
382
- }
383
- catch (error) {
384
- // Continue with ReactCLI-specific code even if base handleTranslate failed
385
- }
386
- // only for typing purposes
387
379
  const options = Object.assign(Object.assign({}, initOptions), settings);
380
+ if (!options.dryRun) {
381
+ try {
382
+ yield _super.handleGenericTranslate.call(this, settings);
383
+ // If the base class's handleTranslate completes successfully, continue with ReactCLI-specific code
384
+ }
385
+ catch (error) {
386
+ // Continue with ReactCLI-specific code even if base handleTranslate failed
387
+ }
388
+ }
388
389
  if (!options.dictionary) {
389
390
  options.dictionary = (0, findFilepath_1.default)([
390
391
  './dictionary.js',
@@ -1,4 +1,4 @@
1
- import { ResolvedFiles, Settings } from '../../types';
1
+ import { ResolvedFiles, Settings, TransformFiles } from '../../types';
2
2
  import { FileFormats } from '../../types/data';
3
3
  /**
4
4
  * Sends an entire file to the API for translation
@@ -6,4 +6,4 @@ import { FileFormats } from '../../types/data';
6
6
  * @param options - Translation options including API settings
7
7
  * @returns The translated file content or null if translation failed
8
8
  */
9
- export declare function translateFiles(filePaths: ResolvedFiles, placeholderPaths: ResolvedFiles, fileFormat: FileFormats, options: Settings): Promise<void>;
9
+ export declare function translateFiles(filePaths: ResolvedFiles, placeholderPaths: ResolvedFiles, transformPaths: TransformFiles, fileFormat: FileFormats, options: Settings): Promise<void>;
@@ -8,19 +8,23 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
11
14
  Object.defineProperty(exports, "__esModule", { value: true });
12
15
  exports.translateFiles = translateFiles;
13
16
  const checkFileTranslations_1 = require("../../api/checkFileTranslations");
14
17
  const sendFiles_1 = require("../../api/sendFiles");
15
18
  const parseFilesConfig_1 = require("../../fs/config/parseFilesConfig");
16
19
  const findFilepath_1 = require("../../fs/findFilepath");
20
+ const path_1 = __importDefault(require("path"));
17
21
  /**
18
22
  * Sends an entire file to the API for translation
19
23
  * @param fileContent - The raw content of the file to translate
20
24
  * @param options - Translation options including API settings
21
25
  * @returns The translated file content or null if translation failed
22
26
  */
23
- function translateFiles(filePaths, placeholderPaths, fileFormat, options) {
27
+ function translateFiles(filePaths, placeholderPaths, transformPaths, fileFormat, options) {
24
28
  return __awaiter(this, void 0, void 0, function* () {
25
29
  let typeIndex = 'json';
26
30
  if (fileFormat === 'MDX') {
@@ -52,10 +56,22 @@ function translateFiles(filePaths, placeholderPaths, fileFormat, options) {
52
56
  const fileMapping = {};
53
57
  for (const locale of locales) {
54
58
  const translatedPaths = (0, parseFilesConfig_1.resolveLocaleFiles)(placeholderPaths, locale);
55
- const translatedFiles = translatedPaths[typeIndex];
59
+ let translatedFiles = translatedPaths[typeIndex];
56
60
  if (!translatedFiles) {
57
61
  continue; // shouldn't happen; typing
58
62
  }
63
+ const transformPath = transformPaths[typeIndex];
64
+ if (transformPath) {
65
+ translatedFiles = translatedFiles.map((filePath) => {
66
+ const directory = path_1.default.dirname(filePath);
67
+ const fileName = path_1.default.basename(filePath);
68
+ const baseName = fileName.split('.')[0];
69
+ const transformedFileName = transformPath
70
+ .replace('*', baseName)
71
+ .replace('[locale]', locale);
72
+ return path_1.default.join(directory, transformedFileName);
73
+ });
74
+ }
59
75
  const localeMapping = {};
60
76
  for (let i = 0; i < sourcePaths.length; i++) {
61
77
  const sourceFile = (0, findFilepath_1.getRelative)(sourcePaths[i]);
@@ -1,4 +1,4 @@
1
- import { FilesOptions, ResolvedFiles } from '../../types';
1
+ import { FilesOptions, ResolvedFiles, TransformFiles } from '../../types';
2
2
  /**
3
3
  * Resolves the files from the files object
4
4
  * Replaces [locale] with the actual locale in the files
@@ -19,4 +19,5 @@ export declare function resolveLocaleFiles(files: ResolvedFiles, locale: string)
19
19
  export declare function resolveFiles(files: FilesOptions, locale: string): {
20
20
  resolvedPaths: ResolvedFiles;
21
21
  placeholderPaths: ResolvedFiles;
22
+ transformPaths: TransformFiles;
22
23
  };
@@ -35,10 +35,11 @@ function resolveLocaleFiles(files, locale) {
35
35
  * @returns The resolved files
36
36
  */
37
37
  function resolveFiles(files, locale) {
38
- var _a, _b, _c;
38
+ var _a, _b, _c, _d, _e;
39
39
  // Initialize result object with empty arrays for each file type
40
40
  const result = {};
41
41
  const placeholderResult = {};
42
+ const transformPaths = {};
42
43
  // Process JSON files
43
44
  if ((_a = files.json) === null || _a === void 0 ? void 0 : _a.include) {
44
45
  if (files.json.include.length > 1) {
@@ -67,7 +68,18 @@ function resolveFiles(files, locale) {
67
68
  result.mdx = mdxPaths.resolvedPaths;
68
69
  placeholderResult.mdx = mdxPaths.placeholderPaths;
69
70
  }
70
- return { resolvedPaths: result, placeholderPaths: placeholderResult };
71
+ // ==== TRANSFORMS ==== //
72
+ if (((_d = files.mdx) === null || _d === void 0 ? void 0 : _d.transform) && !Array.isArray(files.mdx.transform)) {
73
+ transformPaths.mdx = files.mdx.transform;
74
+ }
75
+ if (((_e = files.md) === null || _e === void 0 ? void 0 : _e.transform) && !Array.isArray(files.md.transform)) {
76
+ transformPaths.md = files.md.transform;
77
+ }
78
+ return {
79
+ resolvedPaths: result,
80
+ placeholderPaths: placeholderResult,
81
+ transformPaths: transformPaths,
82
+ };
71
83
  }
72
84
  // Helper function to expand glob patterns
73
85
  function expandGlobPatterns(patterns, locale) {
@@ -68,9 +68,11 @@ export type FilesOptions = {
68
68
  };
69
69
  md?: {
70
70
  include: string[];
71
+ transform?: string;
71
72
  };
72
73
  mdx?: {
73
74
  include: string[];
75
+ transform?: string;
74
76
  };
75
77
  };
76
78
  export type ResolvedFiles = {
@@ -78,6 +80,11 @@ export type ResolvedFiles = {
78
80
  md?: string[];
79
81
  mdx?: string[];
80
82
  };
83
+ export type TransformFiles = {
84
+ json?: string;
85
+ md?: string;
86
+ mdx?: string;
87
+ };
81
88
  export type Settings = {
82
89
  config: string;
83
90
  baseUrl: string;
@@ -88,6 +95,7 @@ export type Settings = {
88
95
  files: {
89
96
  resolvedPaths: ResolvedFiles;
90
97
  placeholderPaths: ResolvedFiles;
98
+ transformPaths: TransformFiles;
91
99
  };
92
100
  versionId?: string;
93
101
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gtx-cli",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "main": "dist/index.js",
5
5
  "bin": "dist/main.js",
6
6
  "scripts": {