gt 2.14.35 → 2.14.37
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 +22 -1
- package/dist/api/collectUserEditDiffs.js +112 -155
- package/dist/api/collectUserEditDiffs.js.map +1 -0
- package/dist/api/downloadFileBatch.js +164 -241
- package/dist/api/downloadFileBatch.js.map +1 -0
- package/dist/api/saveLocalEdits.js +37 -41
- package/dist/api/saveLocalEdits.js.map +1 -0
- package/dist/bin/bin-entry.js +17 -7
- package/dist/bin/bin-entry.js.map +1 -0
- package/dist/bin/bin-main.js +43 -61
- package/dist/bin/bin-main.js.map +1 -0
- package/dist/cli/base.js +382 -497
- package/dist/cli/base.js.map +1 -0
- package/dist/cli/commands/download.js +41 -49
- package/dist/cli/commands/download.js.map +1 -0
- package/dist/cli/commands/enqueue.js +26 -25
- package/dist/cli/commands/enqueue.js.map +1 -0
- package/dist/cli/commands/setupProject.js +33 -36
- package/dist/cli/commands/setupProject.js.map +1 -0
- package/dist/cli/commands/stage.js +53 -61
- package/dist/cli/commands/stage.js.map +1 -0
- package/dist/cli/commands/translate.js +75 -112
- package/dist/cli/commands/translate.js.map +1 -0
- package/dist/cli/commands/upload.js +185 -213
- package/dist/cli/commands/upload.js.map +1 -0
- package/dist/cli/commands/utils/validation.js +39 -34
- package/dist/cli/commands/utils/validation.js.map +1 -0
- package/dist/cli/flags.js +35 -62
- package/dist/cli/flags.js.map +1 -0
- package/dist/cli/inline.js +112 -137
- package/dist/cli/inline.js.map +1 -0
- package/dist/cli/next.js +17 -12
- package/dist/cli/next.js.map +1 -0
- package/dist/cli/node.js +19 -15
- package/dist/cli/node.js.map +1 -0
- package/dist/cli/python.js +13 -8
- package/dist/cli/python.js.map +1 -0
- package/dist/cli/react.js +61 -78
- package/dist/cli/react.js.map +1 -0
- package/dist/config/defaults.js +16 -11
- package/dist/config/defaults.js.map +1 -0
- package/dist/config/generateSettings.js +167 -269
- package/dist/config/generateSettings.js.map +1 -0
- package/dist/config/optionPresets.js +78 -96
- package/dist/config/optionPresets.js.map +1 -0
- package/dist/config/resolveConfig.js +27 -32
- package/dist/config/resolveConfig.js.map +1 -0
- package/dist/config/utils.js +7 -3
- package/dist/config/utils.js.map +1 -0
- package/dist/config/validateSettings.js +19 -30
- package/dist/config/validateSettings.js.map +1 -0
- package/dist/console/colors.js +18 -13
- package/dist/console/colors.js.map +1 -0
- package/dist/console/displayTranslateSummary.js +40 -37
- package/dist/console/displayTranslateSummary.js.map +1 -0
- package/dist/console/formatting.js +8 -5
- package/dist/console/formatting.js.map +1 -0
- package/dist/console/index.d.ts +11 -9
- package/dist/console/index.js +53 -50
- package/dist/console/index.js.map +1 -0
- package/dist/console/inkFields.d.ts +23 -0
- package/dist/console/inkFields.js +87 -0
- package/dist/console/inkFields.js.map +1 -0
- package/dist/console/inkLayout.d.ts +7 -0
- package/dist/console/inkLayout.js +139 -0
- package/dist/console/inkLayout.js.map +1 -0
- package/dist/console/inkLocaleData.d.ts +4 -0
- package/dist/console/inkLocaleData.js +32 -0
- package/dist/console/inkLocaleData.js.map +1 -0
- package/dist/console/inkPrompts.d.ts +8 -0
- package/dist/console/inkPrompts.js +496 -0
- package/dist/console/inkPrompts.js.map +1 -0
- package/dist/console/inkSession.d.ts +3 -0
- package/dist/console/inkSession.js +42 -0
- package/dist/console/inkSession.js.map +1 -0
- package/dist/console/inkTerminal.d.ts +4 -0
- package/dist/console/inkTerminal.js +15 -0
- package/dist/console/inkTerminal.js.map +1 -0
- package/dist/console/inkTypes.d.ts +66 -0
- package/dist/console/inkTypes.js +1 -0
- package/dist/console/inkUtils.d.ts +24 -0
- package/dist/console/inkUtils.js +87 -0
- package/dist/console/inkUtils.js.map +1 -0
- package/dist/console/logger.js +209 -249
- package/dist/console/logger.js.map +1 -0
- package/dist/console/logging.d.ts +14 -0
- package/dist/console/logging.js +203 -162
- package/dist/console/logging.js.map +1 -0
- package/dist/console/promptParsing.d.ts +5 -0
- package/dist/console/promptParsing.js +28 -0
- package/dist/console/promptParsing.js.map +1 -0
- package/dist/console/terminalSession.d.ts +5 -0
- package/dist/console/terminalSession.js +38 -0
- package/dist/console/terminalSession.js.map +1 -0
- package/dist/extraction/index.js +3 -2
- package/dist/extraction/mapToUpdates.js +19 -18
- package/dist/extraction/mapToUpdates.js.map +1 -0
- package/dist/extraction/postProcess.js +68 -86
- package/dist/extraction/postProcess.js.map +1 -0
- package/dist/formats/files/aggregateFiles.js +223 -304
- package/dist/formats/files/aggregateFiles.js.map +1 -0
- package/dist/formats/files/collectFiles.js +53 -54
- package/dist/formats/files/collectFiles.js.map +1 -0
- package/dist/formats/files/convertToFileTranslationData.js +21 -19
- package/dist/formats/files/convertToFileTranslationData.js.map +1 -0
- package/dist/formats/files/fileMapping.js +82 -119
- package/dist/formats/files/fileMapping.js.map +1 -0
- package/dist/formats/files/preprocess/mdx.js +15 -12
- package/dist/formats/files/preprocess/mdx.js.map +1 -0
- package/dist/formats/files/preprocess/mintlify.js +15 -13
- package/dist/formats/files/preprocess/mintlify.js.map +1 -0
- package/dist/formats/files/preprocessContent.js +20 -21
- package/dist/formats/files/preprocessContent.js.map +1 -0
- package/dist/formats/files/save.js +18 -15
- package/dist/formats/files/save.js.map +1 -0
- package/dist/formats/files/supportedFiles.js +27 -22
- package/dist/formats/files/supportedFiles.js.map +1 -0
- package/dist/formats/files/transformFormat.js +93 -100
- package/dist/formats/files/transformFormat.js.map +1 -0
- package/dist/formats/json/extractJson.js +83 -110
- package/dist/formats/json/extractJson.js.map +1 -0
- package/dist/formats/json/flattenJson.js +41 -48
- package/dist/formats/json/flattenJson.js.map +1 -0
- package/dist/formats/json/jsonPath.js +20 -15
- package/dist/formats/json/jsonPath.js.map +1 -0
- package/dist/formats/json/jsonPointer.js +17 -17
- package/dist/formats/json/jsonPointer.js.map +1 -0
- package/dist/formats/json/mergeJson.js +230 -371
- package/dist/formats/json/mergeJson.js.map +1 -0
- package/dist/formats/json/parseJson.js +74 -111
- package/dist/formats/json/parseJson.js.map +1 -0
- package/dist/formats/json/transformJson.js +53 -61
- package/dist/formats/json/transformJson.js.map +1 -0
- package/dist/formats/json/utils.js +158 -187
- package/dist/formats/json/utils.js.map +1 -0
- package/dist/formats/parseKeyedMetadata.js +85 -106
- package/dist/formats/parseKeyedMetadata.js.map +1 -0
- package/dist/formats/utils.js +13 -23
- package/dist/formats/utils.js.map +1 -0
- package/dist/formats/yaml/extractYaml.js +32 -31
- package/dist/formats/yaml/extractYaml.js.map +1 -0
- package/dist/formats/yaml/mergeYaml.js +43 -60
- package/dist/formats/yaml/mergeYaml.js.map +1 -0
- package/dist/formats/yaml/parseYaml.js +34 -23
- package/dist/formats/yaml/parseYaml.js.map +1 -0
- package/dist/formats/yaml/utils.js +19 -21
- package/dist/formats/yaml/utils.js.map +1 -0
- package/dist/fs/clearLocaleDirs.js +82 -114
- package/dist/fs/clearLocaleDirs.js.map +1 -0
- package/dist/fs/config/downloadedVersions.js +174 -188
- package/dist/fs/config/downloadedVersions.js.map +1 -0
- package/dist/fs/config/loadConfig.js +12 -8
- package/dist/fs/config/loadConfig.js.map +1 -0
- package/dist/fs/config/parseFilesConfig.js +166 -227
- package/dist/fs/config/parseFilesConfig.js.map +1 -0
- package/dist/fs/config/setupConfig.js +43 -52
- package/dist/fs/config/setupConfig.js.map +1 -0
- package/dist/fs/config/updateConfig.js +44 -56
- package/dist/fs/config/updateConfig.js.map +1 -0
- package/dist/fs/config/updateVersions.js +27 -28
- package/dist/fs/config/updateVersions.js.map +1 -0
- package/dist/fs/copyFile.js +33 -37
- package/dist/fs/copyFile.js.map +1 -0
- package/dist/fs/createLoadTranslationsFile.js +32 -48
- package/dist/fs/createLoadTranslationsFile.js.map +1 -0
- package/dist/fs/determineFramework/detectPythonLibrary.js +30 -34
- package/dist/fs/determineFramework/detectPythonLibrary.js.map +1 -0
- package/dist/fs/determineFramework/index.js +46 -64
- package/dist/fs/determineFramework/index.js.map +1 -0
- package/dist/fs/determineFramework/matchPyprojectDependency.js +65 -78
- package/dist/fs/determineFramework/matchPyprojectDependency.js.map +1 -0
- package/dist/fs/determineFramework/matchRequirementsTxtDependency.js +21 -19
- package/dist/fs/determineFramework/matchRequirementsTxtDependency.js.map +1 -0
- package/dist/fs/determineFramework/matchSetupPyDependency.js +60 -81
- package/dist/fs/determineFramework/matchSetupPyDependency.js.map +1 -0
- package/dist/fs/determineFramework/resolveGtDependency.js +15 -15
- package/dist/fs/determineFramework/resolveGtDependency.js.map +1 -0
- package/dist/fs/findFilepath.js +63 -78
- package/dist/fs/findFilepath.js.map +1 -0
- package/dist/fs/loadJSON.js +18 -15
- package/dist/fs/loadJSON.js.map +1 -0
- package/dist/fs/matchFiles.js +12 -7
- package/dist/fs/matchFiles.js.map +1 -0
- package/dist/fs/saveJSON.js +10 -6
- package/dist/fs/saveJSON.js.map +1 -0
- package/dist/fs/utils.js +19 -15
- package/dist/fs/utils.js.map +1 -0
- package/dist/functions.d.ts +2 -1
- package/dist/functions.js +3 -6
- package/dist/generated/version.d.ts +1 -1
- package/dist/generated/version.js +6 -2
- package/dist/generated/version.js.map +1 -0
- package/dist/git/branches.js +77 -83
- package/dist/git/branches.js.map +1 -0
- package/dist/hooks/postProcess.js +97 -114
- package/dist/hooks/postProcess.js.map +1 -0
- package/dist/index.js +23 -31
- package/dist/index.js.map +1 -0
- package/dist/locadex/setupFlow.js +11 -8
- package/dist/locadex/setupFlow.js.map +1 -0
- package/dist/main.js +17 -7
- package/dist/main.js.map +1 -0
- package/dist/next/config/parseNextConfig.js +32 -51
- package/dist/next/config/parseNextConfig.js.map +1 -0
- package/dist/next/jsx/utils.js +25 -37
- package/dist/next/jsx/utils.js.map +1 -0
- package/dist/next/parse/handleInitGT.js +87 -154
- package/dist/next/parse/handleInitGT.js.map +1 -0
- package/dist/next/parse/wrapContent.js +136 -158
- package/dist/next/parse/wrapContent.js.map +1 -0
- package/dist/python/parse/createPythonInlineUpdates.js +36 -33
- package/dist/python/parse/createPythonInlineUpdates.js.map +1 -0
- package/dist/react/config/createESBuildConfig.js +115 -115
- package/dist/react/config/createESBuildConfig.js.map +1 -0
- package/dist/react/jsx/evaluateJsx.js +90 -124
- package/dist/react/jsx/evaluateJsx.js.map +1 -0
- package/dist/react/jsx/utils/buildImportMap.js +24 -28
- package/dist/react/jsx/utils/buildImportMap.js.map +1 -0
- package/dist/react/jsx/utils/constants.js +79 -87
- package/dist/react/jsx/utils/constants.js.map +1 -0
- package/dist/react/jsx/utils/extractSourceCode.js +36 -37
- package/dist/react/jsx/utils/extractSourceCode.js.map +1 -0
- package/dist/react/jsx/utils/getCalleeNameFromExpression.js +30 -30
- package/dist/react/jsx/utils/getCalleeNameFromExpression.js.map +1 -0
- package/dist/react/jsx/utils/getPathsAndAliases.js +70 -105
- package/dist/react/jsx/utils/getPathsAndAliases.js.map +1 -0
- package/dist/react/jsx/utils/isNumberLiteral.js +13 -11
- package/dist/react/jsx/utils/isNumberLiteral.js.map +1 -0
- package/dist/react/jsx/utils/jsxParsing/addGTIdentifierToSyntaxTree.js +103 -148
- package/dist/react/jsx/utils/jsxParsing/addGTIdentifierToSyntaxTree.js.map +1 -0
- package/dist/react/jsx/utils/jsxParsing/autoInsertion.js +305 -389
- package/dist/react/jsx/utils/jsxParsing/autoInsertion.js.map +1 -0
- package/dist/react/jsx/utils/jsxParsing/handleChildrenWhitespace.js +122 -193
- package/dist/react/jsx/utils/jsxParsing/handleChildrenWhitespace.js.map +1 -0
- package/dist/react/jsx/utils/jsxParsing/multiplication/findMultiplicationNode.js +50 -64
- package/dist/react/jsx/utils/jsxParsing/multiplication/findMultiplicationNode.js.map +1 -0
- package/dist/react/jsx/utils/jsxParsing/multiplication/multiplyJsxTree.js +41 -68
- package/dist/react/jsx/utils/jsxParsing/multiplication/multiplyJsxTree.js.map +1 -0
- package/dist/react/jsx/utils/jsxParsing/parseJsx.js +760 -1107
- package/dist/react/jsx/utils/jsxParsing/parseJsx.js.map +1 -0
- package/dist/react/jsx/utils/jsxParsing/parseTProps.js +35 -71
- package/dist/react/jsx/utils/jsxParsing/parseTProps.js.map +1 -0
- package/dist/react/jsx/utils/jsxParsing/removeNullChildrenFields.js +39 -58
- package/dist/react/jsx/utils/jsxParsing/removeNullChildrenFields.js.map +1 -0
- package/dist/react/jsx/utils/jsxParsing/types.js +10 -24
- package/dist/react/jsx/utils/jsxParsing/types.js.map +1 -0
- package/dist/react/jsx/utils/mapAttributeName.js +13 -13
- package/dist/react/jsx/utils/mapAttributeName.js.map +1 -0
- package/dist/react/jsx/utils/parseAst.js +142 -272
- package/dist/react/jsx/utils/parseAst.js.map +1 -0
- package/dist/react/jsx/utils/parseString.js +726 -1090
- package/dist/react/jsx/utils/parseString.js.map +1 -0
- package/dist/react/jsx/utils/parseStringFunction.js +274 -401
- package/dist/react/jsx/utils/parseStringFunction.js.map +1 -0
- package/dist/react/jsx/utils/resolveImportPath.d.ts +1 -1
- package/dist/react/jsx/utils/resolveImportPath.js +125 -108
- package/dist/react/jsx/utils/resolveImportPath.js.map +1 -0
- package/dist/react/jsx/utils/stringParsing/derivation/containsDeriveCall.js +18 -24
- package/dist/react/jsx/utils/stringParsing/derivation/containsDeriveCall.js.map +1 -0
- package/dist/react/jsx/utils/stringParsing/derivation/handleDerivation.js +412 -579
- package/dist/react/jsx/utils/stringParsing/derivation/handleDerivation.js.map +1 -0
- package/dist/react/jsx/utils/stringParsing/derivation/index.js +57 -67
- package/dist/react/jsx/utils/stringParsing/derivation/index.js.map +1 -0
- package/dist/react/jsx/utils/stringParsing/derivation/isDeriveCall.js +26 -36
- package/dist/react/jsx/utils/stringParsing/derivation/isDeriveCall.js.map +1 -0
- package/dist/react/jsx/utils/stringParsing/processTaggedTemplateCall/handleTaggedTemplateTranslationCall.js +29 -24
- package/dist/react/jsx/utils/stringParsing/processTaggedTemplateCall/handleTaggedTemplateTranslationCall.js.map +1 -0
- package/dist/react/jsx/utils/stringParsing/processTaggedTemplateCall/index.js +34 -32
- package/dist/react/jsx/utils/stringParsing/processTaggedTemplateCall/index.js.map +1 -0
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/extractStringEntryMetadata.js +80 -117
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/extractStringEntryMetadata.js.map +1 -0
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleDeriveTranslationCall.js +24 -19
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleDeriveTranslationCall.js.map +1 -0
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleInvalidTranslationCall.js +18 -21
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleInvalidTranslationCall.js.map +1 -0
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleLiteralTranslationCall.js +45 -50
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleLiteralTranslationCall.js.map +1 -0
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/index.js +54 -59
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/index.js.map +1 -0
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/routeTranslationCall.js +56 -69
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/routeTranslationCall.js.map +1 -0
- package/dist/react/jsx/utils/validateStringFunction.js +21 -29
- package/dist/react/jsx/utils/validateStringFunction.js.map +1 -0
- package/dist/react/jsx/wrapJsx.js +192 -375
- package/dist/react/jsx/wrapJsx.js.map +1 -0
- package/dist/react/parse/addVitePlugin/index.js +40 -34
- package/dist/react/parse/addVitePlugin/index.js.map +1 -0
- package/dist/react/parse/addVitePlugin/installCompiler.js +18 -20
- package/dist/react/parse/addVitePlugin/installCompiler.js.map +1 -0
- package/dist/react/parse/addVitePlugin/updateViteConfig.js +107 -111
- package/dist/react/parse/addVitePlugin/updateViteConfig.js.map +1 -0
- package/dist/react/parse/addVitePlugin/utils/addCompilerImport.js +23 -26
- package/dist/react/parse/addVitePlugin/utils/addCompilerImport.js.map +1 -0
- package/dist/react/parse/addVitePlugin/utils/addPluginInvocation.js +29 -43
- package/dist/react/parse/addVitePlugin/utils/addPluginInvocation.js.map +1 -0
- package/dist/react/parse/addVitePlugin/utils/checkCompilerImport.js +70 -104
- package/dist/react/parse/addVitePlugin/utils/checkCompilerImport.js.map +1 -0
- package/dist/react/parse/addVitePlugin/utils/checkPluginInvocation.js +23 -29
- package/dist/react/parse/addVitePlugin/utils/checkPluginInvocation.js.map +1 -0
- package/dist/react/parse/createDictionaryUpdates.js +121 -185
- package/dist/react/parse/createDictionaryUpdates.js.map +1 -0
- package/dist/react/parse/createInlineUpdates.js +123 -139
- package/dist/react/parse/createInlineUpdates.js.map +1 -0
- package/dist/react/parse/wrapContent.js +131 -156
- package/dist/react/parse/wrapContent.js.map +1 -0
- package/dist/react/utils/flattenDictionary.js +55 -70
- package/dist/react/utils/flattenDictionary.js.map +1 -0
- package/dist/react/utils/getEntryAndMetadata.js +14 -10
- package/dist/react/utils/getEntryAndMetadata.js.map +1 -0
- package/dist/react/utils/getVariableName.js +36 -33
- package/dist/react/utils/getVariableName.js.map +1 -0
- package/dist/setup/detectFramework.js +85 -102
- package/dist/setup/detectFramework.js.map +1 -0
- package/dist/setup/frameworkUtils.js +17 -28
- package/dist/setup/frameworkUtils.js.map +1 -0
- package/dist/setup/userInput.js +24 -31
- package/dist/setup/userInput.js.map +1 -0
- package/dist/setup/wizard.js +141 -143
- package/dist/setup/wizard.js.map +1 -0
- package/dist/state/mintlifyRefMap.js +12 -9
- package/dist/state/mintlifyRefMap.js.map +1 -0
- package/dist/state/recentDownloads.js +26 -23
- package/dist/state/recentDownloads.js.map +1 -0
- package/dist/state/translateWarnings.js +17 -8
- package/dist/state/translateWarnings.js.map +1 -0
- package/dist/translation/parse.js +77 -98
- package/dist/translation/parse.js.map +1 -0
- package/dist/translation/stage.js +28 -43
- package/dist/translation/stage.js.map +1 -0
- package/dist/translation/validate.js +68 -91
- package/dist/translation/validate.js.map +1 -0
- package/dist/types/libraries.js +93 -91
- package/dist/types/libraries.js.map +1 -0
- package/dist/types/parsing.js +19 -10
- package/dist/types/parsing.js.map +1 -0
- package/dist/utils/addExplicitAnchorIds.js +270 -389
- package/dist/utils/addExplicitAnchorIds.js.map +1 -0
- package/dist/utils/calculateTimeoutMs.js +11 -6
- package/dist/utils/calculateTimeoutMs.js.map +1 -0
- package/dist/utils/constants.js +15 -12
- package/dist/utils/constants.js.map +1 -0
- package/dist/utils/credentials.js +67 -114
- package/dist/utils/credentials.js.map +1 -0
- package/dist/utils/fetch.js +22 -20
- package/dist/utils/fetch.js.map +1 -0
- package/dist/utils/flattenJsonFiles.js +27 -34
- package/dist/utils/flattenJsonFiles.js.map +1 -0
- package/dist/utils/gitDiff.js +30 -32
- package/dist/utils/gitDiff.js.map +1 -0
- package/dist/utils/gt.js +7 -2
- package/dist/utils/gt.js.map +1 -0
- package/dist/utils/hash.js +14 -9
- package/dist/utils/hash.js.map +1 -0
- package/dist/utils/headers.js +10 -13
- package/dist/utils/headers.js.map +1 -0
- package/dist/utils/installPackage.js +70 -75
- package/dist/utils/installPackage.js.map +1 -0
- package/dist/utils/localizeRelativeAssets.js +114 -157
- package/dist/utils/localizeRelativeAssets.js.map +1 -0
- package/dist/utils/localizeStaticImports.js +229 -371
- package/dist/utils/localizeStaticImports.js.map +1 -0
- package/dist/utils/localizeStaticUrls.js +241 -424
- package/dist/utils/localizeStaticUrls.js.map +1 -0
- package/dist/utils/mintlifyTitleFallback.js +64 -72
- package/dist/utils/mintlifyTitleFallback.js.map +1 -0
- package/dist/utils/monorepoVersionCheck.js +177 -215
- package/dist/utils/monorepoVersionCheck.js.map +1 -0
- package/dist/utils/packageInfo.js +17 -16
- package/dist/utils/packageInfo.js.map +1 -0
- package/dist/utils/packageJson.js +51 -66
- package/dist/utils/packageJson.js.map +1 -0
- package/dist/utils/packageManager.js +237 -260
- package/dist/utils/packageManager.js.map +1 -0
- package/dist/utils/parse/needsCJS.js +36 -69
- package/dist/utils/parse/needsCJS.js.map +1 -0
- package/dist/utils/persistPostprocessHashes.js +30 -32
- package/dist/utils/persistPostprocessHashes.js.map +1 -0
- package/dist/utils/processAnchorIds.js +32 -54
- package/dist/utils/processAnchorIds.js.map +1 -0
- package/dist/utils/processOpenApi.js +469 -578
- package/dist/utils/processOpenApi.js.map +1 -0
- package/dist/utils/resolveMintlifyRefs.js +89 -105
- package/dist/utils/resolveMintlifyRefs.js.map +1 -0
- package/dist/utils/resolvePublish.js +46 -54
- package/dist/utils/resolvePublish.js.map +1 -0
- package/dist/utils/sanitizeFileContent.js +20 -27
- package/dist/utils/sanitizeFileContent.js.map +1 -0
- package/dist/utils/sharedStaticAssets.js +248 -366
- package/dist/utils/sharedStaticAssets.js.map +1 -0
- package/dist/utils/splitMintlifyLanguageRefs.js +208 -282
- package/dist/utils/splitMintlifyLanguageRefs.js.map +1 -0
- package/dist/utils/validateMdx.js +26 -23
- package/dist/utils/validateMdx.js.map +1 -0
- package/dist/utils/wrapPlainUrls.js +58 -70
- package/dist/utils/wrapPlainUrls.js.map +1 -0
- package/dist/workflows/download.js +92 -126
- package/dist/workflows/download.js.map +1 -0
- package/dist/workflows/enqueue.js +47 -54
- package/dist/workflows/enqueue.js.map +1 -0
- package/dist/workflows/publish.js +29 -29
- package/dist/workflows/publish.js.map +1 -0
- package/dist/workflows/setupProject.js +39 -40
- package/dist/workflows/setupProject.js.map +1 -0
- package/dist/workflows/stage.js +61 -65
- package/dist/workflows/stage.js.map +1 -0
- package/dist/workflows/steps/BranchStep.js +118 -163
- package/dist/workflows/steps/BranchStep.js.map +1 -0
- package/dist/workflows/steps/DownloadStep.js +107 -137
- package/dist/workflows/steps/DownloadStep.js.map +1 -0
- package/dist/workflows/steps/EnqueueStep.js +32 -32
- package/dist/workflows/steps/EnqueueStep.js.map +1 -0
- package/dist/workflows/steps/PollJobsStep.js +208 -292
- package/dist/workflows/steps/PollJobsStep.js.map +1 -0
- package/dist/workflows/steps/PublishStep.js +33 -38
- package/dist/workflows/steps/PublishStep.js.map +1 -0
- package/dist/workflows/steps/SetupStep.js +71 -72
- package/dist/workflows/steps/SetupStep.js.map +1 -0
- package/dist/workflows/steps/TagStep.js +39 -44
- package/dist/workflows/steps/TagStep.js.map +1 -0
- package/dist/workflows/steps/UploadSourcesStep.js +108 -140
- package/dist/workflows/steps/UploadSourcesStep.js.map +1 -0
- package/dist/workflows/steps/UploadTranslationsStep.js +61 -71
- package/dist/workflows/steps/UploadTranslationsStep.js.map +1 -0
- package/dist/workflows/steps/UserEditDiffsStep.js +32 -34
- package/dist/workflows/steps/UserEditDiffsStep.js.map +1 -0
- package/dist/workflows/steps/WorkflowStep.js +6 -2
- package/dist/workflows/steps/WorkflowStep.js.map +1 -0
- package/dist/workflows/upload.js +45 -46
- package/dist/workflows/upload.js.map +1 -0
- package/package.json +14 -7
|
@@ -1,241 +1,180 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import chalk from
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
1
|
+
import { logger } from "../../console/logger.js";
|
|
2
|
+
import { SUPPORTED_FILE_EXTENSIONS } from "../../formats/files/supportedFiles.js";
|
|
3
|
+
import { BASE_PARSING_FLAGS_DEFAULT, GT_PARSING_FLAGS_DEFAULT } from "../../config/defaults.js";
|
|
4
|
+
import { resolveTransformationFormat } from "../../formats/files/transformFormat.js";
|
|
5
|
+
import chalk from "chalk";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import fg from "fast-glob";
|
|
8
|
+
import micromatch from "micromatch";
|
|
9
|
+
//#region src/fs/config/parseFilesConfig.ts
|
|
9
10
|
/**
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
// Replace [locale] with locale in all paths
|
|
23
|
-
result.gt = files.gt?.replace(/\[locale\]/g, locale);
|
|
24
|
-
return result;
|
|
11
|
+
* Resolves the files from the files object
|
|
12
|
+
* Replaces [locale] with the actual locale in the files
|
|
13
|
+
*
|
|
14
|
+
* @param files - The files object
|
|
15
|
+
* @param locale - The locale to replace [locale] with
|
|
16
|
+
* @returns The resolved files
|
|
17
|
+
*/
|
|
18
|
+
function resolveLocaleFiles(files, locale) {
|
|
19
|
+
const result = {};
|
|
20
|
+
for (const fileType of SUPPORTED_FILE_EXTENSIONS) result[fileType] = files[fileType]?.map((filepath) => filepath.replace(/\[locale\]/g, locale));
|
|
21
|
+
result.gt = files.gt?.replace(/\[locale\]/g, locale);
|
|
22
|
+
return result;
|
|
25
23
|
}
|
|
26
24
|
/**
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return { paths, publishPatterns, unpublishPatterns };
|
|
25
|
+
* Normalizes include patterns into plain path strings and tracks which
|
|
26
|
+
* patterns have explicit publish flags.
|
|
27
|
+
*/
|
|
28
|
+
function normalizeIncludePatterns(patterns) {
|
|
29
|
+
const paths = [];
|
|
30
|
+
const publishPatterns = [];
|
|
31
|
+
const unpublishPatterns = [];
|
|
32
|
+
for (const pattern of patterns) if (typeof pattern === "string") paths.push(pattern);
|
|
33
|
+
else {
|
|
34
|
+
paths.push(pattern.pattern);
|
|
35
|
+
if (pattern.publish === true) publishPatterns.push(pattern.pattern);
|
|
36
|
+
else if (pattern.publish === false) unpublishPatterns.push(pattern.pattern);
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
paths,
|
|
40
|
+
publishPatterns,
|
|
41
|
+
unpublishPatterns
|
|
42
|
+
};
|
|
49
43
|
}
|
|
50
44
|
/**
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
transformFormats,
|
|
108
|
-
publishPaths,
|
|
109
|
-
unpublishPaths,
|
|
110
|
-
parsingFlags,
|
|
111
|
-
gtJson: (() => {
|
|
112
|
-
const rawGtFlags = (files.gt?.parsingFlags || {});
|
|
113
|
-
if ('autoDerive' in rawGtFlags && !('autoderive' in rawGtFlags)) {
|
|
114
|
-
rawGtFlags.autoderive = rawGtFlags.autoDerive;
|
|
115
|
-
delete rawGtFlags.autoDerive;
|
|
116
|
-
}
|
|
117
|
-
return {
|
|
118
|
-
publish: files.gt?.publish,
|
|
119
|
-
parsingFlags: {
|
|
120
|
-
...GT_PARSING_FLAGS_DEFAULT,
|
|
121
|
-
...rawGtFlags,
|
|
122
|
-
},
|
|
123
|
-
};
|
|
124
|
-
})(),
|
|
125
|
-
};
|
|
45
|
+
* Resolves the files from the files object.
|
|
46
|
+
* Performs glob pattern expansion on the files.
|
|
47
|
+
* Replaces [locale] with the actual locale in the files.
|
|
48
|
+
*
|
|
49
|
+
* @param files - The files object
|
|
50
|
+
* @returns The resolved files
|
|
51
|
+
*/
|
|
52
|
+
function resolveFiles(files, locale, locales, cwd, compositePatterns) {
|
|
53
|
+
const resolvedPaths = {};
|
|
54
|
+
const placeholderResult = {};
|
|
55
|
+
const transformPaths = {};
|
|
56
|
+
const transformFormats = {};
|
|
57
|
+
const publishPaths = /* @__PURE__ */ new Set();
|
|
58
|
+
const unpublishPaths = /* @__PURE__ */ new Set();
|
|
59
|
+
const parsingFlags = {};
|
|
60
|
+
if (files.gt?.output) placeholderResult.gt = path.resolve(cwd, files.gt.output);
|
|
61
|
+
for (const fileType of SUPPORTED_FILE_EXTENSIONS) {
|
|
62
|
+
const transform = files[fileType]?.transform;
|
|
63
|
+
if (transform && (typeof transform === "string" || typeof transform === "object" || Array.isArray(transform))) transformPaths[fileType] = transform;
|
|
64
|
+
const transformFormat = resolveTransformationFormat(fileType, files[fileType]?.transformationFormat);
|
|
65
|
+
if (transformFormat) transformFormats[fileType] = transformFormat;
|
|
66
|
+
if (files[fileType]?.include) {
|
|
67
|
+
const { paths, publishPatterns, unpublishPatterns } = normalizeIncludePatterns(files[fileType].include);
|
|
68
|
+
const filePaths = expandGlobPatterns(cwd, paths, files[fileType]?.exclude || [], locale, locales, transformPaths[fileType] || void 0, compositePatterns);
|
|
69
|
+
resolvedPaths[fileType] = filePaths.resolvedPaths;
|
|
70
|
+
placeholderResult[fileType] = filePaths.placeholderPaths;
|
|
71
|
+
classifyPublishPaths(filePaths.resolvedPaths, publishPatterns, unpublishPatterns, cwd, locale, publishPaths, unpublishPaths);
|
|
72
|
+
}
|
|
73
|
+
if (files[fileType]?.parsingFlags) parsingFlags[fileType] = {
|
|
74
|
+
...BASE_PARSING_FLAGS_DEFAULT,
|
|
75
|
+
...files[fileType].parsingFlags
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
resolvedPaths,
|
|
80
|
+
placeholderPaths: placeholderResult,
|
|
81
|
+
transformPaths,
|
|
82
|
+
transformFormats,
|
|
83
|
+
publishPaths,
|
|
84
|
+
unpublishPaths,
|
|
85
|
+
parsingFlags,
|
|
86
|
+
gtJson: (() => {
|
|
87
|
+
const rawGtFlags = files.gt?.parsingFlags || {};
|
|
88
|
+
if ("autoDerive" in rawGtFlags && !("autoderive" in rawGtFlags)) {
|
|
89
|
+
rawGtFlags.autoderive = rawGtFlags.autoDerive;
|
|
90
|
+
delete rawGtFlags.autoDerive;
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
publish: files.gt?.publish,
|
|
94
|
+
parsingFlags: {
|
|
95
|
+
...GT_PARSING_FLAGS_DEFAULT,
|
|
96
|
+
...rawGtFlags
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
})()
|
|
100
|
+
};
|
|
126
101
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
const matches = fg.sync(absolutePattern, {
|
|
162
|
-
absolute: true,
|
|
163
|
-
ignore: expandedExcludePatterns,
|
|
164
|
-
});
|
|
165
|
-
resolvedPaths.push(...matches);
|
|
166
|
-
// For each match, create a version with [locale] in the correct positions
|
|
167
|
-
matches.forEach((match) => {
|
|
168
|
-
const absolutePath = path.resolve(cwd, match);
|
|
169
|
-
const patternPath = path.resolve(cwd, pattern);
|
|
170
|
-
let originalAbsolutePath = absolutePath;
|
|
171
|
-
if (localePositions.length > 0) {
|
|
172
|
-
const placeholderPath = buildPlaceholderPathFromPattern(patternPath, absolutePath, localeTag);
|
|
173
|
-
originalAbsolutePath = placeholderPath;
|
|
174
|
-
}
|
|
175
|
-
placeholderPaths.push(originalAbsolutePath);
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
return { resolvedPaths, placeholderPaths };
|
|
102
|
+
function expandGlobPatterns(cwd, includePatterns, excludePatterns, locale, locales, transformPatterns, compositePatterns) {
|
|
103
|
+
const resolvedPaths = [];
|
|
104
|
+
const placeholderPaths = [];
|
|
105
|
+
for (const pattern of includePatterns) {
|
|
106
|
+
if (!pattern.includes("[locale]") && !transformPatterns && !compositePatterns?.includes(pattern)) logger.warn(chalk.yellow(`Pattern "${pattern}" does not include [locale], so the CLI tool may incorrectly save translated files.`));
|
|
107
|
+
const localePositions = [];
|
|
108
|
+
let searchIndex = 0;
|
|
109
|
+
const localeTag = "[locale]";
|
|
110
|
+
while (true) {
|
|
111
|
+
const foundIndex = pattern.indexOf(localeTag, searchIndex);
|
|
112
|
+
if (foundIndex === -1) break;
|
|
113
|
+
localePositions.push(foundIndex);
|
|
114
|
+
searchIndex = foundIndex + 8;
|
|
115
|
+
}
|
|
116
|
+
const expandedPattern = pattern.replace(/\[locale\]/g, locale);
|
|
117
|
+
const absolutePattern = path.resolve(cwd, expandedPattern);
|
|
118
|
+
const expandedExcludePatterns = Array.from(new Set(excludePatterns.flatMap((p) => locales.map((targetLocale) => path.resolve(cwd, p.replace(/\[locale\]/g, locale).replace(/\[locales\]/g, targetLocale))))));
|
|
119
|
+
const matches = fg.sync(absolutePattern, {
|
|
120
|
+
absolute: true,
|
|
121
|
+
ignore: expandedExcludePatterns
|
|
122
|
+
});
|
|
123
|
+
resolvedPaths.push(...matches);
|
|
124
|
+
matches.forEach((match) => {
|
|
125
|
+
const absolutePath = path.resolve(cwd, match);
|
|
126
|
+
const patternPath = path.resolve(cwd, pattern);
|
|
127
|
+
let originalAbsolutePath = absolutePath;
|
|
128
|
+
if (localePositions.length > 0) originalAbsolutePath = buildPlaceholderPathFromPattern(patternPath, absolutePath, localeTag);
|
|
129
|
+
placeholderPaths.push(originalAbsolutePath);
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
return {
|
|
133
|
+
resolvedPaths,
|
|
134
|
+
placeholderPaths
|
|
135
|
+
};
|
|
179
136
|
}
|
|
180
137
|
function buildPlaceholderPathFromPattern(patternPath, absolutePath, localeTag) {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
}
|
|
199
|
-
let placeholderPosixPath = posixPath;
|
|
200
|
-
const indices = matchWithIndices.indices;
|
|
201
|
-
for (let i = indices.length - 1; i >= 1; i--) {
|
|
202
|
-
const [start, end] = indices[i];
|
|
203
|
-
if (start === -1 || end === -1)
|
|
204
|
-
continue;
|
|
205
|
-
placeholderPosixPath =
|
|
206
|
-
placeholderPosixPath.slice(0, start) +
|
|
207
|
-
localeTag +
|
|
208
|
-
placeholderPosixPath.slice(end);
|
|
209
|
-
}
|
|
210
|
-
return path.normalize(placeholderPosixPath);
|
|
138
|
+
if (!patternPath.includes(localeTag)) return absolutePath;
|
|
139
|
+
const posixPattern = toPosixPath(patternPath);
|
|
140
|
+
const posixPath = toPosixPath(absolutePath);
|
|
141
|
+
const baseRegex = micromatch.makeRe(posixPattern, { literalBrackets: true });
|
|
142
|
+
const localeRegexSource = baseRegex.source.replace(/\\\[locale\\\]/g, "([^/]+)");
|
|
143
|
+
const flags = baseRegex.flags.includes("d") ? baseRegex.flags : `${baseRegex.flags}d`;
|
|
144
|
+
const match = new RegExp(localeRegexSource, flags).exec(posixPath);
|
|
145
|
+
const matchWithIndices = match;
|
|
146
|
+
if (!match || !matchWithIndices.indices) return absolutePath;
|
|
147
|
+
let placeholderPosixPath = posixPath;
|
|
148
|
+
const indices = matchWithIndices.indices;
|
|
149
|
+
for (let i = indices.length - 1; i >= 1; i--) {
|
|
150
|
+
const [start, end] = indices[i];
|
|
151
|
+
if (start === -1 || end === -1) continue;
|
|
152
|
+
placeholderPosixPath = placeholderPosixPath.slice(0, start) + localeTag + placeholderPosixPath.slice(end);
|
|
153
|
+
}
|
|
154
|
+
return path.normalize(placeholderPosixPath);
|
|
211
155
|
}
|
|
212
156
|
function toPosixPath(value) {
|
|
213
|
-
|
|
157
|
+
return value.split(path.sep).join(path.posix.sep);
|
|
214
158
|
}
|
|
215
159
|
/**
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
160
|
+
* Classifies resolved file paths into publish/unpublish sets by matching
|
|
161
|
+
* them against the given glob patterns. Uses POSIX paths for micromatch
|
|
162
|
+
* compatibility but stores platform-native paths in the output sets.
|
|
163
|
+
*/
|
|
220
164
|
function classifyPublishPaths(resolvedPaths, publishPatterns, unpublishPatterns, cwd, locale, publishPaths, unpublishPaths) {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
}
|
|
233
|
-
for (const pattern of unpublishPatterns) {
|
|
234
|
-
const matched = new Set(micromatch(posixPaths, toAbsoluteGlob(pattern)));
|
|
235
|
-
for (let i = 0; i < posixPaths.length; i++) {
|
|
236
|
-
if (matched.has(posixPaths[i])) {
|
|
237
|
-
unpublishPaths.add(resolvedPaths[i]);
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
}
|
|
165
|
+
if (publishPatterns.length === 0 && unpublishPatterns.length === 0) return;
|
|
166
|
+
const posixPaths = resolvedPaths.map(toPosixPath);
|
|
167
|
+
const toAbsoluteGlob = (p) => toPosixPath(path.resolve(cwd, p.replace(/\[locale\]/g, locale)));
|
|
168
|
+
for (const pattern of publishPatterns) {
|
|
169
|
+
const matched = new Set(micromatch(posixPaths, toAbsoluteGlob(pattern)));
|
|
170
|
+
for (let i = 0; i < posixPaths.length; i++) if (matched.has(posixPaths[i])) publishPaths.add(resolvedPaths[i]);
|
|
171
|
+
}
|
|
172
|
+
for (const pattern of unpublishPatterns) {
|
|
173
|
+
const matched = new Set(micromatch(posixPaths, toAbsoluteGlob(pattern)));
|
|
174
|
+
for (let i = 0; i < posixPaths.length; i++) if (matched.has(posixPaths[i])) unpublishPaths.add(resolvedPaths[i]);
|
|
175
|
+
}
|
|
241
176
|
}
|
|
177
|
+
//#endregion
|
|
178
|
+
export { expandGlobPatterns, normalizeIncludePatterns, resolveFiles, resolveLocaleFiles };
|
|
179
|
+
|
|
180
|
+
//# sourceMappingURL=parseFilesConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parseFilesConfig.js","names":[],"sources":["../../../src/fs/config/parseFilesConfig.ts"],"sourcesContent":["import path from 'node:path';\nimport {\n FilesOptions,\n IncludePattern,\n ResolvedFiles,\n Settings,\n TransformFormats,\n TransformFiles,\n TransformOption,\n} from '../../types/index.js';\nimport fg from 'fast-glob';\nimport { SUPPORTED_FILE_EXTENSIONS } from '../../formats/files/supportedFiles.js';\nimport { logger } from '../../console/logger.js';\nimport chalk from 'chalk';\nimport micromatch from 'micromatch';\nimport { ParseFlagsByFileType } from '../../types/parsing.js';\nimport {\n BASE_PARSING_FLAGS_DEFAULT,\n GT_PARSING_FLAGS_DEFAULT,\n} from '../../config/defaults.js';\nimport { resolveTransformationFormat } from '../../formats/files/transformFormat.js';\n\n/**\n * Resolves the files from the files object\n * Replaces [locale] with the actual locale in the files\n *\n * @param files - The files object\n * @param locale - The locale to replace [locale] with\n * @returns The resolved files\n */\nexport function resolveLocaleFiles(\n files: ResolvedFiles,\n locale: string\n): ResolvedFiles {\n const result: ResolvedFiles = {};\n\n for (const fileType of SUPPORTED_FILE_EXTENSIONS) {\n result[fileType] = files[fileType]?.map((filepath) =>\n filepath.replace(/\\[locale\\]/g, locale)\n );\n }\n\n // Replace [locale] with locale in all paths\n result.gt = files.gt?.replace(/\\[locale\\]/g, locale);\n\n return result;\n}\n/**\n * Normalizes include patterns into plain path strings and tracks which\n * patterns have explicit publish flags.\n */\nexport function normalizeIncludePatterns(patterns: IncludePattern[]): {\n paths: string[];\n publishPatterns: string[];\n unpublishPatterns: string[];\n} {\n const paths: string[] = [];\n const publishPatterns: string[] = [];\n const unpublishPatterns: string[] = [];\n\n for (const pattern of patterns) {\n if (typeof pattern === 'string') {\n paths.push(pattern);\n } else {\n paths.push(pattern.pattern);\n if (pattern.publish === true) {\n publishPatterns.push(pattern.pattern);\n } else if (pattern.publish === false) {\n unpublishPatterns.push(pattern.pattern);\n }\n }\n }\n\n return { paths, publishPatterns, unpublishPatterns };\n}\n\n/**\n * Resolves the files from the files object.\n * Performs glob pattern expansion on the files.\n * Replaces [locale] with the actual locale in the files.\n *\n * @param files - The files object\n * @returns The resolved files\n */\nexport function resolveFiles(\n files: FilesOptions,\n locale: string,\n locales: string[],\n cwd: string,\n compositePatterns?: string[]\n): Settings['files'] {\n // Initialize result object with empty arrays for each file type\n const resolvedPaths: ResolvedFiles = {};\n const placeholderResult: ResolvedFiles = {};\n const transformPaths: TransformFiles = {};\n // Output format transforms are tracked separately from path transforms.\n const transformFormats: TransformFormats = {};\n const publishPaths = new Set<string>();\n const unpublishPaths = new Set<string>();\n const parsingFlags: ParseFlagsByFileType = {};\n\n // Process GT files\n if (files.gt?.output) {\n placeholderResult.gt = path.resolve(cwd, files.gt.output);\n }\n\n for (const fileType of SUPPORTED_FILE_EXTENSIONS) {\n // ==== TRANSFORMS ==== //\n const transform = files[fileType]?.transform;\n if (\n transform &&\n (typeof transform === 'string' ||\n typeof transform === 'object' ||\n Array.isArray(transform))\n ) {\n transformPaths[fileType] = transform;\n }\n // Validate source -> output format transforms during settings generation.\n const transformFormat = resolveTransformationFormat(\n fileType,\n files[fileType]?.transformationFormat\n );\n if (transformFormat) {\n transformFormats[fileType] = transformFormat;\n }\n // ==== PLACEHOLDERS ==== //\n if (files[fileType]?.include) {\n const { paths, publishPatterns, unpublishPatterns } =\n normalizeIncludePatterns(files[fileType].include);\n\n const filePaths = expandGlobPatterns(\n cwd,\n paths,\n files[fileType]?.exclude || [],\n locale,\n locales,\n transformPaths[fileType] || undefined,\n compositePatterns\n );\n resolvedPaths[fileType] = filePaths.resolvedPaths;\n placeholderResult[fileType] = filePaths.placeholderPaths;\n\n // Classify resolved paths into publish/unpublish sets\n classifyPublishPaths(\n filePaths.resolvedPaths,\n publishPatterns,\n unpublishPatterns,\n cwd,\n locale,\n publishPaths,\n unpublishPaths\n );\n }\n // ==== OTHER ==== //\n if (files[fileType]?.parsingFlags) {\n parsingFlags[fileType] = {\n ...BASE_PARSING_FLAGS_DEFAULT,\n ...files[fileType].parsingFlags,\n };\n }\n }\n\n return {\n resolvedPaths,\n placeholderPaths: placeholderResult,\n transformPaths: transformPaths,\n transformFormats,\n publishPaths,\n unpublishPaths,\n parsingFlags,\n gtJson: (() => {\n const rawGtFlags = (files.gt?.parsingFlags || {}) as Record<\n string,\n unknown\n >;\n if ('autoDerive' in rawGtFlags && !('autoderive' in rawGtFlags)) {\n rawGtFlags.autoderive = rawGtFlags.autoDerive;\n delete rawGtFlags.autoDerive;\n }\n return {\n publish: files.gt?.publish,\n parsingFlags: {\n ...GT_PARSING_FLAGS_DEFAULT,\n ...rawGtFlags,\n },\n };\n })(),\n };\n}\n\n// Helper function to expand glob patterns\nexport function expandGlobPatterns(\n cwd: string,\n includePatterns: string[],\n excludePatterns: string[],\n locale: string,\n locales: string[],\n transformPatterns?: TransformOption | string | TransformOption[],\n compositePatterns?: string[]\n): {\n resolvedPaths: string[];\n placeholderPaths: string[];\n} {\n // Expand glob patterns to include all matching files\n const resolvedPaths: string[] = [];\n const placeholderPaths: string[] = [];\n\n // Process include patterns\n for (const pattern of includePatterns) {\n // Track positions where [locale] appears in the original pattern\n // It must be included in the pattern, otherwise the CLI tool will not be able to find the correct output path\n // Warn if it's not included\n // Ignore if is composite pattern\n if (\n !pattern.includes('[locale]') &&\n !transformPatterns &&\n !compositePatterns?.includes(pattern)\n ) {\n logger.warn(\n chalk.yellow(\n `Pattern \"${pattern}\" does not include [locale], so the CLI tool may incorrectly save translated files.`\n )\n );\n }\n const localePositions: number[] = [];\n let searchIndex = 0;\n const localeTag = '[locale]';\n\n while (true) {\n const foundIndex = pattern.indexOf(localeTag, searchIndex);\n if (foundIndex === -1) break;\n localePositions.push(foundIndex);\n searchIndex = foundIndex + localeTag.length;\n }\n\n const expandedPattern = pattern.replace(/\\[locale\\]/g, locale);\n\n // Resolve the absolute pattern path\n const absolutePattern = path.resolve(cwd, expandedPattern);\n\n // Prepare exclude patterns with locale replaced\n const expandedExcludePatterns = Array.from(\n new Set(\n excludePatterns.flatMap((p) =>\n locales.map((targetLocale) =>\n path.resolve(\n cwd,\n p\n .replace(/\\[locale\\]/g, locale)\n .replace(/\\[locales\\]/g, targetLocale)\n )\n )\n )\n )\n );\n\n // Use fast-glob to find all matching files, excluding the patterns\n const matches = fg.sync(absolutePattern, {\n absolute: true,\n ignore: expandedExcludePatterns,\n });\n\n resolvedPaths.push(...matches);\n\n // For each match, create a version with [locale] in the correct positions\n matches.forEach((match) => {\n const absolutePath = path.resolve(cwd, match);\n const patternPath = path.resolve(cwd, pattern);\n let originalAbsolutePath = absolutePath;\n\n if (localePositions.length > 0) {\n const placeholderPath = buildPlaceholderPathFromPattern(\n patternPath,\n absolutePath,\n localeTag\n );\n originalAbsolutePath = placeholderPath;\n }\n\n placeholderPaths.push(originalAbsolutePath);\n });\n }\n\n return { resolvedPaths, placeholderPaths };\n}\n\nfunction buildPlaceholderPathFromPattern(\n patternPath: string,\n absolutePath: string,\n localeTag: string\n): string {\n if (!patternPath.includes(localeTag)) {\n return absolutePath;\n }\n\n const posixPattern = toPosixPath(patternPath);\n const posixPath = toPosixPath(absolutePath);\n\n const baseRegex = micromatch.makeRe(posixPattern, {\n literalBrackets: true,\n });\n const localeRegexSource = baseRegex.source.replace(\n /\\\\\\[locale\\\\\\]/g,\n '([^/]+)'\n );\n const flags = baseRegex.flags.includes('d')\n ? baseRegex.flags\n : `${baseRegex.flags}d`;\n const matcher = new RegExp(localeRegexSource, flags);\n const match = matcher.exec(posixPath);\n\n const matchWithIndices = match as RegExpExecArray & {\n indices?: Array<[number, number]>;\n };\n\n if (!match || !matchWithIndices.indices) {\n return absolutePath;\n }\n\n let placeholderPosixPath = posixPath;\n const indices = matchWithIndices.indices;\n\n for (let i = indices.length - 1; i >= 1; i--) {\n const [start, end] = indices[i];\n if (start === -1 || end === -1) continue;\n placeholderPosixPath =\n placeholderPosixPath.slice(0, start) +\n localeTag +\n placeholderPosixPath.slice(end);\n }\n\n return path.normalize(placeholderPosixPath);\n}\n\nfunction toPosixPath(value: string): string {\n return value.split(path.sep).join(path.posix.sep);\n}\n\n/**\n * Classifies resolved file paths into publish/unpublish sets by matching\n * them against the given glob patterns. Uses POSIX paths for micromatch\n * compatibility but stores platform-native paths in the output sets.\n */\nfunction classifyPublishPaths(\n resolvedPaths: string[],\n publishPatterns: string[],\n unpublishPatterns: string[],\n cwd: string,\n locale: string,\n publishPaths: Set<string>,\n unpublishPaths: Set<string>\n): void {\n if (publishPatterns.length === 0 && unpublishPatterns.length === 0) return;\n\n const posixPaths = resolvedPaths.map(toPosixPath);\n const toAbsoluteGlob = (p: string) =>\n toPosixPath(path.resolve(cwd, p.replace(/\\[locale\\]/g, locale)));\n\n for (const pattern of publishPatterns) {\n const matched = new Set(micromatch(posixPaths, toAbsoluteGlob(pattern)));\n for (let i = 0; i < posixPaths.length; i++) {\n if (matched.has(posixPaths[i])) {\n publishPaths.add(resolvedPaths[i]);\n }\n }\n }\n\n for (const pattern of unpublishPatterns) {\n const matched = new Set(micromatch(posixPaths, toAbsoluteGlob(pattern)));\n for (let i = 0; i < posixPaths.length; i++) {\n if (matched.has(posixPaths[i])) {\n unpublishPaths.add(resolvedPaths[i]);\n }\n }\n }\n}\n"],"mappings":"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"}
|
|
@@ -1,54 +1,45 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
1
|
+
import { logger } from "../../console/logger.js";
|
|
2
|
+
import { GT_CONFIG_SCHEMA_URL } from "../../utils/constants.js";
|
|
3
|
+
import { displayCreatedConfigFile } from "../../console/logging.js";
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
//#region src/fs/config/setupConfig.ts
|
|
5
6
|
/**
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
mergedContent.locales = mergedContent.locales
|
|
41
|
-
? [...new Set([...mergedContent.locales, ...options.locales])]
|
|
42
|
-
: options.locales;
|
|
43
|
-
}
|
|
44
|
-
// write to file
|
|
45
|
-
const mergedJsonContent = JSON.stringify(mergedContent, null, 2);
|
|
46
|
-
await fs.promises.writeFile(configFilepath, mergedJsonContent, 'utf-8');
|
|
47
|
-
// show update in console
|
|
48
|
-
displayCreatedConfigFile(configFilepath);
|
|
49
|
-
}
|
|
50
|
-
catch (error) {
|
|
51
|
-
logger.error(`An error occurred while updating ${configFilepath}: ${error}`);
|
|
52
|
-
}
|
|
53
|
-
return configFilepath;
|
|
7
|
+
* Checks if the config file exists.
|
|
8
|
+
* If yes, make sure make sure projectId is correct
|
|
9
|
+
* If not, creates a new JSON file at the given filepath and writes the provided config object to it.
|
|
10
|
+
* @param {string} configFilepath - The path to the config file.
|
|
11
|
+
* @param {Record<string, any>} configObject - The config object to write if the file does not exist.
|
|
12
|
+
*/
|
|
13
|
+
async function createOrUpdateConfig(configFilepath, options) {
|
|
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
|
+
let oldContent = {};
|
|
24
|
+
if (fs.existsSync(configFilepath)) {
|
|
25
|
+
const parsed = JSON.parse(await fs.promises.readFile(configFilepath, "utf-8"));
|
|
26
|
+
oldContent = typeof parsed === "object" && parsed !== null ? parsed : {};
|
|
27
|
+
}
|
|
28
|
+
const mergedContent = {
|
|
29
|
+
$schema: GT_CONFIG_SCHEMA_URL,
|
|
30
|
+
...oldContent,
|
|
31
|
+
...newContent
|
|
32
|
+
};
|
|
33
|
+
if (options.locales) mergedContent.locales = mergedContent.locales ? [...new Set([...mergedContent.locales, ...options.locales])] : options.locales;
|
|
34
|
+
const mergedJsonContent = JSON.stringify(mergedContent, null, 2);
|
|
35
|
+
await fs.promises.writeFile(configFilepath, mergedJsonContent, "utf-8");
|
|
36
|
+
displayCreatedConfigFile(configFilepath);
|
|
37
|
+
} catch (error) {
|
|
38
|
+
logger.error(`An error occurred while updating ${configFilepath}: ${error}`);
|
|
39
|
+
}
|
|
40
|
+
return configFilepath;
|
|
54
41
|
}
|
|
42
|
+
//#endregion
|
|
43
|
+
export { createOrUpdateConfig };
|
|
44
|
+
|
|
45
|
+
//# sourceMappingURL=setupConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setupConfig.js","names":[],"sources":["../../../src/fs/config/setupConfig.ts"],"sourcesContent":["import fs from 'node:fs';\nimport { displayCreatedConfigFile } from '../../console/logging.js';\nimport { FilesOptions, SupportedFrameworks } from '../../types/index.js';\nimport { logger } from '../../console/logger.js';\nimport { GT_CONFIG_SCHEMA_URL } from '../../utils/constants.js';\n\n/**\n * Checks if the config file exists.\n * If yes, make sure make sure projectId is correct\n * If not, creates a new JSON file at the given filepath and writes the provided config object to it.\n * @param {string} configFilepath - The path to the config file.\n * @param {Record<string, any>} configObject - The config object to write if the file does not exist.\n */\nexport async function createOrUpdateConfig(\n configFilepath: string,\n options: {\n projectId?: string;\n defaultLocale?: string;\n locales?: string[];\n files?: FilesOptions;\n framework?: SupportedFrameworks;\n baseUrl?: string;\n publish?: boolean;\n }\n): Promise<string> {\n // Filter out empty string values from the config object\n const newContent = {\n ...(options.projectId && { projectId: options.projectId }),\n ...(options.defaultLocale && { defaultLocale: options.defaultLocale }),\n ...(options.files && { files: options.files }),\n ...(options.framework && { framework: options.framework }),\n ...(options.baseUrl && { baseUrl: options.baseUrl }),\n ...(options.publish && { publish: options.publish }),\n };\n try {\n // if file exists\n let oldContent: Record<string, unknown> = {};\n if (fs.existsSync(configFilepath)) {\n const parsed = JSON.parse(\n await fs.promises.readFile(configFilepath, 'utf-8')\n );\n oldContent =\n typeof parsed === 'object' && parsed !== null\n ? (parsed as Record<string, unknown>)\n : {};\n }\n\n // merge old and new content\n const mergedContent = {\n $schema: GT_CONFIG_SCHEMA_URL,\n ...oldContent,\n ...newContent,\n } as Record<string, unknown> & { locales?: string[] };\n\n // Add locales to mergedContent if they exist\n if (options.locales) {\n mergedContent.locales = mergedContent.locales\n ? [...new Set([...mergedContent.locales, ...options.locales])]\n : options.locales;\n }\n\n // write to file\n const mergedJsonContent = JSON.stringify(mergedContent, null, 2);\n await fs.promises.writeFile(configFilepath, mergedJsonContent, 'utf-8');\n\n // show update in console\n displayCreatedConfigFile(configFilepath);\n } catch (error) {\n logger.error(\n `An error occurred while updating ${configFilepath}: ${error}`\n );\n }\n return configFilepath;\n}\n"],"mappings":";;;;;;;;;;;;AAaA,eAAsB,qBACpB,gBACA,SASiB;CAEjB,MAAM,aAAa;EACjB,GAAI,QAAQ,aAAa,EAAE,WAAW,QAAQ,WAAW;EACzD,GAAI,QAAQ,iBAAiB,EAAE,eAAe,QAAQ,eAAe;EACrE,GAAI,QAAQ,SAAS,EAAE,OAAO,QAAQ,OAAO;EAC7C,GAAI,QAAQ,aAAa,EAAE,WAAW,QAAQ,WAAW;EACzD,GAAI,QAAQ,WAAW,EAAE,SAAS,QAAQ,SAAS;EACnD,GAAI,QAAQ,WAAW,EAAE,SAAS,QAAQ,SAAS;EACpD;AACD,KAAI;EAEF,IAAI,aAAsC,EAAE;AAC5C,MAAI,GAAG,WAAW,eAAe,EAAE;GACjC,MAAM,SAAS,KAAK,MAClB,MAAM,GAAG,SAAS,SAAS,gBAAgB,QAAQ,CACpD;AACD,gBACE,OAAO,WAAW,YAAY,WAAW,OACpC,SACD,EAAE;;EAIV,MAAM,gBAAgB;GACpB,SAAS;GACT,GAAG;GACH,GAAG;GACJ;AAGD,MAAI,QAAQ,QACV,eAAc,UAAU,cAAc,UAClC,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,cAAc,SAAS,GAAG,QAAQ,QAAQ,CAAC,CAAC,GAC5D,QAAQ;EAId,MAAM,oBAAoB,KAAK,UAAU,eAAe,MAAM,EAAE;AAChE,QAAM,GAAG,SAAS,UAAU,gBAAgB,mBAAmB,QAAQ;AAGvE,2BAAyB,eAAe;UACjC,OAAO;AACd,SAAO,MACL,oCAAoC,eAAe,IAAI,QACxD;;AAEH,QAAO"}
|