gtx-cli 2.3.4 → 2.3.6-alpha.1

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.
Files changed (192) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/package.json +23 -18
  3. package/dist/api/checkFileTranslations.d.ts +0 -23
  4. package/dist/api/checkFileTranslations.js +0 -236
  5. package/dist/api/downloadFileBatch.d.ts +0 -20
  6. package/dist/api/downloadFileBatch.js +0 -113
  7. package/dist/api/sendFiles.d.ts +0 -17
  8. package/dist/api/sendFiles.js +0 -115
  9. package/dist/api/uploadFiles.d.ts +0 -27
  10. package/dist/api/uploadFiles.js +0 -40
  11. package/dist/cli/base.d.ts +0 -32
  12. package/dist/cli/base.js +0 -335
  13. package/dist/cli/commands/stage.d.ts +0 -5
  14. package/dist/cli/commands/stage.js +0 -100
  15. package/dist/cli/commands/translate.d.ts +0 -6
  16. package/dist/cli/commands/translate.js +0 -63
  17. package/dist/cli/flags.d.ts +0 -3
  18. package/dist/cli/flags.js +0 -38
  19. package/dist/cli/next.d.ts +0 -11
  20. package/dist/cli/next.js +0 -20
  21. package/dist/cli/react.d.ts +0 -18
  22. package/dist/cli/react.js +0 -175
  23. package/dist/config/generateSettings.d.ts +0 -9
  24. package/dist/config/generateSettings.js +0 -171
  25. package/dist/config/optionPresets.d.ts +0 -2
  26. package/dist/config/optionPresets.js +0 -56
  27. package/dist/config/resolveConfig.d.ts +0 -4
  28. package/dist/config/resolveConfig.js +0 -19
  29. package/dist/config/utils.d.ts +0 -2
  30. package/dist/config/utils.js +0 -4
  31. package/dist/config/validateSettings.d.ts +0 -3
  32. package/dist/config/validateSettings.js +0 -32
  33. package/dist/console/colors.d.ts +0 -5
  34. package/dist/console/colors.js +0 -16
  35. package/dist/console/index.d.ts +0 -21
  36. package/dist/console/index.js +0 -24
  37. package/dist/console/logging.d.ts +0 -53
  38. package/dist/console/logging.js +0 -185
  39. package/dist/formats/files/fileMapping.d.ts +0 -11
  40. package/dist/formats/files/fileMapping.js +0 -82
  41. package/dist/formats/files/save.d.ts +0 -5
  42. package/dist/formats/files/save.js +0 -17
  43. package/dist/formats/files/supportedFiles.d.ts +0 -10
  44. package/dist/formats/files/supportedFiles.js +0 -18
  45. package/dist/formats/files/translate.d.ts +0 -4
  46. package/dist/formats/files/translate.js +0 -119
  47. package/dist/formats/files/upload.d.ts +0 -13
  48. package/dist/formats/files/upload.js +0 -136
  49. package/dist/formats/gt/save.d.ts +0 -9
  50. package/dist/formats/gt/save.js +0 -26
  51. package/dist/formats/json/flattenJson.d.ts +0 -14
  52. package/dist/formats/json/flattenJson.js +0 -64
  53. package/dist/formats/json/mergeJson.d.ts +0 -13
  54. package/dist/formats/json/mergeJson.js +0 -257
  55. package/dist/formats/json/parseJson.d.ts +0 -2
  56. package/dist/formats/json/parseJson.js +0 -108
  57. package/dist/formats/json/utils.d.ts +0 -47
  58. package/dist/formats/json/utils.js +0 -149
  59. package/dist/formats/utils.d.ts +0 -2
  60. package/dist/formats/utils.js +0 -24
  61. package/dist/formats/yaml/mergeYaml.d.ts +0 -5
  62. package/dist/formats/yaml/mergeYaml.js +0 -55
  63. package/dist/formats/yaml/parseYaml.d.ts +0 -5
  64. package/dist/formats/yaml/parseYaml.js +0 -23
  65. package/dist/formats/yaml/utils.d.ts +0 -2
  66. package/dist/formats/yaml/utils.js +0 -22
  67. package/dist/fs/config/loadConfig.d.ts +0 -1
  68. package/dist/fs/config/loadConfig.js +0 -9
  69. package/dist/fs/config/parseFilesConfig.d.ts +0 -27
  70. package/dist/fs/config/parseFilesConfig.js +0 -126
  71. package/dist/fs/config/setupConfig.d.ts +0 -17
  72. package/dist/fs/config/setupConfig.js +0 -50
  73. package/dist/fs/config/updateConfig.d.ts +0 -10
  74. package/dist/fs/config/updateConfig.js +0 -36
  75. package/dist/fs/config/updateVersions.d.ts +0 -10
  76. package/dist/fs/config/updateVersions.js +0 -30
  77. package/dist/fs/copyFile.d.ts +0 -7
  78. package/dist/fs/copyFile.js +0 -39
  79. package/dist/fs/createLoadTranslationsFile.d.ts +0 -1
  80. package/dist/fs/createLoadTranslationsFile.js +0 -36
  81. package/dist/fs/determineFramework.d.ts +0 -5
  82. package/dist/fs/determineFramework.js +0 -46
  83. package/dist/fs/findFilepath.d.ts +0 -36
  84. package/dist/fs/findFilepath.js +0 -89
  85. package/dist/fs/getPackageResource.d.ts +0 -1
  86. package/dist/fs/getPackageResource.js +0 -6
  87. package/dist/fs/index.d.ts +0 -1
  88. package/dist/fs/index.js +0 -1
  89. package/dist/fs/loadJSON.d.ts +0 -6
  90. package/dist/fs/loadJSON.js +0 -17
  91. package/dist/fs/matchFiles.d.ts +0 -1
  92. package/dist/fs/matchFiles.js +0 -8
  93. package/dist/fs/saveJSON.d.ts +0 -1
  94. package/dist/fs/saveJSON.js +0 -7
  95. package/dist/fs/utils.d.ts +0 -1
  96. package/dist/fs/utils.js +0 -16
  97. package/dist/hooks/postProcess.d.ts +0 -4
  98. package/dist/hooks/postProcess.js +0 -110
  99. package/dist/index.d.ts +0 -4
  100. package/dist/index.js +0 -20
  101. package/dist/main.d.ts +0 -2
  102. package/dist/main.js +0 -9
  103. package/dist/next/config/parseNextConfig.d.ts +0 -10
  104. package/dist/next/config/parseNextConfig.js +0 -53
  105. package/dist/next/jsx/utils.d.ts +0 -7
  106. package/dist/next/jsx/utils.js +0 -42
  107. package/dist/next/parse/handleInitGT.d.ts +0 -7
  108. package/dist/next/parse/handleInitGT.js +0 -208
  109. package/dist/next/parse/wrapContent.d.ts +0 -11
  110. package/dist/next/parse/wrapContent.js +0 -163
  111. package/dist/react/config/createESBuildConfig.d.ts +0 -2
  112. package/dist/react/config/createESBuildConfig.js +0 -119
  113. package/dist/react/data-_gt/addGTIdentifierToSyntaxTree.d.ts +0 -8
  114. package/dist/react/data-_gt/addGTIdentifierToSyntaxTree.js +0 -111
  115. package/dist/react/jsx/evaluateJsx.d.ts +0 -17
  116. package/dist/react/jsx/evaluateJsx.js +0 -85
  117. package/dist/react/jsx/trimJsxStringChildren.d.ts +0 -7
  118. package/dist/react/jsx/trimJsxStringChildren.js +0 -95
  119. package/dist/react/jsx/utils/constants.d.ts +0 -10
  120. package/dist/react/jsx/utils/constants.js +0 -31
  121. package/dist/react/jsx/utils/parseAst.d.ts +0 -30
  122. package/dist/react/jsx/utils/parseAst.js +0 -277
  123. package/dist/react/jsx/utils/parseJsx.d.ts +0 -21
  124. package/dist/react/jsx/utils/parseJsx.js +0 -244
  125. package/dist/react/jsx/utils/parseStringFunction.d.ts +0 -16
  126. package/dist/react/jsx/utils/parseStringFunction.js +0 -411
  127. package/dist/react/jsx/utils/validateStringFunction.d.ts +0 -7
  128. package/dist/react/jsx/utils/validateStringFunction.js +0 -31
  129. package/dist/react/jsx/wrapJsx.d.ts +0 -51
  130. package/dist/react/jsx/wrapJsx.js +0 -387
  131. package/dist/react/parse/createDictionaryUpdates.d.ts +0 -3
  132. package/dist/react/parse/createDictionaryUpdates.js +0 -169
  133. package/dist/react/parse/createInlineUpdates.d.ts +0 -6
  134. package/dist/react/parse/createInlineUpdates.js +0 -122
  135. package/dist/react/parse/wrapContent.d.ts +0 -11
  136. package/dist/react/parse/wrapContent.js +0 -162
  137. package/dist/react/utils/flattenDictionary.d.ts +0 -20
  138. package/dist/react/utils/flattenDictionary.js +0 -75
  139. package/dist/react/utils/getEntryAndMetadata.d.ts +0 -5
  140. package/dist/react/utils/getEntryAndMetadata.js +0 -11
  141. package/dist/react/utils/getVariableName.d.ts +0 -25
  142. package/dist/react/utils/getVariableName.js +0 -37
  143. package/dist/setup/userInput.d.ts +0 -4
  144. package/dist/setup/userInput.js +0 -29
  145. package/dist/setup/wizard.d.ts +0 -2
  146. package/dist/setup/wizard.js +0 -127
  147. package/dist/translation/parse.d.ts +0 -15
  148. package/dist/translation/parse.js +0 -76
  149. package/dist/translation/stage.d.ts +0 -2
  150. package/dist/translation/stage.js +0 -44
  151. package/dist/translation/validate.d.ts +0 -2
  152. package/dist/translation/validate.js +0 -50
  153. package/dist/types/data/json.d.ts +0 -6
  154. package/dist/types/data/json.js +0 -1
  155. package/dist/types/data.d.ts +0 -30
  156. package/dist/types/data.js +0 -1
  157. package/dist/types/files.d.ts +0 -1
  158. package/dist/types/files.js +0 -1
  159. package/dist/types/index.d.ts +0 -173
  160. package/dist/types/index.js +0 -1
  161. package/dist/utils/addExplicitAnchorIds.d.ts +0 -24
  162. package/dist/utils/addExplicitAnchorIds.js +0 -260
  163. package/dist/utils/constants.d.ts +0 -2
  164. package/dist/utils/constants.js +0 -2
  165. package/dist/utils/credentials.d.ts +0 -12
  166. package/dist/utils/credentials.js +0 -119
  167. package/dist/utils/flattenJsonFiles.d.ts +0 -2
  168. package/dist/utils/flattenJsonFiles.js +0 -36
  169. package/dist/utils/gt.d.ts +0 -2
  170. package/dist/utils/gt.js +0 -2
  171. package/dist/utils/hash.d.ts +0 -6
  172. package/dist/utils/hash.js +0 -11
  173. package/dist/utils/headers.d.ts +0 -1
  174. package/dist/utils/headers.js +0 -14
  175. package/dist/utils/installPackage.d.ts +0 -3
  176. package/dist/utils/installPackage.js +0 -77
  177. package/dist/utils/localizeStaticImports.d.ts +0 -15
  178. package/dist/utils/localizeStaticImports.js +0 -341
  179. package/dist/utils/localizeStaticUrls.d.ts +0 -19
  180. package/dist/utils/localizeStaticUrls.js +0 -432
  181. package/dist/utils/packageInfo.d.ts +0 -3
  182. package/dist/utils/packageInfo.js +0 -17
  183. package/dist/utils/packageJson.d.ts +0 -6
  184. package/dist/utils/packageJson.js +0 -76
  185. package/dist/utils/packageManager.d.ts +0 -28
  186. package/dist/utils/packageManager.js +0 -269
  187. package/dist/utils/processAnchorIds.d.ts +0 -6
  188. package/dist/utils/processAnchorIds.js +0 -47
  189. package/dist/utils/sanitizeFileContent.d.ts +0 -6
  190. package/dist/utils/sanitizeFileContent.js +0 -29
  191. package/dist/utils/validateMdx.d.ts +0 -10
  192. package/dist/utils/validateMdx.js +0 -25
