gtx-cli 2.6.31 → 2.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -1261
- package/README.md +12 -3
- package/dist/bin/bin-entry.js +2 -1
- package/dist/config/generateSettings.d.ts +1 -9
- package/dist/config/generateSettings.js +1 -214
- package/dist/config/resolveConfig.d.ts +1 -4
- package/dist/config/resolveConfig.js +1 -33
- package/dist/fs/config/setupConfig.d.ts +1 -17
- package/dist/fs/config/setupConfig.js +1 -50
- package/dist/fs/matchFiles.d.ts +1 -1
- package/dist/fs/matchFiles.js +1 -8
- package/dist/functions.d.ts +1 -7
- package/dist/functions.js +1 -6
- package/dist/index.d.ts +1 -4
- package/dist/index.js +1 -27
- package/dist/main.js +2 -2
- package/dist/next/parse/handleInitGT.d.ts +1 -7
- package/dist/next/parse/handleInitGT.js +1 -157
- package/dist/next/parse/wrapContent.d.ts +1 -12
- package/dist/next/parse/wrapContent.js +1 -164
- package/dist/react/parse/wrapContent.d.ts +1 -12
- package/dist/react/parse/wrapContent.js +1 -162
- package/dist/types/index.d.ts +1 -243
- package/dist/types/index.js +1 -1
- package/dist/utils/installPackage.d.ts +1 -3
- package/dist/utils/installPackage.js +1 -77
- package/dist/utils/packageInfo.d.ts +1 -3
- package/dist/utils/packageInfo.js +1 -17
- package/dist/utils/packageJson.d.ts +1 -6
- package/dist/utils/packageJson.js +1 -68
- package/dist/utils/packageManager.d.ts +1 -28
- package/dist/utils/packageManager.js +1 -269
- package/package.json +11 -97
- package/dist/api/collectUserEditDiffs.d.ts +0 -9
- package/dist/api/collectUserEditDiffs.js +0 -159
- package/dist/api/downloadFileBatch.d.ts +0 -23
- package/dist/api/downloadFileBatch.js +0 -190
- package/dist/api/saveLocalEdits.d.ts +0 -6
- package/dist/api/saveLocalEdits.js +0 -38
- package/dist/cli/base.d.ts +0 -59
- package/dist/cli/base.js +0 -529
- package/dist/cli/commands/download.d.ts +0 -8
- package/dist/cli/commands/download.js +0 -51
- package/dist/cli/commands/enqueue.d.ts +0 -9
- package/dist/cli/commands/enqueue.js +0 -27
- package/dist/cli/commands/setupProject.d.ts +0 -7
- package/dist/cli/commands/setupProject.js +0 -37
- package/dist/cli/commands/stage.d.ts +0 -9
- package/dist/cli/commands/stage.js +0 -59
- package/dist/cli/commands/translate.d.ts +0 -7
- package/dist/cli/commands/translate.js +0 -70
- package/dist/cli/commands/upload.d.ts +0 -13
- package/dist/cli/commands/upload.js +0 -142
- package/dist/cli/commands/utils/validation.d.ts +0 -13
- package/dist/cli/commands/utils/validation.js +0 -38
- package/dist/cli/flags.d.ts +0 -15
- package/dist/cli/flags.js +0 -70
- package/dist/cli/inline.d.ts +0 -17
- package/dist/cli/inline.js +0 -135
- package/dist/cli/next.d.ts +0 -10
- package/dist/cli/next.js +0 -12
- package/dist/cli/node.d.ts +0 -10
- package/dist/cli/node.js +0 -9
- package/dist/cli/react.d.ts +0 -12
- package/dist/cli/react.js +0 -72
- package/dist/config/optionPresets.d.ts +0 -3
- package/dist/config/optionPresets.js +0 -65
- 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 -6
- package/dist/console/colors.js +0 -19
- package/dist/console/displayTranslateSummary.d.ts +0 -1
- package/dist/console/displayTranslateSummary.js +0 -42
- package/dist/console/formatting.d.ts +0 -1
- package/dist/console/formatting.js +0 -7
- package/dist/console/index.d.ts +0 -34
- package/dist/console/index.js +0 -46
- package/dist/console/logger.d.ts +0 -35
- package/dist/console/logger.js +0 -250
- package/dist/console/logging.d.ts +0 -52
- package/dist/console/logging.js +0 -175
- package/dist/formats/files/aggregateFiles.d.ts +0 -4
- package/dist/formats/files/aggregateFiles.js +0 -156
- package/dist/formats/files/collectFiles.d.ts +0 -6
- package/dist/formats/files/collectFiles.js +0 -49
- package/dist/formats/files/convertToFileTranslationData.d.ts +0 -15
- package/dist/formats/files/convertToFileTranslationData.js +0 -21
- package/dist/formats/files/fileMapping.d.ts +0 -11
- package/dist/formats/files/fileMapping.js +0 -115
- package/dist/formats/files/preprocess/mdx.d.ts +0 -6
- package/dist/formats/files/preprocess/mdx.js +0 -14
- package/dist/formats/files/preprocess/mintlify.d.ts +0 -5
- package/dist/formats/files/preprocess/mintlify.js +0 -15
- package/dist/formats/files/preprocessContent.d.ts +0 -8
- package/dist/formats/files/preprocessContent.js +0 -23
- 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 -11
- package/dist/formats/files/supportedFiles.js +0 -20
- package/dist/formats/json/extractJson.d.ts +0 -15
- package/dist/formats/json/extractJson.js +0 -101
- 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 -367
- package/dist/formats/json/parseJson.d.ts +0 -2
- package/dist/formats/json/parseJson.js +0 -109
- package/dist/formats/json/utils.d.ts +0 -47
- package/dist/formats/json/utils.js +0 -150
- 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 -61
- package/dist/formats/yaml/parseYaml.d.ts +0 -5
- package/dist/formats/yaml/parseYaml.js +0 -24
- package/dist/formats/yaml/utils.d.ts +0 -2
- package/dist/formats/yaml/utils.js +0 -23
- package/dist/fs/clearLocaleDirs.d.ts +0 -8
- package/dist/fs/clearLocaleDirs.js +0 -126
- package/dist/fs/config/downloadedVersions.d.ts +0 -21
- package/dist/fs/config/downloadedVersions.js +0 -50
- 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 -150
- package/dist/fs/config/updateConfig.d.ts +0 -21
- package/dist/fs/config/updateConfig.js +0 -57
- package/dist/fs/config/updateVersions.d.ts +0 -11
- 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 -49
- package/dist/fs/determineFramework.d.ts +0 -5
- package/dist/fs/determineFramework.js +0 -53
- package/dist/fs/findFilepath.d.ts +0 -36
- package/dist/fs/findFilepath.js +0 -90
- 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/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/generated/version.d.ts +0 -1
- package/dist/generated/version.js +0 -2
- package/dist/git/branches.d.ts +0 -7
- package/dist/git/branches.js +0 -88
- package/dist/hooks/postProcess.d.ts +0 -4
- package/dist/hooks/postProcess.js +0 -110
- package/dist/locadex/setupFlow.d.ts +0 -2
- package/dist/locadex/setupFlow.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/react/config/createESBuildConfig.d.ts +0 -2
- package/dist/react/config/createESBuildConfig.js +0 -119
- package/dist/react/jsx/evaluateJsx.d.ts +0 -24
- package/dist/react/jsx/evaluateJsx.js +0 -123
- package/dist/react/jsx/utils/buildImportMap.d.ts +0 -9
- package/dist/react/jsx/utils/buildImportMap.js +0 -30
- package/dist/react/jsx/utils/constants.d.ts +0 -15
- package/dist/react/jsx/utils/constants.js +0 -49
- package/dist/react/jsx/utils/getCalleeNameFromExpression.d.ts +0 -9
- package/dist/react/jsx/utils/getCalleeNameFromExpression.js +0 -32
- package/dist/react/jsx/utils/getPathsAndAliases.d.ts +0 -21
- package/dist/react/jsx/utils/getPathsAndAliases.js +0 -91
- package/dist/react/jsx/utils/isNumberLiteral.d.ts +0 -7
- package/dist/react/jsx/utils/isNumberLiteral.js +0 -13
- package/dist/react/jsx/utils/jsxParsing/addGTIdentifierToSyntaxTree.d.ts +0 -9
- package/dist/react/jsx/utils/jsxParsing/addGTIdentifierToSyntaxTree.js +0 -138
- package/dist/react/jsx/utils/jsxParsing/handleChildrenWhitespace.d.ts +0 -6
- package/dist/react/jsx/utils/jsxParsing/handleChildrenWhitespace.js +0 -197
- package/dist/react/jsx/utils/jsxParsing/multiplication/findMultiplicationNode.d.ts +0 -13
- package/dist/react/jsx/utils/jsxParsing/multiplication/findMultiplicationNode.js +0 -42
- package/dist/react/jsx/utils/jsxParsing/multiplication/multiplyJsxTree.d.ts +0 -5
- package/dist/react/jsx/utils/jsxParsing/multiplication/multiplyJsxTree.js +0 -69
- package/dist/react/jsx/utils/jsxParsing/parseJsx.d.ts +0 -33
- package/dist/react/jsx/utils/jsxParsing/parseJsx.js +0 -918
- package/dist/react/jsx/utils/jsxParsing/parseTProps.d.ts +0 -8
- package/dist/react/jsx/utils/jsxParsing/parseTProps.js +0 -65
- package/dist/react/jsx/utils/jsxParsing/removeNullChildrenFields.d.ts +0 -2
- package/dist/react/jsx/utils/jsxParsing/removeNullChildrenFields.js +0 -61
- package/dist/react/jsx/utils/jsxParsing/types.d.ts +0 -48
- package/dist/react/jsx/utils/jsxParsing/types.js +0 -34
- package/dist/react/jsx/utils/mapAttributeName.d.ts +0 -11
- package/dist/react/jsx/utils/mapAttributeName.js +0 -12
- package/dist/react/jsx/utils/parseAst.d.ts +0 -31
- package/dist/react/jsx/utils/parseAst.js +0 -278
- package/dist/react/jsx/utils/parseDeclareStatic.d.ts +0 -15
- package/dist/react/jsx/utils/parseDeclareStatic.js +0 -540
- package/dist/react/jsx/utils/parseString.d.ts +0 -25
- package/dist/react/jsx/utils/parseString.js +0 -540
- package/dist/react/jsx/utils/parseStringFunction.d.ts +0 -30
- package/dist/react/jsx/utils/parseStringFunction.js +0 -348
- package/dist/react/jsx/utils/resolveImportPath.d.ts +0 -11
- package/dist/react/jsx/utils/resolveImportPath.js +0 -111
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/extractStringEntryMetadata.d.ts +0 -29
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/extractStringEntryMetadata.js +0 -86
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleInvalidTranslationCall.d.ts +0 -14
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleInvalidTranslationCall.js +0 -24
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleLiteralTranslationCall.d.ts +0 -19
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleLiteralTranslationCall.js +0 -31
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleStaticTranslationCall.d.ts +0 -22
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleStaticTranslationCall.js +0 -51
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/index.d.ts +0 -18
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/index.js +0 -39
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/routeTranslationCall.d.ts +0 -24
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/routeTranslationCall.js +0 -68
- package/dist/react/jsx/utils/stringParsing/types.d.ts +0 -41
- package/dist/react/jsx/utils/stringParsing/types.js +0 -1
- package/dist/react/jsx/utils/types.d.ts +0 -14
- package/dist/react/jsx/utils/types.js +0 -1
- 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/addVitePlugin/index.d.ts +0 -22
- package/dist/react/parse/addVitePlugin/index.js +0 -41
- package/dist/react/parse/addVitePlugin/installCompiler.d.ts +0 -8
- package/dist/react/parse/addVitePlugin/installCompiler.js +0 -22
- package/dist/react/parse/addVitePlugin/updateViteConfig.d.ts +0 -19
- package/dist/react/parse/addVitePlugin/updateViteConfig.js +0 -120
- package/dist/react/parse/addVitePlugin/utils/addCompilerImport.d.ts +0 -9
- package/dist/react/parse/addVitePlugin/utils/addCompilerImport.js +0 -34
- package/dist/react/parse/addVitePlugin/utils/addPluginInvocation.d.ts +0 -11
- package/dist/react/parse/addVitePlugin/utils/addPluginInvocation.js +0 -48
- package/dist/react/parse/addVitePlugin/utils/checkCompilerImport.d.ts +0 -15
- package/dist/react/parse/addVitePlugin/utils/checkCompilerImport.js +0 -113
- package/dist/react/parse/addVitePlugin/utils/checkPluginInvocation.d.ts +0 -12
- package/dist/react/parse/addVitePlugin/utils/checkPluginInvocation.js +0 -32
- package/dist/react/parse/createDictionaryUpdates.d.ts +0 -3
- package/dist/react/parse/createDictionaryUpdates.js +0 -187
- package/dist/react/parse/createInlineUpdates.d.ts +0 -13
- package/dist/react/parse/createInlineUpdates.js +0 -161
- 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/agentInstructions.d.ts +0 -24
- package/dist/setup/agentInstructions.js +0 -138
- package/dist/setup/detectFramework.d.ts +0 -31
- package/dist/setup/detectFramework.js +0 -106
- package/dist/setup/frameworkUtils.d.ts +0 -3
- package/dist/setup/frameworkUtils.js +0 -30
- package/dist/setup/instructions/base.md +0 -29
- package/dist/setup/instructions/gt-next.md +0 -107
- package/dist/setup/instructions/gt-react.md +0 -98
- package/dist/setup/userInput.d.ts +0 -4
- package/dist/setup/userInput.js +0 -32
- package/dist/setup/wizard.d.ts +0 -3
- package/dist/setup/wizard.js +0 -147
- package/dist/state/recentDownloads.d.ts +0 -12
- package/dist/state/recentDownloads.js +0 -18
- package/dist/state/translateWarnings.d.ts +0 -10
- package/dist/state/translateWarnings.js +0 -13
- package/dist/translation/parse.d.ts +0 -17
- package/dist/translation/parse.js +0 -77
- package/dist/translation/stage.d.ts +0 -3
- package/dist/translation/stage.js +0 -44
- package/dist/translation/validate.d.ts +0 -14
- package/dist/translation/validate.js +0 -100
- package/dist/types/branch.d.ts +0 -14
- package/dist/types/branch.js +0 -1
- package/dist/types/data/json.d.ts +0 -6
- package/dist/types/data/json.js +0 -1
- package/dist/types/data.d.ts +0 -37
- package/dist/types/data.js +0 -1
- package/dist/types/files.d.ts +0 -8
- package/dist/types/files.js +0 -1
- package/dist/types/libraries.d.ts +0 -31
- package/dist/types/libraries.js +0 -72
- package/dist/types/parsing.d.ts +0 -3
- package/dist/types/parsing.js +0 -1
- package/dist/utils/addExplicitAnchorIds.d.ts +0 -24
- package/dist/utils/addExplicitAnchorIds.js +0 -416
- package/dist/utils/constants.d.ts +0 -5
- package/dist/utils/constants.js +0 -6
- package/dist/utils/credentials.d.ts +0 -12
- package/dist/utils/credentials.js +0 -120
- package/dist/utils/flattenJsonFiles.d.ts +0 -2
- package/dist/utils/flattenJsonFiles.js +0 -36
- package/dist/utils/gitDiff.d.ts +0 -8
- package/dist/utils/gitDiff.js +0 -34
- 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/localizeRelativeAssets.d.ts +0 -8
- package/dist/utils/localizeRelativeAssets.js +0 -166
- package/dist/utils/localizeStaticImports.d.ts +0 -15
- package/dist/utils/localizeStaticImports.js +0 -397
- package/dist/utils/localizeStaticUrls.d.ts +0 -19
- package/dist/utils/localizeStaticUrls.js +0 -450
- package/dist/utils/mintlifyTitleFallback.d.ts +0 -6
- package/dist/utils/mintlifyTitleFallback.js +0 -80
- package/dist/utils/parse/needsCJS.d.ts +0 -20
- package/dist/utils/parse/needsCJS.js +0 -72
- package/dist/utils/persistPostprocessHashes.d.ts +0 -12
- package/dist/utils/persistPostprocessHashes.js +0 -39
- package/dist/utils/processAnchorIds.d.ts +0 -6
- package/dist/utils/processAnchorIds.js +0 -56
- package/dist/utils/processOpenApi.d.ts +0 -8
- package/dist/utils/processOpenApi.js +0 -651
- package/dist/utils/sanitizeFileContent.d.ts +0 -6
- package/dist/utils/sanitizeFileContent.js +0 -29
- package/dist/utils/sharedStaticAssets.d.ts +0 -9
- package/dist/utils/sharedStaticAssets.js +0 -384
- package/dist/utils/validateMdx.d.ts +0 -10
- package/dist/utils/validateMdx.js +0 -25
- package/dist/utils/wrapPlainUrls.d.ts +0 -8
- package/dist/utils/wrapPlainUrls.js +0 -72
- package/dist/workflows/download.d.ts +0 -32
- package/dist/workflows/download.js +0 -131
- package/dist/workflows/enqueue.d.ts +0 -17
- package/dist/workflows/enqueue.js +0 -59
- package/dist/workflows/setupProject.d.ts +0 -13
- package/dist/workflows/setupProject.js +0 -48
- package/dist/workflows/stage.d.ts +0 -18
- package/dist/workflows/stage.js +0 -59
- package/dist/workflows/steps/BranchStep.d.ts +0 -13
- package/dist/workflows/steps/BranchStep.js +0 -161
- package/dist/workflows/steps/DownloadStep.d.ts +0 -19
- package/dist/workflows/steps/DownloadStep.js +0 -131
- package/dist/workflows/steps/EnqueueStep.d.ts +0 -15
- package/dist/workflows/steps/EnqueueStep.js +0 -33
- package/dist/workflows/steps/PollJobsStep.d.ts +0 -31
- package/dist/workflows/steps/PollJobsStep.js +0 -288
- package/dist/workflows/steps/SetupStep.d.ts +0 -16
- package/dist/workflows/steps/SetupStep.js +0 -72
- package/dist/workflows/steps/UploadSourcesStep.d.ts +0 -27
- package/dist/workflows/steps/UploadSourcesStep.js +0 -131
- package/dist/workflows/steps/UploadTranslationsStep.d.ts +0 -22
- package/dist/workflows/steps/UploadTranslationsStep.js +0 -71
- package/dist/workflows/steps/UserEditDiffsStep.d.ts +0 -11
- package/dist/workflows/steps/UserEditDiffsStep.js +0 -30
- package/dist/workflows/steps/WorkflowStep.d.ts +0 -4
- package/dist/workflows/steps/WorkflowStep.js +0 -2
- package/dist/workflows/upload.d.ts +0 -15
- package/dist/workflows/upload.js +0 -47
package/dist/formats/utils.d.ts
DELETED
package/dist/formats/utils.js
DELETED
|
@@ -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,61 +0,0 @@
|
|
|
1
|
-
import JSONPointer from 'jsonpointer';
|
|
2
|
-
import { exitSync } from '../../console/logging.js';
|
|
3
|
-
import { logger } from '../../console/logger.js';
|
|
4
|
-
import { validateYamlSchema } from './utils.js';
|
|
5
|
-
import YAML from 'yaml';
|
|
6
|
-
import { applyTransformations } from '../json/mergeJson.js';
|
|
7
|
-
export default function mergeYaml(originalContent, inputPath, options, targets, defaultLocale) {
|
|
8
|
-
const yamlSchema = validateYamlSchema(options, inputPath);
|
|
9
|
-
if (!yamlSchema) {
|
|
10
|
-
return targets.map((target) => target.translatedContent);
|
|
11
|
-
}
|
|
12
|
-
let originalYaml;
|
|
13
|
-
try {
|
|
14
|
-
originalYaml = YAML.parse(originalContent);
|
|
15
|
-
}
|
|
16
|
-
catch {
|
|
17
|
-
logger.error(`Invalid YAML file: ${inputPath}`);
|
|
18
|
-
return exitSync(1);
|
|
19
|
-
}
|
|
20
|
-
// Unreachable (validated in validateYamlSchema, included for type check)
|
|
21
|
-
if (!yamlSchema.include) {
|
|
22
|
-
logger.error('No include property found in YAML schema');
|
|
23
|
-
return exitSync(1);
|
|
24
|
-
}
|
|
25
|
-
// Handle include
|
|
26
|
-
const output = [];
|
|
27
|
-
for (const target of targets) {
|
|
28
|
-
// Must clone the original YAML to avoid mutations
|
|
29
|
-
const mergedYaml = JSON.parse(JSON.stringify(originalYaml));
|
|
30
|
-
let translatedJson;
|
|
31
|
-
try {
|
|
32
|
-
translatedJson = JSON.parse(target.translatedContent);
|
|
33
|
-
}
|
|
34
|
-
catch {
|
|
35
|
-
// If parsing fails, treat as empty object to avoid crashes
|
|
36
|
-
translatedJson = {};
|
|
37
|
-
}
|
|
38
|
-
for (const [jsonPointer, translatedValue] of Object.entries(translatedJson)) {
|
|
39
|
-
try {
|
|
40
|
-
// Try to get the value - if this succeeds, the pointer exists
|
|
41
|
-
if (JSONPointer.get(mergedYaml, jsonPointer) == null) {
|
|
42
|
-
continue;
|
|
43
|
-
}
|
|
44
|
-
// Set the new value regardless of what the current value is (including null/falsy)
|
|
45
|
-
JSONPointer.set(mergedYaml, jsonPointer, translatedValue);
|
|
46
|
-
}
|
|
47
|
-
catch {
|
|
48
|
-
// Silently ignore invalid or non-existent JSON pointers
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
// Apply transformations if they exist
|
|
52
|
-
if (yamlSchema.transform) {
|
|
53
|
-
applyTransformations(mergedYaml, yamlSchema.transform, target.targetLocale, defaultLocale);
|
|
54
|
-
}
|
|
55
|
-
output.push(YAML.stringify(mergedYaml));
|
|
56
|
-
}
|
|
57
|
-
if (!output.length) {
|
|
58
|
-
return [originalContent];
|
|
59
|
-
}
|
|
60
|
-
return output;
|
|
61
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { exitSync } from '../../console/logging.js';
|
|
2
|
-
import { logger } from '../../console/logger.js';
|
|
3
|
-
import YAML from 'yaml';
|
|
4
|
-
import { validateYamlSchema } from './utils.js';
|
|
5
|
-
import { flattenJsonWithStringFilter } from '../json/flattenJson.js';
|
|
6
|
-
export default function parseYaml(content, filePath, options) {
|
|
7
|
-
const yamlSchema = validateYamlSchema(options, filePath);
|
|
8
|
-
if (!yamlSchema) {
|
|
9
|
-
return { content, fileFormat: 'YAML' };
|
|
10
|
-
}
|
|
11
|
-
let yaml;
|
|
12
|
-
try {
|
|
13
|
-
yaml = YAML.parse(content);
|
|
14
|
-
}
|
|
15
|
-
catch {
|
|
16
|
-
logger.error(`Invalid YAML file: ${filePath}`);
|
|
17
|
-
return exitSync(1);
|
|
18
|
-
}
|
|
19
|
-
if (yamlSchema.include) {
|
|
20
|
-
const flattenedYaml = flattenJsonWithStringFilter(yaml, yamlSchema.include);
|
|
21
|
-
return { content: JSON.stringify(flattenedYaml), fileFormat: 'JSON' };
|
|
22
|
-
}
|
|
23
|
-
return { content, fileFormat: 'YAML' };
|
|
24
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { exitSync } from '../../console/logging.js';
|
|
2
|
-
import { logger } from '../../console/logger.js';
|
|
3
|
-
import micromatch from 'micromatch';
|
|
4
|
-
const { isMatch } = micromatch;
|
|
5
|
-
import path from 'path';
|
|
6
|
-
export function validateYamlSchema(options, filePath) {
|
|
7
|
-
if (!options.yamlSchema) {
|
|
8
|
-
return null;
|
|
9
|
-
}
|
|
10
|
-
// Check if the file matches any of the yaml schema globs
|
|
11
|
-
const fileGlobs = Object.keys(options.yamlSchema);
|
|
12
|
-
const matchingGlob = fileGlobs.find((fileGlob) => isMatch(path.relative(process.cwd(), filePath), fileGlob));
|
|
13
|
-
if (!matchingGlob || !options.yamlSchema[matchingGlob]) {
|
|
14
|
-
return null;
|
|
15
|
-
}
|
|
16
|
-
// Validate includes
|
|
17
|
-
const yamlSchema = options.yamlSchema[matchingGlob];
|
|
18
|
-
if (!yamlSchema.include) {
|
|
19
|
-
logger.error('No include property found in YAML schema');
|
|
20
|
-
return exitSync(1);
|
|
21
|
-
}
|
|
22
|
-
return yamlSchema;
|
|
23
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Clears translated files before writing new translations
|
|
3
|
-
* @param filePaths - Set of translated file paths to clear
|
|
4
|
-
* @param locales - Array of locale codes to match against
|
|
5
|
-
* @param excludePatterns - Optional array of glob patterns to exclude from clearing (supports [locale] and [locales])
|
|
6
|
-
* @param cwd - Current working directory for resolving relative exclude patterns (defaults to process.cwd())
|
|
7
|
-
*/
|
|
8
|
-
export declare function clearLocaleDirs(filePaths: Set<string>, locales: string[], excludePatterns?: string[], cwd?: string): Promise<void>;
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import fs from 'fs/promises';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import { logger } from '../console/logger.js';
|
|
4
|
-
import fg from 'fast-glob';
|
|
5
|
-
import micromatch from 'micromatch';
|
|
6
|
-
/**
|
|
7
|
-
* Extracts locale directories from translated file paths.
|
|
8
|
-
* Groups files by their immediate parent containing a locale code.
|
|
9
|
-
* For example: "snippets/es/api-test/file.mdx" -> "snippets/es"
|
|
10
|
-
*/
|
|
11
|
-
function extractLocaleDirectories(filePaths, locales) {
|
|
12
|
-
const localeDirs = new Set();
|
|
13
|
-
const localeSet = new Set(locales);
|
|
14
|
-
for (const filePath of filePaths) {
|
|
15
|
-
const parts = filePath.split(path.sep);
|
|
16
|
-
// Find directory segments that match the provided locales
|
|
17
|
-
for (let i = 0; i < parts.length - 1; i++) {
|
|
18
|
-
const segment = parts[i];
|
|
19
|
-
if (localeSet.has(segment)) {
|
|
20
|
-
// Found a locale directory, capture up to and including this segment
|
|
21
|
-
const localeDir = parts.slice(0, i + 1).join(path.sep);
|
|
22
|
-
localeDirs.add(localeDir);
|
|
23
|
-
break;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return localeDirs;
|
|
28
|
-
}
|
|
29
|
-
async function getAllFiles(dirPath) {
|
|
30
|
-
return await fg(path.join(dirPath, '**/*'), {
|
|
31
|
-
absolute: true,
|
|
32
|
-
onlyFiles: true,
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
async function getFilesToDelete(dirPath, excludePatterns, currentLocale, cwd) {
|
|
36
|
-
const allFiles = await getAllFiles(dirPath);
|
|
37
|
-
const absoluteCwd = path.resolve(cwd);
|
|
38
|
-
const expandedExcludePatterns = excludePatterns.map((p) => {
|
|
39
|
-
const resolvedPattern = path.isAbsolute(p) ? p : path.join(absoluteCwd, p);
|
|
40
|
-
return resolvedPattern
|
|
41
|
-
.replace(/\[locale\]/g, currentLocale)
|
|
42
|
-
.replace(/\[locales\]/g, currentLocale);
|
|
43
|
-
});
|
|
44
|
-
const filesToKeep = micromatch(allFiles, expandedExcludePatterns, {
|
|
45
|
-
dot: true,
|
|
46
|
-
});
|
|
47
|
-
const filesToKeepSet = new Set(filesToKeep);
|
|
48
|
-
return allFiles.filter((file) => !filesToKeepSet.has(file));
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Clears translated files before writing new translations
|
|
52
|
-
* @param filePaths - Set of translated file paths to clear
|
|
53
|
-
* @param locales - Array of locale codes to match against
|
|
54
|
-
* @param excludePatterns - Optional array of glob patterns to exclude from clearing (supports [locale] and [locales])
|
|
55
|
-
* @param cwd - Current working directory for resolving relative exclude patterns (defaults to process.cwd())
|
|
56
|
-
*/
|
|
57
|
-
export async function clearLocaleDirs(filePaths, locales, excludePatterns, cwd = process.cwd()) {
|
|
58
|
-
// Extract locale directories
|
|
59
|
-
const localeDirs = extractLocaleDirectories(filePaths, locales);
|
|
60
|
-
for (const dir of localeDirs) {
|
|
61
|
-
try {
|
|
62
|
-
await fs.stat(dir);
|
|
63
|
-
// Extract locale from directory path
|
|
64
|
-
const dirParts = dir.split(path.sep);
|
|
65
|
-
const locale = locales.find((loc) => dirParts.includes(loc));
|
|
66
|
-
if (!locale) {
|
|
67
|
-
continue;
|
|
68
|
-
}
|
|
69
|
-
if (!excludePatterns?.length) {
|
|
70
|
-
await fs.rm(dir, { recursive: true, force: true });
|
|
71
|
-
logger.success(`Cleared locale directory: ${dir}`);
|
|
72
|
-
continue;
|
|
73
|
-
}
|
|
74
|
-
const filesToDelete = await getFilesToDelete(dir, excludePatterns, locale, cwd);
|
|
75
|
-
// Get all files for count comparison
|
|
76
|
-
const allFiles = await getAllFiles(dir);
|
|
77
|
-
for (const file of filesToDelete) {
|
|
78
|
-
try {
|
|
79
|
-
await fs.unlink(file);
|
|
80
|
-
}
|
|
81
|
-
catch (error) {
|
|
82
|
-
if (error.code !== 'ENOENT') {
|
|
83
|
-
logger.warn(`Failed to delete file ${file}: ${error}`);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
// Clean up empty directories
|
|
88
|
-
await cleanupEmptyDirs(dir);
|
|
89
|
-
const excludedCount = allFiles.length - filesToDelete.length;
|
|
90
|
-
if (excludedCount > 0) {
|
|
91
|
-
logger.success(`Cleared locale directory: ${dir} (excluded ${excludedCount} file${excludedCount > 1 ? 's' : ''})`);
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
logger.success(`Cleared locale directory: ${dir}`);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
catch (error) {
|
|
98
|
-
if (error.code !== 'ENOENT') {
|
|
99
|
-
logger.warn(`Failed to clear locale directory ${dir}: ${error}`);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Recursively removes empty directories
|
|
106
|
-
* @param dirPath - The directory to clean up
|
|
107
|
-
*/
|
|
108
|
-
async function cleanupEmptyDirs(dirPath) {
|
|
109
|
-
try {
|
|
110
|
-
const entries = await fs.readdir(dirPath, { withFileTypes: true });
|
|
111
|
-
// Recursively clean subdirectories first
|
|
112
|
-
for (const entry of entries) {
|
|
113
|
-
if (entry.isDirectory()) {
|
|
114
|
-
await cleanupEmptyDirs(path.join(dirPath, entry.name));
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
// Check if directory is now empty
|
|
118
|
-
const remainingEntries = await fs.readdir(dirPath);
|
|
119
|
-
if (remainingEntries.length === 0) {
|
|
120
|
-
await fs.rmdir(dirPath);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
catch (error) {
|
|
124
|
-
// Ignore errors - directory might not exist or might not be empty
|
|
125
|
-
}
|
|
126
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
export type DownloadedVersionEntry = {
|
|
2
|
-
fileName?: string;
|
|
3
|
-
updatedAt?: string;
|
|
4
|
-
postProcessHash?: string;
|
|
5
|
-
sourceHash?: string;
|
|
6
|
-
};
|
|
7
|
-
export type DownloadedVersions = {
|
|
8
|
-
version: number;
|
|
9
|
-
entries: {
|
|
10
|
-
[branchId: string]: {
|
|
11
|
-
[fileId: string]: {
|
|
12
|
-
[versionId: string]: {
|
|
13
|
-
[locale: string]: DownloadedVersionEntry;
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
};
|
|
18
|
-
};
|
|
19
|
-
export declare function getDownloadedVersions(configDirectory: string): DownloadedVersions;
|
|
20
|
-
export declare function saveDownloadedVersions(configDirectory: string, lock: DownloadedVersions): void;
|
|
21
|
-
export declare function ensureNestedObject(obj: any, path: string[]): any;
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import { logger } from '../../console/logger.js';
|
|
4
|
-
// New lock file name, use old name for deletion of legacy lock file
|
|
5
|
-
const GT_LOCK_FILE = 'gt-lock.json';
|
|
6
|
-
const LEGACY_DOWNLOADED_VERSIONS_FILE = 'downloaded-versions.json';
|
|
7
|
-
export function getDownloadedVersions(configDirectory) {
|
|
8
|
-
try {
|
|
9
|
-
// Clean up legacy lock files inside the config directory
|
|
10
|
-
const rootPath = path.join(process.cwd(), GT_LOCK_FILE);
|
|
11
|
-
const legacyPath = path.join(configDirectory, LEGACY_DOWNLOADED_VERSIONS_FILE);
|
|
12
|
-
try {
|
|
13
|
-
if (fs.existsSync(legacyPath)) {
|
|
14
|
-
fs.unlinkSync(legacyPath);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
catch { }
|
|
18
|
-
const filepath = fs.existsSync(rootPath) ? rootPath : null;
|
|
19
|
-
if (!filepath)
|
|
20
|
-
return { version: 1, entries: {} };
|
|
21
|
-
const raw = JSON.parse(fs.readFileSync(filepath, 'utf8'));
|
|
22
|
-
if (raw && typeof raw === 'object' && raw.version && raw.entries) {
|
|
23
|
-
return raw;
|
|
24
|
-
}
|
|
25
|
-
return { version: 1, entries: {} };
|
|
26
|
-
}
|
|
27
|
-
catch (error) {
|
|
28
|
-
logger.error(`An error occurred while getting downloaded versions: ${error}`);
|
|
29
|
-
return { version: 1, entries: {} };
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
export function saveDownloadedVersions(configDirectory, lock) {
|
|
33
|
-
try {
|
|
34
|
-
// Write the lock file to the repo root
|
|
35
|
-
const filepath = path.join(process.cwd(), GT_LOCK_FILE);
|
|
36
|
-
fs.mkdirSync(path.dirname(filepath), { recursive: true });
|
|
37
|
-
fs.writeFileSync(filepath, JSON.stringify(lock, null, 2));
|
|
38
|
-
}
|
|
39
|
-
catch (error) {
|
|
40
|
-
logger.error(`An error occurred while updating ${GT_LOCK_FILE}: ${error}`);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
export function ensureNestedObject(obj, path) {
|
|
44
|
-
return path.reduce((current, key, index) => {
|
|
45
|
-
if (index === path.length - 1)
|
|
46
|
-
return current;
|
|
47
|
-
current[key] = current[key] || {};
|
|
48
|
-
return current[key];
|
|
49
|
-
}, obj);
|
|
50
|
-
}
|
|
@@ -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 | TransformOption[], compositePatterns?: string[]): {
|
|
25
|
-
resolvedPaths: string[];
|
|
26
|
-
placeholderPaths: string[];
|
|
27
|
-
};
|
|
@@ -1,150 +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 { logger } from '../../console/logger.js';
|
|
5
|
-
import chalk from 'chalk';
|
|
6
|
-
import micromatch from 'micromatch';
|
|
7
|
-
/**
|
|
8
|
-
* Resolves the files from the files object
|
|
9
|
-
* Replaces [locale] with the actual locale in the files
|
|
10
|
-
*
|
|
11
|
-
* @param files - The files object
|
|
12
|
-
* @param locale - The locale to replace [locale] with
|
|
13
|
-
* @returns The resolved files
|
|
14
|
-
*/
|
|
15
|
-
export function resolveLocaleFiles(files, locale) {
|
|
16
|
-
const result = {};
|
|
17
|
-
for (const fileType of SUPPORTED_FILE_EXTENSIONS) {
|
|
18
|
-
result[fileType] = files[fileType]?.map((filepath) => filepath.replace(/\[locale\]/g, locale));
|
|
19
|
-
}
|
|
20
|
-
// Replace [locale] with locale in all paths
|
|
21
|
-
result.gt = files.gt?.replace(/\[locale\]/g, locale);
|
|
22
|
-
return result;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Resolves the files from the files object
|
|
26
|
-
* Performs glob pattern expansion on the files
|
|
27
|
-
* Replaces [locale] with the actual locale in the files
|
|
28
|
-
*
|
|
29
|
-
* @param files - The files object
|
|
30
|
-
* @returns The resolved files
|
|
31
|
-
*/
|
|
32
|
-
export function resolveFiles(files, locale, locales, cwd, compositePatterns) {
|
|
33
|
-
// Initialize result object with empty arrays for each file type
|
|
34
|
-
const result = {};
|
|
35
|
-
const placeholderResult = {};
|
|
36
|
-
const transformPaths = {};
|
|
37
|
-
// Process GT files
|
|
38
|
-
if (files.gt?.output) {
|
|
39
|
-
placeholderResult.gt = path.resolve(cwd, files.gt.output);
|
|
40
|
-
}
|
|
41
|
-
for (const fileType of SUPPORTED_FILE_EXTENSIONS) {
|
|
42
|
-
// ==== TRANSFORMS ==== //
|
|
43
|
-
const transform = files[fileType]?.transform;
|
|
44
|
-
if (transform &&
|
|
45
|
-
(typeof transform === 'string' ||
|
|
46
|
-
typeof transform === 'object' ||
|
|
47
|
-
Array.isArray(transform))) {
|
|
48
|
-
transformPaths[fileType] = transform;
|
|
49
|
-
}
|
|
50
|
-
// ==== PLACEHOLDERS ==== //
|
|
51
|
-
if (files[fileType]?.include) {
|
|
52
|
-
const filePaths = expandGlobPatterns(cwd, files[fileType].include, files[fileType]?.exclude || [], locale, locales, transformPaths[fileType] || undefined, compositePatterns);
|
|
53
|
-
result[fileType] = filePaths.resolvedPaths;
|
|
54
|
-
placeholderResult[fileType] = filePaths.placeholderPaths;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
return {
|
|
58
|
-
resolvedPaths: result,
|
|
59
|
-
placeholderPaths: placeholderResult,
|
|
60
|
-
transformPaths: transformPaths,
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
// Helper function to expand glob patterns
|
|
64
|
-
export function expandGlobPatterns(cwd, includePatterns, excludePatterns, locale, locales, transformPatterns, compositePatterns) {
|
|
65
|
-
// Expand glob patterns to include all matching files
|
|
66
|
-
const resolvedPaths = [];
|
|
67
|
-
const placeholderPaths = [];
|
|
68
|
-
// Process include patterns
|
|
69
|
-
for (const pattern of includePatterns) {
|
|
70
|
-
// Track positions where [locale] appears in the original pattern
|
|
71
|
-
// It must be included in the pattern, otherwise the CLI tool will not be able to find the correct output path
|
|
72
|
-
// Warn if it's not included
|
|
73
|
-
// Ignore if is composite pattern
|
|
74
|
-
if (!pattern.includes('[locale]') &&
|
|
75
|
-
!transformPatterns &&
|
|
76
|
-
!compositePatterns?.includes(pattern)) {
|
|
77
|
-
logger.warn(chalk.yellow(`Pattern "${pattern}" does not include [locale], so the CLI tool may incorrectly save translated files.`));
|
|
78
|
-
}
|
|
79
|
-
const localePositions = [];
|
|
80
|
-
let searchIndex = 0;
|
|
81
|
-
const localeTag = '[locale]';
|
|
82
|
-
while (true) {
|
|
83
|
-
const foundIndex = pattern.indexOf(localeTag, searchIndex);
|
|
84
|
-
if (foundIndex === -1)
|
|
85
|
-
break;
|
|
86
|
-
localePositions.push(foundIndex);
|
|
87
|
-
searchIndex = foundIndex + localeTag.length;
|
|
88
|
-
}
|
|
89
|
-
const expandedPattern = pattern.replace(/\[locale\]/g, locale);
|
|
90
|
-
// Resolve the absolute pattern path
|
|
91
|
-
const absolutePattern = path.resolve(cwd, expandedPattern);
|
|
92
|
-
// Prepare exclude patterns with locale replaced
|
|
93
|
-
const expandedExcludePatterns = Array.from(new Set(excludePatterns.flatMap((p) => locales.map((targetLocale) => path.resolve(cwd, p
|
|
94
|
-
.replace(/\[locale\]/g, locale)
|
|
95
|
-
.replace(/\[locales\]/g, targetLocale))))));
|
|
96
|
-
// Use fast-glob to find all matching files, excluding the patterns
|
|
97
|
-
const matches = fg.sync(absolutePattern, {
|
|
98
|
-
absolute: true,
|
|
99
|
-
ignore: expandedExcludePatterns,
|
|
100
|
-
});
|
|
101
|
-
resolvedPaths.push(...matches);
|
|
102
|
-
// For each match, create a version with [locale] in the correct positions
|
|
103
|
-
matches.forEach((match) => {
|
|
104
|
-
const absolutePath = path.resolve(cwd, match);
|
|
105
|
-
const patternPath = path.resolve(cwd, pattern);
|
|
106
|
-
let originalAbsolutePath = absolutePath;
|
|
107
|
-
if (localePositions.length > 0) {
|
|
108
|
-
const placeholderPath = buildPlaceholderPathFromPattern(patternPath, absolutePath, localeTag);
|
|
109
|
-
originalAbsolutePath = placeholderPath;
|
|
110
|
-
}
|
|
111
|
-
placeholderPaths.push(originalAbsolutePath);
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
return { resolvedPaths, placeholderPaths };
|
|
115
|
-
}
|
|
116
|
-
function buildPlaceholderPathFromPattern(patternPath, absolutePath, localeTag) {
|
|
117
|
-
if (!patternPath.includes(localeTag)) {
|
|
118
|
-
return absolutePath;
|
|
119
|
-
}
|
|
120
|
-
const posixPattern = toPosixPath(patternPath);
|
|
121
|
-
const posixPath = toPosixPath(absolutePath);
|
|
122
|
-
const baseRegex = micromatch.makeRe(posixPattern, {
|
|
123
|
-
literalBrackets: true,
|
|
124
|
-
});
|
|
125
|
-
const localeRegexSource = baseRegex.source.replace(/\\\[locale\\\]/g, '([^/]+)');
|
|
126
|
-
const flags = baseRegex.flags.includes('d')
|
|
127
|
-
? baseRegex.flags
|
|
128
|
-
: `${baseRegex.flags}d`;
|
|
129
|
-
const matcher = new RegExp(localeRegexSource, flags);
|
|
130
|
-
const match = matcher.exec(posixPath);
|
|
131
|
-
const matchWithIndices = match;
|
|
132
|
-
if (!match || !matchWithIndices.indices) {
|
|
133
|
-
return absolutePath;
|
|
134
|
-
}
|
|
135
|
-
let placeholderPosixPath = posixPath;
|
|
136
|
-
const indices = matchWithIndices.indices;
|
|
137
|
-
for (let i = indices.length - 1; i >= 1; i--) {
|
|
138
|
-
const [start, end] = indices[i];
|
|
139
|
-
if (start === -1 || end === -1)
|
|
140
|
-
continue;
|
|
141
|
-
placeholderPosixPath =
|
|
142
|
-
placeholderPosixPath.slice(0, start) +
|
|
143
|
-
localeTag +
|
|
144
|
-
placeholderPosixPath.slice(end);
|
|
145
|
-
}
|
|
146
|
-
return path.normalize(placeholderPosixPath);
|
|
147
|
-
}
|
|
148
|
-
function toPosixPath(value) {
|
|
149
|
-
return value.split(path.sep).join(path.posix.sep);
|
|
150
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Options for updating the config file.
|
|
3
|
-
*
|
|
4
|
-
* Since these are all string values, we can use null to mark them for removal
|
|
5
|
-
*/
|
|
6
|
-
type UpdateConfigOptions = {
|
|
7
|
-
projectId?: string | null;
|
|
8
|
-
_versionId?: string | null;
|
|
9
|
-
_branchId?: string | null;
|
|
10
|
-
stageTranslations?: boolean | null;
|
|
11
|
-
};
|
|
12
|
-
/**
|
|
13
|
-
* Update the config file version id, locales, and projectId (if necessary)
|
|
14
|
-
* @param {string} configFilepath - The path to the config file.
|
|
15
|
-
* @param {UpdateConfigOptions} options - The options to update the config file with.
|
|
16
|
-
* @returns {Promise<void>} - A promise that resolves when the config file is updated.
|
|
17
|
-
*
|
|
18
|
-
* Hint: Mark a field as null to remove it from the config file.
|
|
19
|
-
*/
|
|
20
|
-
export default function updateConfig(configFilepath: string, options: UpdateConfigOptions): Promise<void>;
|
|
21
|
-
export {};
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
|
-
import { displayUpdatedConfigFile } from '../../console/logging.js';
|
|
3
|
-
import { logger } from '../../console/logger.js';
|
|
4
|
-
/**
|
|
5
|
-
* Update the config file version id, locales, and projectId (if necessary)
|
|
6
|
-
* @param {string} configFilepath - The path to the config file.
|
|
7
|
-
* @param {UpdateConfigOptions} options - The options to update the config file with.
|
|
8
|
-
* @returns {Promise<void>} - A promise that resolves when the config file is updated.
|
|
9
|
-
*
|
|
10
|
-
* Hint: Mark a field as null to remove it from the config file.
|
|
11
|
-
*/
|
|
12
|
-
export default async function updateConfig(configFilepath, options) {
|
|
13
|
-
// Filter out empty string values from the config object
|
|
14
|
-
const { projectId, _versionId, _branchId, stageTranslations } = options;
|
|
15
|
-
const newContent = {
|
|
16
|
-
...(projectId && { projectId }),
|
|
17
|
-
...(_versionId && { _versionId }),
|
|
18
|
-
...(_branchId && { _branchId }),
|
|
19
|
-
// Omit when false
|
|
20
|
-
...(stageTranslations && { stageTranslations }),
|
|
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
|
-
...oldContent,
|
|
31
|
-
...newContent,
|
|
32
|
-
};
|
|
33
|
-
// Apply null filter to remove values that were marked for removal
|
|
34
|
-
const filteredContent = applyNullFilter(mergedContent, options);
|
|
35
|
-
// write to file
|
|
36
|
-
const jsonContent = JSON.stringify(filteredContent, null, 2);
|
|
37
|
-
await fs.promises.writeFile(configFilepath, jsonContent, 'utf-8');
|
|
38
|
-
// show update in console
|
|
39
|
-
displayUpdatedConfigFile(configFilepath);
|
|
40
|
-
}
|
|
41
|
-
catch (error) {
|
|
42
|
-
logger.error(`An error occurred while updating ${configFilepath}: ${error}`);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
// --- Helper functions --- //
|
|
46
|
-
/**
|
|
47
|
-
* Remove values from object if they were marked for removal
|
|
48
|
-
*/
|
|
49
|
-
function applyNullFilter(obj, filter) {
|
|
50
|
-
const result = { ...obj };
|
|
51
|
-
for (const key of Object.keys(filter)) {
|
|
52
|
-
if (filter[key] === null) {
|
|
53
|
-
delete result[key];
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return result;
|
|
57
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
type StagedVersionData = Record<string, // fileId
|
|
2
|
-
{
|
|
3
|
-
fileName: string;
|
|
4
|
-
versionId: string;
|
|
5
|
-
}>;
|
|
6
|
-
export declare function updateVersions({ configDirectory, versionData, }: {
|
|
7
|
-
configDirectory: string;
|
|
8
|
-
versionData: StagedVersionData;
|
|
9
|
-
}): Promise<void>;
|
|
10
|
-
export declare function getStagedVersions(configDirectory: string): Promise<StagedVersionData>;
|
|
11
|
-
export {};
|