gtx-cli 2.3.5 → 2.3.6-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/package.json +23 -18
- package/dist/api/checkFileTranslations.d.ts +0 -23
- package/dist/api/checkFileTranslations.js +0 -236
- package/dist/api/downloadFileBatch.d.ts +0 -20
- package/dist/api/downloadFileBatch.js +0 -113
- package/dist/api/sendFiles.d.ts +0 -17
- package/dist/api/sendFiles.js +0 -115
- package/dist/api/uploadFiles.d.ts +0 -27
- package/dist/api/uploadFiles.js +0 -40
- package/dist/cli/base.d.ts +0 -32
- package/dist/cli/base.js +0 -335
- package/dist/cli/commands/stage.d.ts +0 -5
- package/dist/cli/commands/stage.js +0 -100
- package/dist/cli/commands/translate.d.ts +0 -6
- package/dist/cli/commands/translate.js +0 -63
- package/dist/cli/flags.d.ts +0 -3
- package/dist/cli/flags.js +0 -38
- package/dist/cli/next.d.ts +0 -11
- package/dist/cli/next.js +0 -20
- package/dist/cli/react.d.ts +0 -18
- package/dist/cli/react.js +0 -175
- package/dist/config/generateSettings.d.ts +0 -9
- package/dist/config/generateSettings.js +0 -176
- package/dist/config/optionPresets.d.ts +0 -2
- package/dist/config/optionPresets.js +0 -56
- package/dist/config/resolveConfig.d.ts +0 -4
- package/dist/config/resolveConfig.js +0 -19
- package/dist/config/utils.d.ts +0 -2
- package/dist/config/utils.js +0 -4
- package/dist/config/validateSettings.d.ts +0 -3
- package/dist/config/validateSettings.js +0 -32
- package/dist/console/colors.d.ts +0 -5
- package/dist/console/colors.js +0 -16
- package/dist/console/index.d.ts +0 -21
- package/dist/console/index.js +0 -24
- package/dist/console/logging.d.ts +0 -53
- package/dist/console/logging.js +0 -185
- package/dist/formats/files/fileMapping.d.ts +0 -11
- package/dist/formats/files/fileMapping.js +0 -82
- package/dist/formats/files/save.d.ts +0 -5
- package/dist/formats/files/save.js +0 -17
- package/dist/formats/files/supportedFiles.d.ts +0 -10
- package/dist/formats/files/supportedFiles.js +0 -18
- package/dist/formats/files/translate.d.ts +0 -4
- package/dist/formats/files/translate.js +0 -119
- package/dist/formats/files/upload.d.ts +0 -13
- package/dist/formats/files/upload.js +0 -136
- package/dist/formats/gt/save.d.ts +0 -9
- package/dist/formats/gt/save.js +0 -26
- package/dist/formats/json/flattenJson.d.ts +0 -14
- package/dist/formats/json/flattenJson.js +0 -64
- package/dist/formats/json/mergeJson.d.ts +0 -13
- package/dist/formats/json/mergeJson.js +0 -257
- package/dist/formats/json/parseJson.d.ts +0 -2
- package/dist/formats/json/parseJson.js +0 -108
- package/dist/formats/json/utils.d.ts +0 -47
- package/dist/formats/json/utils.js +0 -149
- package/dist/formats/utils.d.ts +0 -2
- package/dist/formats/utils.js +0 -24
- package/dist/formats/yaml/mergeYaml.d.ts +0 -5
- package/dist/formats/yaml/mergeYaml.js +0 -55
- package/dist/formats/yaml/parseYaml.d.ts +0 -5
- package/dist/formats/yaml/parseYaml.js +0 -23
- package/dist/formats/yaml/utils.d.ts +0 -2
- package/dist/formats/yaml/utils.js +0 -22
- package/dist/fs/config/loadConfig.d.ts +0 -1
- package/dist/fs/config/loadConfig.js +0 -9
- package/dist/fs/config/parseFilesConfig.d.ts +0 -27
- package/dist/fs/config/parseFilesConfig.js +0 -129
- package/dist/fs/config/setupConfig.d.ts +0 -17
- package/dist/fs/config/setupConfig.js +0 -50
- package/dist/fs/config/updateConfig.d.ts +0 -10
- package/dist/fs/config/updateConfig.js +0 -36
- package/dist/fs/config/updateVersions.d.ts +0 -10
- package/dist/fs/config/updateVersions.js +0 -30
- package/dist/fs/copyFile.d.ts +0 -7
- package/dist/fs/copyFile.js +0 -39
- package/dist/fs/createLoadTranslationsFile.d.ts +0 -1
- package/dist/fs/createLoadTranslationsFile.js +0 -36
- package/dist/fs/determineFramework.d.ts +0 -5
- package/dist/fs/determineFramework.js +0 -46
- package/dist/fs/findFilepath.d.ts +0 -36
- package/dist/fs/findFilepath.js +0 -89
- package/dist/fs/getPackageResource.d.ts +0 -1
- package/dist/fs/getPackageResource.js +0 -6
- package/dist/fs/index.d.ts +0 -1
- package/dist/fs/index.js +0 -1
- package/dist/fs/loadJSON.d.ts +0 -6
- package/dist/fs/loadJSON.js +0 -17
- package/dist/fs/matchFiles.d.ts +0 -1
- package/dist/fs/matchFiles.js +0 -8
- package/dist/fs/saveJSON.d.ts +0 -1
- package/dist/fs/saveJSON.js +0 -7
- package/dist/fs/utils.d.ts +0 -1
- package/dist/fs/utils.js +0 -16
- package/dist/hooks/postProcess.d.ts +0 -4
- package/dist/hooks/postProcess.js +0 -110
- package/dist/index.d.ts +0 -4
- package/dist/index.js +0 -20
- package/dist/main.d.ts +0 -2
- package/dist/main.js +0 -9
- package/dist/next/config/parseNextConfig.d.ts +0 -10
- package/dist/next/config/parseNextConfig.js +0 -53
- package/dist/next/jsx/utils.d.ts +0 -7
- package/dist/next/jsx/utils.js +0 -42
- package/dist/next/parse/handleInitGT.d.ts +0 -7
- package/dist/next/parse/handleInitGT.js +0 -208
- package/dist/next/parse/wrapContent.d.ts +0 -11
- package/dist/next/parse/wrapContent.js +0 -163
- package/dist/react/config/createESBuildConfig.d.ts +0 -2
- package/dist/react/config/createESBuildConfig.js +0 -119
- package/dist/react/data-_gt/addGTIdentifierToSyntaxTree.d.ts +0 -8
- package/dist/react/data-_gt/addGTIdentifierToSyntaxTree.js +0 -111
- package/dist/react/jsx/evaluateJsx.d.ts +0 -17
- package/dist/react/jsx/evaluateJsx.js +0 -85
- package/dist/react/jsx/trimJsxStringChildren.d.ts +0 -7
- package/dist/react/jsx/trimJsxStringChildren.js +0 -95
- package/dist/react/jsx/utils/constants.d.ts +0 -10
- package/dist/react/jsx/utils/constants.js +0 -31
- package/dist/react/jsx/utils/parseAst.d.ts +0 -30
- package/dist/react/jsx/utils/parseAst.js +0 -277
- package/dist/react/jsx/utils/parseJsx.d.ts +0 -21
- package/dist/react/jsx/utils/parseJsx.js +0 -244
- package/dist/react/jsx/utils/parseStringFunction.d.ts +0 -16
- package/dist/react/jsx/utils/parseStringFunction.js +0 -411
- package/dist/react/jsx/utils/validateStringFunction.d.ts +0 -7
- package/dist/react/jsx/utils/validateStringFunction.js +0 -31
- package/dist/react/jsx/wrapJsx.d.ts +0 -51
- package/dist/react/jsx/wrapJsx.js +0 -387
- package/dist/react/parse/createDictionaryUpdates.d.ts +0 -3
- package/dist/react/parse/createDictionaryUpdates.js +0 -169
- package/dist/react/parse/createInlineUpdates.d.ts +0 -6
- package/dist/react/parse/createInlineUpdates.js +0 -122
- package/dist/react/parse/wrapContent.d.ts +0 -11
- package/dist/react/parse/wrapContent.js +0 -162
- package/dist/react/utils/flattenDictionary.d.ts +0 -20
- package/dist/react/utils/flattenDictionary.js +0 -75
- package/dist/react/utils/getEntryAndMetadata.d.ts +0 -5
- package/dist/react/utils/getEntryAndMetadata.js +0 -11
- package/dist/react/utils/getVariableName.d.ts +0 -25
- package/dist/react/utils/getVariableName.js +0 -37
- package/dist/setup/userInput.d.ts +0 -4
- package/dist/setup/userInput.js +0 -29
- package/dist/setup/wizard.d.ts +0 -2
- package/dist/setup/wizard.js +0 -127
- package/dist/translation/parse.d.ts +0 -15
- package/dist/translation/parse.js +0 -76
- package/dist/translation/stage.d.ts +0 -2
- package/dist/translation/stage.js +0 -44
- package/dist/translation/validate.d.ts +0 -2
- package/dist/translation/validate.js +0 -50
- package/dist/types/data/json.d.ts +0 -6
- package/dist/types/data/json.js +0 -1
- package/dist/types/data.d.ts +0 -30
- package/dist/types/data.js +0 -1
- package/dist/types/files.d.ts +0 -1
- package/dist/types/files.js +0 -1
- package/dist/types/index.d.ts +0 -173
- package/dist/types/index.js +0 -1
- package/dist/utils/addExplicitAnchorIds.d.ts +0 -24
- package/dist/utils/addExplicitAnchorIds.js +0 -260
- package/dist/utils/constants.d.ts +0 -2
- package/dist/utils/constants.js +0 -2
- package/dist/utils/credentials.d.ts +0 -12
- package/dist/utils/credentials.js +0 -119
- package/dist/utils/flattenJsonFiles.d.ts +0 -2
- package/dist/utils/flattenJsonFiles.js +0 -36
- package/dist/utils/gt.d.ts +0 -2
- package/dist/utils/gt.js +0 -2
- package/dist/utils/hash.d.ts +0 -6
- package/dist/utils/hash.js +0 -11
- package/dist/utils/headers.d.ts +0 -1
- package/dist/utils/headers.js +0 -14
- package/dist/utils/installPackage.d.ts +0 -3
- package/dist/utils/installPackage.js +0 -77
- package/dist/utils/localizeStaticImports.d.ts +0 -15
- package/dist/utils/localizeStaticImports.js +0 -341
- package/dist/utils/localizeStaticUrls.d.ts +0 -19
- package/dist/utils/localizeStaticUrls.js +0 -432
- package/dist/utils/packageInfo.d.ts +0 -3
- package/dist/utils/packageInfo.js +0 -17
- package/dist/utils/packageJson.d.ts +0 -6
- package/dist/utils/packageJson.js +0 -76
- package/dist/utils/packageManager.d.ts +0 -28
- package/dist/utils/packageManager.js +0 -269
- package/dist/utils/processAnchorIds.d.ts +0 -6
- package/dist/utils/processAnchorIds.js +0 -47
- package/dist/utils/sanitizeFileContent.d.ts +0 -6
- package/dist/utils/sanitizeFileContent.js +0 -29
- package/dist/utils/validateMdx.d.ts +0 -10
- package/dist/utils/validateMdx.js +0 -25
|
@@ -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,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,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,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, compositePatterns?: 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, compositePatterns?: string[]): {
|
|
25
|
-
resolvedPaths: string[];
|
|
26
|
-
placeholderPaths: string[];
|
|
27
|
-
};
|
|
@@ -1,129 +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, compositePatterns) {
|
|
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, compositePatterns);
|
|
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, compositePatterns) {
|
|
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
|
-
// Ignore if is composite pattern
|
|
72
|
-
if (!pattern.includes('[locale]') &&
|
|
73
|
-
!transformPatterns &&
|
|
74
|
-
!compositePatterns?.includes(pattern)) {
|
|
75
|
-
logWarning(chalk.yellow(`Pattern "${pattern}" does not include [locale], so the CLI tool may incorrectly save translated files.`));
|
|
76
|
-
}
|
|
77
|
-
const localePositions = [];
|
|
78
|
-
let searchIndex = 0;
|
|
79
|
-
const localeTag = '[locale]';
|
|
80
|
-
while (true) {
|
|
81
|
-
const foundIndex = pattern.indexOf(localeTag, searchIndex);
|
|
82
|
-
if (foundIndex === -1)
|
|
83
|
-
break;
|
|
84
|
-
localePositions.push(foundIndex);
|
|
85
|
-
searchIndex = foundIndex + localeTag.length;
|
|
86
|
-
}
|
|
87
|
-
const expandedPattern = pattern.replace(/\[locale\]/g, locale);
|
|
88
|
-
// Resolve the absolute pattern path
|
|
89
|
-
const absolutePattern = path.resolve(cwd, expandedPattern);
|
|
90
|
-
// Prepare exclude patterns with locale replaced
|
|
91
|
-
const expandedExcludePatterns = Array.from(new Set(excludePatterns.flatMap((p) => locales.map((targetLocale) => path.resolve(cwd, p
|
|
92
|
-
.replace(/\[locale\]/g, locale)
|
|
93
|
-
.replace(/\[locales\]/g, targetLocale))))));
|
|
94
|
-
// Use fast-glob to find all matching files, excluding the patterns
|
|
95
|
-
const matches = fg.sync(absolutePattern, {
|
|
96
|
-
absolute: true,
|
|
97
|
-
ignore: expandedExcludePatterns,
|
|
98
|
-
});
|
|
99
|
-
resolvedPaths.push(...matches);
|
|
100
|
-
// For each match, create a version with [locale] in the correct positions
|
|
101
|
-
matches.forEach((match) => {
|
|
102
|
-
// Convert to absolute path to make replacement easier
|
|
103
|
-
const absolutePath = path.resolve(cwd, match);
|
|
104
|
-
const patternPath = path.resolve(cwd, pattern);
|
|
105
|
-
let originalAbsolutePath = absolutePath;
|
|
106
|
-
if (localePositions.length > 0) {
|
|
107
|
-
// Replace all instances of [locale]
|
|
108
|
-
// but only in path segments where we expect it based on the original pattern
|
|
109
|
-
const pathParts = absolutePath.split(path.sep);
|
|
110
|
-
const patternParts = patternPath.split(path.sep);
|
|
111
|
-
for (let i = 0; i < pathParts.length; i++) {
|
|
112
|
-
if (i < patternParts.length) {
|
|
113
|
-
if (patternParts[i].includes(localeTag)) {
|
|
114
|
-
// This segment should have the locale replaced
|
|
115
|
-
// Create regex from pattern to match the actual path structure
|
|
116
|
-
const regexPattern = patternParts[i].replace(/\[locale\]/g, `(${locale.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')})`);
|
|
117
|
-
const regex = new RegExp(regexPattern);
|
|
118
|
-
pathParts[i] = pathParts[i].replace(regex, patternParts[i].replace(/\[locale\]/g, localeTag));
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
originalAbsolutePath = pathParts.join(path.sep);
|
|
123
|
-
}
|
|
124
|
-
// Convert back to absolute path
|
|
125
|
-
placeholderPaths.push(originalAbsolutePath);
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
return { resolvedPaths, placeholderPaths };
|
|
129
|
-
}
|
|
@@ -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
|
-
}
|
package/dist/fs/copyFile.d.ts
DELETED
package/dist/fs/copyFile.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import fs from 'node:fs';
|
|
3
|
-
import { logError } from '../console/logging.js';
|
|
4
|
-
/**
|
|
5
|
-
* Copy a file to target locale without translation
|
|
6
|
-
*
|
|
7
|
-
* This is a naive approach, does not allow for wild cards
|
|
8
|
-
*/
|
|
9
|
-
export default async function copyFile(settings) {
|
|
10
|
-
if (!settings.options?.copyFiles || settings.options.copyFiles.length === 0) {
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
// Construct a map of source paths to target paths
|
|
14
|
-
const copyFiles = settings.options.copyFiles.reduce((paths, filePathTemplate) => {
|
|
15
|
-
const sourcePath = path.join(process.cwd(), filePathTemplate.replace('[locale]', settings.defaultLocale));
|
|
16
|
-
if (!fs.existsSync(sourcePath)) {
|
|
17
|
-
logError(`Failed to copy files: File path does not exist: ${sourcePath}`);
|
|
18
|
-
return paths;
|
|
19
|
-
}
|
|
20
|
-
paths[sourcePath] = [];
|
|
21
|
-
for (const locale of settings.locales) {
|
|
22
|
-
if (locale === settings.defaultLocale)
|
|
23
|
-
continue;
|
|
24
|
-
const targetPath = path.join(process.cwd(), filePathTemplate.replace('[locale]', locale));
|
|
25
|
-
paths[sourcePath].push(targetPath);
|
|
26
|
-
}
|
|
27
|
-
return paths;
|
|
28
|
-
}, {});
|
|
29
|
-
// Copy each file to the target locale
|
|
30
|
-
for (const sourcePath in copyFiles) {
|
|
31
|
-
for (const targetPath of copyFiles[sourcePath]) {
|
|
32
|
-
// Ensure the target directory exists
|
|
33
|
-
const targetDir = path.dirname(targetPath);
|
|
34
|
-
await fs.promises.mkdir(targetDir, { recursive: true });
|
|
35
|
-
// Copy the file
|
|
36
|
-
await fs.promises.copyFile(sourcePath, targetPath);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function createLoadTranslationsFile(appDirectory: string, translationsDir?: string): Promise<void>;
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import { logInfo } from '../console/logging.js';
|
|
4
|
-
import chalk from 'chalk';
|
|
5
|
-
export async function createLoadTranslationsFile(appDirectory, translationsDir = './public/_gt') {
|
|
6
|
-
const usingSrcDirectory = fs.existsSync(path.join(appDirectory, 'src'));
|
|
7
|
-
// Calculate the relative path from the loadTranslations.js location to the translations directory
|
|
8
|
-
const loadTranslationsDir = usingSrcDirectory
|
|
9
|
-
? path.join(appDirectory, 'src')
|
|
10
|
-
: appDirectory;
|
|
11
|
-
const relativePath = path.relative(loadTranslationsDir, path.resolve(appDirectory, translationsDir));
|
|
12
|
-
const publicPath = relativePath ? `${relativePath}/` : './';
|
|
13
|
-
const filePath = usingSrcDirectory
|
|
14
|
-
? path.join(appDirectory, 'src', 'loadTranslations.js')
|
|
15
|
-
: path.join(appDirectory, 'loadTranslations.js');
|
|
16
|
-
if (!fs.existsSync(filePath)) {
|
|
17
|
-
const loadTranslationsContent = `
|
|
18
|
-
export default async function loadTranslations(locale) {
|
|
19
|
-
try {
|
|
20
|
-
// Load translations from ${translationsDir} directory
|
|
21
|
-
// This matches the GT config files.gt.output path
|
|
22
|
-
const t = await import(\`${publicPath}\${locale}.json\`);
|
|
23
|
-
return t.default;
|
|
24
|
-
} catch (error) {
|
|
25
|
-
console.warn(\`Failed to load translations for locale \${locale}:\`, error);
|
|
26
|
-
return {};
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
`;
|
|
30
|
-
await fs.promises.writeFile(filePath, loadTranslationsContent);
|
|
31
|
-
logInfo(`Created ${chalk.cyan('loadTranslations.js')} file at ${chalk.cyan(filePath)}.`);
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
logInfo(`Found ${chalk.cyan('loadTranslations.js')} file at ${chalk.cyan(filePath)}. Skipping creation...`);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import chalk from 'chalk';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import fs from 'node:fs';
|
|
4
|
-
import { logError } from '../console/logging.js';
|
|
5
|
-
export function determineLibrary() {
|
|
6
|
-
let library = 'base';
|
|
7
|
-
const additionalModules = [];
|
|
8
|
-
try {
|
|
9
|
-
// Get the current working directory (where the CLI is being run)
|
|
10
|
-
const cwd = process.cwd();
|
|
11
|
-
const packageJsonPath = path.join(cwd, 'package.json');
|
|
12
|
-
// Check if package.json exists
|
|
13
|
-
if (!fs.existsSync(packageJsonPath)) {
|
|
14
|
-
logError(chalk.red('No package.json found in the current directory. Please run this command from the root of your project.'));
|
|
15
|
-
return { library: 'base', additionalModules: [] };
|
|
16
|
-
}
|
|
17
|
-
// Read and parse package.json
|
|
18
|
-
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
19
|
-
const dependencies = {
|
|
20
|
-
...packageJson.dependencies,
|
|
21
|
-
...packageJson.devDependencies,
|
|
22
|
-
};
|
|
23
|
-
// Check for gt-next or gt-react in dependencies
|
|
24
|
-
if (dependencies['gt-next']) {
|
|
25
|
-
library = 'gt-next';
|
|
26
|
-
}
|
|
27
|
-
else if (dependencies['gt-react']) {
|
|
28
|
-
library = 'gt-react';
|
|
29
|
-
}
|
|
30
|
-
else if (dependencies['next-intl']) {
|
|
31
|
-
library = 'next-intl';
|
|
32
|
-
}
|
|
33
|
-
else if (dependencies['i18next']) {
|
|
34
|
-
library = 'i18next';
|
|
35
|
-
}
|
|
36
|
-
if (dependencies['i18next-icu']) {
|
|
37
|
-
additionalModules.push('i18next-icu');
|
|
38
|
-
}
|
|
39
|
-
// Fallback to base if neither is found
|
|
40
|
-
return { library, additionalModules };
|
|
41
|
-
}
|
|
42
|
-
catch (error) {
|
|
43
|
-
logError('Error determining framework: ' + String(error));
|
|
44
|
-
return { library: 'base', additionalModules: [] };
|
|
45
|
-
}
|
|
46
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Resolve the file path from the given file path or default paths.
|
|
3
|
-
* @param {string} filePath - The file path to resolve.
|
|
4
|
-
* @param {string[]} defaultPaths - The default paths to check.
|
|
5
|
-
* @returns {string} - The resolved file path.
|
|
6
|
-
*/
|
|
7
|
-
export default function findFilepath(paths: string[], errorMessage?: string): string;
|
|
8
|
-
/**
|
|
9
|
-
* Resolve the file paths from the given file paths or default paths.
|
|
10
|
-
* @param {string[]} paths - The file paths to resolve.
|
|
11
|
-
* @param {string} errorMessage - The error message to throw if no paths are found.
|
|
12
|
-
* @returns {string[]} - The resolved file paths.
|
|
13
|
-
*/
|
|
14
|
-
export declare function findFilepaths(paths: string[], errorMessage?: string): string[];
|
|
15
|
-
export declare function getRelativePath(file: string, srcDirectory: string): string;
|
|
16
|
-
/**
|
|
17
|
-
* Find a file in a directory based on a wildcard pattern.
|
|
18
|
-
* @param {string} filePattern - The wildcard pattern to search for.
|
|
19
|
-
* @param {string} file - The file to search for.
|
|
20
|
-
* @returns {string} - The path to the file.
|
|
21
|
-
*/
|
|
22
|
-
export declare function findFile(filePattern: string, file: string): string;
|
|
23
|
-
/**
|
|
24
|
-
* Read a file and return the contents.
|
|
25
|
-
* @param {string} filePath - The path to the file to read.
|
|
26
|
-
* @returns {string} - The contents of the file.
|
|
27
|
-
*/
|
|
28
|
-
export declare function readFile(filePath: string): string;
|
|
29
|
-
/**
|
|
30
|
-
* Find a file in a directory.
|
|
31
|
-
* @param {string} dir - The directory to search in.
|
|
32
|
-
* @param {string} file - The file to search for.
|
|
33
|
-
* @returns {string} - The path to the file.
|
|
34
|
-
*/
|
|
35
|
-
export declare function findFileInDir(dir: string, file: string): string;
|
|
36
|
-
export declare function getRelative(absolutePath: string): string;
|