@@ -1,149 +0,0 @@
1
- import { getLocaleProperties } from 'generaltranslation';
2
- import { exit, logError } from '../../console/logging.js';
3
- import { JSONPath } from 'jsonpath-plus';
4
- import { flattenJson } from './flattenJson.js';
5
- import path from 'node:path';
6
- import micromatch from 'micromatch';
7
- const { isMatch } = micromatch;
8
- // Find the matching source item in an array
9
- // where the key matches the identifying locale property
10
- // If no matching item is found, exit with an error
11
- export function findMatchingItemArray(locale, sourceObjectOptions, sourceObjectPointer, sourceObjectValue) {
12
- const { identifyingLocaleProperty, localeKeyJsonPath } = getSourceObjectOptionsArray(locale, sourceObjectPointer, sourceObjectOptions);
13
- // Use the json pointer key to locate the source item
14
- const matchingItems = {};
15
- for (const [index, item] of sourceObjectValue.entries()) {
16
- // Get the key candidates
17
- const keyCandidates = JSONPath({
18
- json: item,
19
- path: localeKeyJsonPath,
20
- resultType: 'all',
21
- flatten: true,
22
- wrap: true,
23
- });
24
- if (!keyCandidates) {
25
- logError(`Source item at path: ${sourceObjectPointer} does not have a key value at path: ${localeKeyJsonPath}`);
26
- exit(1);
27
- }
28
- else if (keyCandidates.length === 0) {
29
- // If no key candidates, skip the item
30
- continue;
31
- }
32
- else if (keyCandidates.length > 1) {
33
- // If multiple key candidates, exit with an error
34
- logError(`Source item at path: ${sourceObjectPointer} has multiple matching keys with path: ${localeKeyJsonPath}`);
35
- exit(1);
36
- }
37
- else if (identifyingLocaleProperty !== keyCandidates[0].value) {
38
- // Validate the key is the identifying locale property
39
- continue;
40
- }
41
- // Map the index to the source item
42
- matchingItems[`/${index}`] = {
43
- sourceItem: item,
44
- keyParentProperty: keyCandidates[0].parentProperty,
45
- keyPointer: keyCandidates[0].pointer,
46
- index,
47
- };
48
- }
49
- return matchingItems;
50
- }
51
- export function findMatchingItemObject(locale, sourceObjectPointer, sourceObjectOptions, sourceObjectValue) {
52
- const { identifyingLocaleProperty } = getSourceObjectOptionsObject(locale, sourceObjectPointer, sourceObjectOptions);
53
- // Locate the source item
54
- if (sourceObjectValue[identifyingLocaleProperty]) {
55
- return {
56
- sourceItem: sourceObjectValue[identifyingLocaleProperty],
57
- keyParentProperty: identifyingLocaleProperty,
58
- };
59
- }
60
- return {
61
- sourceItem: undefined,
62
- keyParentProperty: identifyingLocaleProperty,
63
- };
64
- }
65
- /**
66
- * Get the identifying locale property for an object
67
- * @param locale - The locale to get the identifying locale property for
68
- * @param sourceObjectPointer - The path to the source object
69
- * @param sourceObjectOptions - The source object options
70
- * @returns The identifying locale property
71
- */
72
- export function getIdentifyingLocaleProperty(locale, sourceObjectPointer, sourceObjectOptions) {
73
- // Validate localeProperty
74
- const localeProperty = sourceObjectOptions.localeProperty || 'code';
75
- const identifyingLocaleProperty = getLocaleProperties(locale)[localeProperty];
76
- if (!identifyingLocaleProperty) {
77
- logError(`Source object options localeProperty is not a valid locale property at path: ${sourceObjectPointer}`);
78
- exit(1);
79
- }
80
- return identifyingLocaleProperty;
81
- }
82
- /**
83
- * Get the identifying locale property and the json path to the key for an array
84
- * @param locale - The locale to get the identifying locale property for
85
- * @param sourceObjectPointer - The path to the source object
86
- * @param sourceObjectOptions - The source object options
87
- * @returns The identifying locale property and the json path to the key
88
- */
89
- export function getSourceObjectOptionsArray(locale, sourceObjectPointer, sourceObjectOptions) {
90
- const identifyingLocaleProperty = getIdentifyingLocaleProperty(locale, sourceObjectPointer, sourceObjectOptions);
91
- const localeKeyJsonPath = sourceObjectOptions.key;
92
- if (!localeKeyJsonPath) {
93
- logError(`Source object options key is required for array at path: ${sourceObjectPointer}`);
94
- exit(1);
95
- }
96
- return { identifyingLocaleProperty, localeKeyJsonPath };
97
- }
98
- export function getSourceObjectOptionsObject(defaultLocale, sourceObjectPointer, sourceObjectOptions) {
99
- const identifyingLocaleProperty = getIdentifyingLocaleProperty(defaultLocale, sourceObjectPointer, sourceObjectOptions);
100
- const jsonPathKey = sourceObjectOptions.key;
101
- if (jsonPathKey) {
102
- logError(`Source object options key is not allowed for object at path: ${sourceObjectPointer}`);
103
- exit(1);
104
- }
105
- return { identifyingLocaleProperty };
106
- }
107
- /**
108
- * Generate a mapping of sourceObjectPointer to SourceObjectOptions
109
- * where the sourceObjectPointer is a jsonpointer to the array or object containing
110
- * @param jsonSchema - The json schema to generate the mapping from
111
- * @param originalJson - The original json to generate the mapping from
112
- * @returns A mapping of sourceObjectPointer to SourceObjectOptions
113
- */
114
- export function generateSourceObjectPointers(jsonSchema, originalJson) {
115
- const sourceObjectPointers = Object.entries(jsonSchema).reduce((acc, [sourceObjectPath, sourceObjectOptions]) => {
116
- const sourceObjects = flattenJson(originalJson, [sourceObjectPath]);
117
- Object.entries(sourceObjects).forEach(([pointer, value]) => {
118
- acc[pointer] = {
119
- sourceObjectValue: value,
120
- sourceObjectOptions,
121
- };
122
- });
123
- return acc;
124
- }, {});
125
- return sourceObjectPointers;
126
- }
127
- export function validateJsonSchema(options, filePath) {
128
- if (!options.jsonSchema) {
129
- return null;
130
- }
131
- const fileGlobs = Object.keys(options.jsonSchema);
132
- const matchingGlob = fileGlobs.find((fileGlob) => isMatch(path.relative(process.cwd(), filePath), fileGlob));
133
- if (!matchingGlob || !options.jsonSchema[matchingGlob]) {
134
- return null;
135
- }
136
- // Validate includes or composite
137
- const jsonSchema = options.jsonSchema[matchingGlob];
138
- if (jsonSchema.include && jsonSchema.composite) {
139
- logError('include and composite cannot be used together in the same JSON schema');
140
- exit(1);
141
- return null;
142
- }
143
- if (!jsonSchema.include && !jsonSchema.composite) {
144
- logError('No include or composite property found in JSON schema');
145
- exit(1);
146
- return null;
147
- }
148
- return jsonSchema;
149
- }
@@ -1,2 +0,0 @@
1
- import { LocaleProperties } from 'generaltranslation/types';
2
- export declare function replaceLocalePlaceholders(string: string, localeProperties: LocaleProperties): string;
@@ -1,24 +0,0 @@
1
- // helper function to replace locale placeholders in a string
2
- // with the corresponding locale properties
3
- // ex: {locale} -> will be replaced with the locale code
4
- // ex: {localeName} -> will be replaced with the locale name
5
- export function replaceLocalePlaceholders(string, localeProperties) {
6
- return string.replace(/\{(\w+)\}/g, (match, property) => {
7
- // Handle common aliases
8
- if (property === 'locale' || property === 'localeCode') {
9
- return localeProperties.code;
10
- }
11
- if (property === 'localeName') {
12
- return localeProperties.name;
13
- }
14
- if (property === 'localeNativeName') {
15
- return localeProperties.nativeName;
16
- }
17
- // Check if the property exists in localeProperties
18
- if (property in localeProperties) {
19
- return localeProperties[property];
20
- }
21
- // Return the original placeholder if property not found
22
- return match;
23
- });
24
- }
@@ -1,5 +0,0 @@
1
- import { AdditionalOptions } from '../../types/index.js';
2
- export default function mergeYaml(originalContent: string, inputPath: string, options: AdditionalOptions, targets: {
3
- translatedContent: string;
4
- targetLocale: string;
5
- }[]): string[];
@@ -1,55 +0,0 @@
1
- import JSONPointer from 'jsonpointer';
2
- import { exit, logError } from '../../console/logging.js';
3
- import { validateYamlSchema } from './utils.js';
4
- import YAML from 'yaml';
5
- export default function mergeYaml(originalContent, inputPath, options, targets) {
6
- const yamlSchema = validateYamlSchema(options, inputPath);
7
- if (!yamlSchema) {
8
- return targets.map((target) => target.translatedContent);
9
- }
10
- let originalYaml;
11
- try {
12
- originalYaml = YAML.parse(originalContent);
13
- }
14
- catch {
15
- logError(`Invalid YAML file: ${inputPath}`);
16
- exit(1);
17
- }
18
- // Unreachable (validated in validateYamlSchema, included for type check)
19
- if (!yamlSchema.include) {
20
- logError('No include property found in YAML schema');
21
- exit(1);
22
- }
23
- // Handle include
24
- const output = [];
25
- for (const target of targets) {
26
- // Must clone the original YAML to avoid mutations
27
- const mergedYaml = JSON.parse(JSON.stringify(originalYaml));
28
- let translatedJson;
29
- try {
30
- translatedJson = JSON.parse(target.translatedContent);
31
- }
32
- catch {
33
- // If parsing fails, treat as empty object to avoid crashes
34
- translatedJson = {};
35
- }
36
- for (const [jsonPointer, translatedValue] of Object.entries(translatedJson)) {
37
- try {
38
- // Try to get the value - if this succeeds, the pointer exists
39
- if (JSONPointer.get(mergedYaml, jsonPointer) == null) {
40
- continue;
41
- }
42
- // Set the new value regardless of what the current value is (including null/falsy)
43
- JSONPointer.set(mergedYaml, jsonPointer, translatedValue);
44
- }
45
- catch {
46
- // Silently ignore invalid or non-existent JSON pointers
47
- }
48
- }
49
- output.push(YAML.stringify(mergedYaml));
50
- }
51
- if (!output.length) {
52
- return [originalContent];
53
- }
54
- return output;
55
- }
@@ -1,5 +0,0 @@
1
- import { AdditionalOptions } from '../../types/index.js';
2
- export default function parseYaml(content: string, filePath: string, options: AdditionalOptions): {
3
- content: string;
4
- fileFormat: 'JSON' | 'YAML';
5
- };
@@ -1,23 +0,0 @@
1
- import { exit, logError } from '../../console/logging.js';
2
- import YAML from 'yaml';
3
- import { validateYamlSchema } from './utils.js';
4
- import { flattenJsonWithStringFilter } from '../json/flattenJson.js';
5
- export default function parseYaml(content, filePath, options) {
6
- const yamlSchema = validateYamlSchema(options, filePath);
7
- if (!yamlSchema) {
8
- return { content, fileFormat: 'YAML' };
9
- }
10
- let yaml;
11
- try {
12
- yaml = YAML.parse(content);
13
- }
14
- catch {
15
- logError(`Invalid YAML file: ${filePath}`);
16
- exit(1);
17
- }
18
- if (yamlSchema.include) {
19
- const flattenedYaml = flattenJsonWithStringFilter(yaml, yamlSchema.include);
20
- return { content: JSON.stringify(flattenedYaml), fileFormat: 'JSON' };
21
- }
22
- return { content, fileFormat: 'YAML' };
23
- }
@@ -1,2 +0,0 @@
1
- import { AdditionalOptions, YamlSchema } from '../../types/index.js';
2
- export declare function validateYamlSchema(options: AdditionalOptions, filePath: string): YamlSchema | null;
@@ -1,22 +0,0 @@
1
- import { logError, exit } from '../../console/logging.js';
2
- import micromatch from 'micromatch';
3
- const { isMatch } = micromatch;
4
- import path from 'path';
5
- export function validateYamlSchema(options, filePath) {
6
- if (!options.yamlSchema) {
7
- return null;
8
- }
9
- // Check if the file matches any of the yaml schema globs
10
- const fileGlobs = Object.keys(options.yamlSchema);
11
- const matchingGlob = fileGlobs.find((fileGlob) => isMatch(path.relative(process.cwd(), filePath), fileGlob));
12
- if (!matchingGlob || !options.yamlSchema[matchingGlob]) {
13
- return null;
14
- }
15
- // Validate includes
16
- const yamlSchema = options.yamlSchema[matchingGlob];
17
- if (!yamlSchema.include) {
18
- logError('No include property found in YAML schema');
19
- exit(1);
20
- }
21
- return yamlSchema;
22
- }
@@ -1 +0,0 @@
1
- export declare function loadConfig(filepath: string): Record<string, any>;
@@ -1,9 +0,0 @@
1
- import fs from 'node:fs';
2
- export function loadConfig(filepath) {
3
- try {
4
- return JSON.parse(fs.readFileSync(filepath, 'utf-8'));
5
- }
6
- catch (error) {
7
- return {};
8
- }
9
- }
@@ -1,27 +0,0 @@
1
- import { FilesOptions, ResolvedFiles, TransformFiles, TransformOption } from '../../types/index.js';
2
- /**
3
- * Resolves the files from the files object
4
- * Replaces [locale] with the actual locale in the files
5
- *
6
- * @param files - The files object
7
- * @param locale - The locale to replace [locale] with
8
- * @returns The resolved files
9
- */
10
- export declare function resolveLocaleFiles(files: ResolvedFiles, locale: string): ResolvedFiles;
11
- /**
12
- * Resolves the files from the files object
13
- * Performs glob pattern expansion on the files
14
- * Replaces [locale] with the actual locale in the files
15
- *
16
- * @param files - The files object
17
- * @returns The resolved files
18
- */
19
- export declare function resolveFiles(files: FilesOptions, locale: string, locales: string[], cwd: string): {
20
- resolvedPaths: ResolvedFiles;
21
- placeholderPaths: ResolvedFiles;
22
- transformPaths: TransformFiles;
23
- };
24
- export declare function expandGlobPatterns(cwd: string, includePatterns: string[], excludePatterns: string[], locale: string, locales: string[], transformPatterns?: TransformOption | string): {
25
- resolvedPaths: string[];
26
- placeholderPaths: string[];
27
- };
@@ -1,126 +0,0 @@
1
- import path from 'node:path';
2
- import fg from 'fast-glob';
3
- import { SUPPORTED_FILE_EXTENSIONS } from '../../formats/files/supportedFiles.js';
4
- import { logWarning } from '../../console/logging.js';
5
- import chalk from 'chalk';
6
- /**
7
- * Resolves the files from the files object
8
- * Replaces [locale] with the actual locale in the files
9
- *
10
- * @param files - The files object
11
- * @param locale - The locale to replace [locale] with
12
- * @returns The resolved files
13
- */
14
- export function resolveLocaleFiles(files, locale) {
15
- const result = {};
16
- for (const fileType of SUPPORTED_FILE_EXTENSIONS) {
17
- result[fileType] = files[fileType]?.map((filepath) => filepath.replace(/\[locale\]/g, locale));
18
- }
19
- // Replace [locale] with locale in all paths
20
- result.gt = files.gt?.replace(/\[locale\]/g, locale);
21
- return result;
22
- }
23
- /**
24
- * Resolves the files from the files object
25
- * Performs glob pattern expansion on the files
26
- * Replaces [locale] with the actual locale in the files
27
- *
28
- * @param files - The files object
29
- * @returns The resolved files
30
- */
31
- export function resolveFiles(files, locale, locales, cwd) {
32
- // Initialize result object with empty arrays for each file type
33
- const result = {};
34
- const placeholderResult = {};
35
- const transformPaths = {};
36
- // Process GT files
37
- if (files.gt?.output) {
38
- placeholderResult.gt = path.resolve(cwd, files.gt.output);
39
- }
40
- for (const fileType of SUPPORTED_FILE_EXTENSIONS) {
41
- // ==== TRANSFORMS ==== //
42
- const transform = files[fileType]?.transform;
43
- if (transform &&
44
- !Array.isArray(transform) &&
45
- (typeof transform === 'string' || typeof transform === 'object')) {
46
- transformPaths[fileType] = transform;
47
- }
48
- // ==== PLACEHOLDERS ==== //
49
- if (files[fileType]?.include) {
50
- const filePaths = expandGlobPatterns(cwd, files[fileType].include, files[fileType]?.exclude || [], locale, locales, transformPaths[fileType] || undefined);
51
- result[fileType] = filePaths.resolvedPaths;
52
- placeholderResult[fileType] = filePaths.placeholderPaths;
53
- }
54
- }
55
- return {
56
- resolvedPaths: result,
57
- placeholderPaths: placeholderResult,
58
- transformPaths: transformPaths,
59
- };
60
- }
61
- // Helper function to expand glob patterns
62
- export function expandGlobPatterns(cwd, includePatterns, excludePatterns, locale, locales, transformPatterns) {
63
- // Expand glob patterns to include all matching files
64
- const resolvedPaths = [];
65
- const placeholderPaths = [];
66
- // Process include patterns
67
- for (const pattern of includePatterns) {
68
- // Track positions where [locale] appears in the original pattern
69
- // It must be included in the pattern, otherwise the CLI tool will not be able to find the correct output path
70
- // Warn if it's not included
71
- if (!pattern.includes('[locale]') && !transformPatterns) {
72
- logWarning(chalk.yellow(`Pattern "${pattern}" does not include [locale], so the CLI tool may incorrectly save translated files.`));
73
- }
74
- const localePositions = [];
75
- let searchIndex = 0;
76
- const localeTag = '[locale]';
77
- while (true) {
78
- const foundIndex = pattern.indexOf(localeTag, searchIndex);
79
- if (foundIndex === -1)
80
- break;
81
- localePositions.push(foundIndex);
82
- searchIndex = foundIndex + localeTag.length;
83
- }
84
- const expandedPattern = pattern.replace(/\[locale\]/g, locale);
85
- // Resolve the absolute pattern path
86
- const absolutePattern = path.resolve(cwd, expandedPattern);
87
- // Prepare exclude patterns with locale replaced
88
- const expandedExcludePatterns = Array.from(new Set(excludePatterns.flatMap((p) => locales.map((targetLocale) => path.resolve(cwd, p
89
- .replace(/\[locale\]/g, locale)
90
- .replace(/\[locales\]/g, targetLocale))))));
91
- // Use fast-glob to find all matching files, excluding the patterns
92
- const matches = fg.sync(absolutePattern, {
93
- absolute: true,
94
- ignore: expandedExcludePatterns,
95
- });
96
- resolvedPaths.push(...matches);
97
- // For each match, create a version with [locale] in the correct positions
98
- matches.forEach((match) => {
99
- // Convert to absolute path to make replacement easier
100
- const absolutePath = path.resolve(cwd, match);
101
- const patternPath = path.resolve(cwd, pattern);
102
- let originalAbsolutePath = absolutePath;
103
- if (localePositions.length > 0) {
104
- // Replace all instances of [locale]
105
- // but only in path segments where we expect it based on the original pattern
106
- const pathParts = absolutePath.split(path.sep);
107
- const patternParts = patternPath.split(path.sep);
108
- for (let i = 0; i < pathParts.length; i++) {
109
- if (i < patternParts.length) {
110
- if (patternParts[i].includes(localeTag)) {
111
- // This segment should have the locale replaced
112
- // Create regex from pattern to match the actual path structure
113
- const regexPattern = patternParts[i].replace(/\[locale\]/g, `(${locale.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')})`);
114
- const regex = new RegExp(regexPattern);
115
- pathParts[i] = pathParts[i].replace(regex, patternParts[i].replace(/\[locale\]/g, localeTag));
116
- }
117
- }
118
- }
119
- originalAbsolutePath = pathParts.join(path.sep);
120
- }
121
- // Convert back to absolute path
122
- placeholderPaths.push(originalAbsolutePath);
123
- });
124
- }
125
- return { resolvedPaths, placeholderPaths };
126
- }
@@ -1,17 +0,0 @@
1
- import { FilesOptions, SupportedFrameworks } from '../../types/index.js';
2
- /**
3
- * Checks if the config file exists.
4
- * If yes, make sure make sure projectId is correct
5
- * If not, creates a new JSON file at the given filepath and writes the provided config object to it.
6
- * @param {string} configFilepath - The path to the config file.
7
- * @param {Record<string, any>} configObject - The config object to write if the file does not exist.
8
- */
9
- export declare function createOrUpdateConfig(configFilepath: string, options: {
10
- projectId?: string;
11
- defaultLocale?: string;
12
- locales?: string[];
13
- files?: FilesOptions;
14
- framework?: SupportedFrameworks;
15
- baseUrl?: string;
16
- publish?: boolean;
17
- }): Promise<string>;
@@ -1,50 +0,0 @@
1
- import fs from 'node:fs';
2
- import { displayCreatedConfigFile } from '../../console/logging.js';
3
- import { logError } from '../../console/logging.js';
4
- import { GT_CONFIG_SCHEMA_URL } from '../../utils/constants.js';
5
- /**
6
- * Checks if the config file exists.
7
- * If yes, make sure make sure projectId is correct
8
- * If not, creates a new JSON file at the given filepath and writes the provided config object to it.
9
- * @param {string} configFilepath - The path to the config file.
10
- * @param {Record<string, any>} configObject - The config object to write if the file does not exist.
11
- */
12
- export async function createOrUpdateConfig(configFilepath, options) {
13
- // Filter out empty string values from the config object
14
- const newContent = {
15
- ...(options.projectId && { projectId: options.projectId }),
16
- ...(options.defaultLocale && { defaultLocale: options.defaultLocale }),
17
- ...(options.files && { files: options.files }),
18
- ...(options.framework && { framework: options.framework }),
19
- ...(options.baseUrl && { baseUrl: options.baseUrl }),
20
- ...(options.publish && { publish: options.publish }),
21
- };
22
- try {
23
- // if file exists
24
- let oldContent = {};
25
- if (fs.existsSync(configFilepath)) {
26
- oldContent = JSON.parse(await fs.promises.readFile(configFilepath, 'utf-8'));
27
- }
28
- // merge old and new content
29
- const mergedContent = {
30
- $schema: GT_CONFIG_SCHEMA_URL,
31
- ...oldContent,
32
- ...newContent,
33
- };
34
- // Add locales to mergedContent if they exist
35
- if (options.locales) {
36
- mergedContent.locales = mergedContent.locales
37
- ? [...new Set([...mergedContent.locales, ...options.locales])]
38
- : options.locales;
39
- }
40
- // write to file
41
- const mergedJsonContent = JSON.stringify(mergedContent, null, 2);
42
- await fs.promises.writeFile(configFilepath, mergedJsonContent, 'utf-8');
43
- // show update in console
44
- displayCreatedConfigFile(configFilepath);
45
- }
46
- catch (error) {
47
- logError(`An error occurred while updating ${configFilepath}: ${error}`);
48
- }
49
- return configFilepath;
50
- }
@@ -1,10 +0,0 @@
1
- /**
2
- * Update the config file version id, locales, and projectId (if necessary)
3
- * @param {Record<string, any>} configObject - The config object to write if the file does not exist.
4
- */
5
- export default function updateConfig({ configFilepath, projectId, _versionId, stageTranslations, }: {
6
- configFilepath: string;
7
- projectId?: string;
8
- _versionId?: string;
9
- stageTranslations?: boolean;
10
- }): Promise<void>;
@@ -1,36 +0,0 @@
1
- import fs from 'node:fs';
2
- import { displayUpdatedConfigFile } from '../../console/logging.js';
3
- import { logError } from '../../console/logging.js';
4
- /**
5
- * Update the config file version id, locales, and projectId (if necessary)
6
- * @param {Record<string, any>} configObject - The config object to write if the file does not exist.
7
- */
8
- export default async function updateConfig({ configFilepath, projectId, _versionId, stageTranslations, }) {
9
- // Filter out empty string values from the config object
10
- const newContent = {
11
- ...(projectId && { projectId }),
12
- ...(_versionId && { _versionId }),
13
- ...(stageTranslations && { stageTranslations }),
14
- // ...(locales && { locales }), // Don't override locales
15
- };
16
- try {
17
- // if file exists
18
- let oldContent = {};
19
- if (fs.existsSync(configFilepath)) {
20
- oldContent = JSON.parse(await fs.promises.readFile(configFilepath, 'utf-8'));
21
- }
22
- // merge old and new content
23
- const mergedContent = {
24
- ...oldContent,
25
- ...newContent,
26
- };
27
- // write to file
28
- const mergedJsonContent = JSON.stringify(mergedContent, null, 2);
29
- await fs.promises.writeFile(configFilepath, mergedJsonContent, 'utf-8');
30
- // show update in console
31
- displayUpdatedConfigFile(configFilepath);
32
- }
33
- catch (error) {
34
- logError(`An error occurred while updating ${configFilepath}: ${error}`);
35
- }
36
- }
@@ -1,10 +0,0 @@
1
- type StagedVersionData = Record<string, {
2
- fileName: string;
3
- versionId: string;
4
- }>;
5
- export declare function updateVersions({ configDirectory, versionData, }: {
6
- configDirectory: string;
7
- versionData: StagedVersionData;
8
- }): Promise<void>;
9
- export declare function getStagedVersions(configDirectory: string): Promise<StagedVersionData>;
10
- export {};
@@ -1,30 +0,0 @@
1
- import fs from 'node:fs';
2
- import { displayUpdatedVersionsFile } from '../../console/logging.js';
3
- import { logError } from '../../console/logging.js';
4
- import path from 'node:path';
5
- const STAGED_VERSIONS_FILE = 'staged-versions.json';
6
- // Update the versions.json file with the new version ids
7
- // of the translations that were sent to the API
8
- export async function updateVersions({ configDirectory, versionData, }) {
9
- const versionFilepath = path.join(configDirectory, STAGED_VERSIONS_FILE);
10
- try {
11
- fs.mkdirSync(configDirectory, { recursive: true });
12
- fs.writeFileSync(versionFilepath, JSON.stringify(versionData, null, 2));
13
- // show update in console
14
- displayUpdatedVersionsFile(versionFilepath);
15
- }
16
- catch (error) {
17
- logError(`An error occurred while updating ${versionFilepath}: ${error}`);
18
- }
19
- }
20
- export async function getStagedVersions(configDirectory) {
21
- try {
22
- const versionFilepath = path.join(configDirectory, STAGED_VERSIONS_FILE);
23
- const versionData = JSON.parse(fs.readFileSync(versionFilepath, 'utf8'));
24
- return versionData;
25
- }
26
- catch (error) {
27
- logError(`An error occurred while getting staged versions: ${error}`);
28
- return {};
29
- }
30
- }
@@ -1,7 +0,0 @@
1
- import { Settings } from '../types/index.js';
2
- /**
3
- * Copy a file to target locale without translation
4
- *
5
- * This is a naive approach, does not allow for wild cards
6
- */
7
- export default function copyFile(settings: Settings): Promise<void>;