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,651 +1,542 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
1
|
+
import { logger } from "../console/logger.js";
|
|
2
|
+
import { createFileMapping } from "../formats/files/fileMapping.js";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
import YAML, { isMap, isScalar } from "yaml";
|
|
6
|
+
import { unified } from "unified";
|
|
7
|
+
import remarkParse from "remark-parse";
|
|
8
|
+
import remarkFrontmatter from "remark-frontmatter";
|
|
9
|
+
//#region src/utils/processOpenApi.ts
|
|
9
10
|
const HTTP_METHODS = new Set([
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
"GET",
|
|
12
|
+
"POST",
|
|
13
|
+
"PUT",
|
|
14
|
+
"PATCH",
|
|
15
|
+
"DELETE",
|
|
16
|
+
"OPTIONS",
|
|
17
|
+
"HEAD",
|
|
18
|
+
"TRACE"
|
|
19
|
+
]);
|
|
20
|
+
const OPENAPI_SPEC_EXTENSIONS = new Set([
|
|
21
|
+
".json",
|
|
22
|
+
".yaml",
|
|
23
|
+
".yml"
|
|
18
24
|
]);
|
|
19
|
-
const OPENAPI_SPEC_EXTENSIONS = new Set(['.json', '.yaml', '.yml']);
|
|
20
25
|
/**
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
if (!fs.existsSync(filePath))
|
|
67
|
-
continue;
|
|
68
|
-
const content = fs.readFileSync(filePath, 'utf8');
|
|
69
|
-
const updated = rewriteFrontmatter(content, filePath, locale, specAnalyses, fileMappingAbs, warnings, configDir);
|
|
70
|
-
if (updated?.changed) {
|
|
71
|
-
await fs.promises.writeFile(filePath, updated.content, 'utf8');
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
const docsJsonTargets = collectDocsJsonTargets(settings, fileMapping, includeFiles);
|
|
76
|
-
for (const target of docsJsonTargets) {
|
|
77
|
-
if (!fs.existsSync(target.path))
|
|
78
|
-
continue;
|
|
79
|
-
const content = fs.readFileSync(target.path, 'utf8');
|
|
80
|
-
const updated = rewriteDocsJsonOpenApi(content, target.path, target.localeHint, specAnalyses, fileMappingAbs, fileMapping, warnings, configDir, settings.defaultLocale);
|
|
81
|
-
if (updated?.changed) {
|
|
82
|
-
await fs.promises.writeFile(target.path, updated.content, 'utf8');
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
for (const message of warnings) {
|
|
86
|
-
logger.warn(message);
|
|
87
|
-
}
|
|
26
|
+
* Postprocess Mintlify OpenAPI references to point to locale-specific spec files.
|
|
27
|
+
* - Uses openapi.files (ordered) to resolve ambiguities (first match wins).
|
|
28
|
+
* - Relies on the user's json transform rules for locale paths.
|
|
29
|
+
* - Warns on missing/ambiguous references but keeps behavior deterministic.
|
|
30
|
+
*/
|
|
31
|
+
async function processOpenApi(settings, includeFiles) {
|
|
32
|
+
const openapiConfig = settings.options?.mintlify?.openapi;
|
|
33
|
+
if (!openapiConfig || !openapiConfig.files?.length) return;
|
|
34
|
+
if (!settings.files) return;
|
|
35
|
+
const configDir = path.dirname(settings.config);
|
|
36
|
+
const specAnalyses = buildSpecAnalyses(openapiConfig.files, configDir);
|
|
37
|
+
if (!specAnalyses.length) return;
|
|
38
|
+
const warnings = /* @__PURE__ */ new Set();
|
|
39
|
+
const { resolvedPaths, placeholderPaths, transformPaths, transformFormats } = settings.files;
|
|
40
|
+
const fileMapping = createFileMapping(resolvedPaths, placeholderPaths, transformPaths, transformFormats, settings.locales, settings.defaultLocale);
|
|
41
|
+
const fileMappingAbs = {};
|
|
42
|
+
for (const [locale, mapping] of Object.entries(fileMapping)) {
|
|
43
|
+
fileMappingAbs[locale] = {};
|
|
44
|
+
for (const [src, dest] of Object.entries(mapping)) {
|
|
45
|
+
const absSrc = path.resolve(configDir, src);
|
|
46
|
+
const absDest = path.resolve(configDir, dest);
|
|
47
|
+
fileMappingAbs[locale][absSrc] = absDest;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const defaultFiles = [...resolvedPaths.mdx || [], ...resolvedPaths.md || []];
|
|
51
|
+
for (const filePath of defaultFiles) {
|
|
52
|
+
if (!fs.existsSync(filePath)) continue;
|
|
53
|
+
const updated = rewriteFrontmatter(fs.readFileSync(filePath, "utf8"), filePath, settings.defaultLocale, specAnalyses, fileMappingAbs, warnings, configDir);
|
|
54
|
+
if (updated?.changed) await fs.promises.writeFile(filePath, updated.content, "utf8");
|
|
55
|
+
}
|
|
56
|
+
for (const [locale, filesMap] of Object.entries(fileMapping)) {
|
|
57
|
+
const targetFiles = Object.values(filesMap).filter((p) => (p.endsWith(".md") || p.endsWith(".mdx")) && (!includeFiles || includeFiles.has(p)));
|
|
58
|
+
for (const filePath of targetFiles) {
|
|
59
|
+
if (!fs.existsSync(filePath)) continue;
|
|
60
|
+
const updated = rewriteFrontmatter(fs.readFileSync(filePath, "utf8"), filePath, locale, specAnalyses, fileMappingAbs, warnings, configDir);
|
|
61
|
+
if (updated?.changed) await fs.promises.writeFile(filePath, updated.content, "utf8");
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
const docsJsonTargets = collectDocsJsonTargets(settings, fileMapping, includeFiles);
|
|
65
|
+
for (const target of docsJsonTargets) {
|
|
66
|
+
if (!fs.existsSync(target.path)) continue;
|
|
67
|
+
const updated = rewriteDocsJsonOpenApi(fs.readFileSync(target.path, "utf8"), target.path, target.localeHint, specAnalyses, fileMappingAbs, fileMapping, warnings, configDir, settings.defaultLocale);
|
|
68
|
+
if (updated?.changed) await fs.promises.writeFile(target.path, updated.content, "utf8");
|
|
69
|
+
}
|
|
70
|
+
for (const message of warnings) logger.warn(message);
|
|
88
71
|
}
|
|
89
72
|
function collectDocsJsonTargets(settings, fileMapping, includeFiles) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
continue;
|
|
113
|
-
addTarget(filePath, locale);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
for (const [filePath, locales] of seen.entries()) {
|
|
117
|
-
const localeHint = locales.size === 1 ? Array.from(locales)[0] : undefined;
|
|
118
|
-
targets.push({ path: filePath, localeHint });
|
|
119
|
-
}
|
|
120
|
-
return targets;
|
|
73
|
+
const targets = [];
|
|
74
|
+
const seen = /* @__PURE__ */ new Map();
|
|
75
|
+
const addTarget = (filePath, locale) => {
|
|
76
|
+
const canonicalPath = path.resolve(filePath);
|
|
77
|
+
if (includeFiles && !includeFiles.has(filePath) && !includeFiles.has(canonicalPath)) return;
|
|
78
|
+
const locales = seen.get(canonicalPath) ?? /* @__PURE__ */ new Set();
|
|
79
|
+
if (locale) locales.add(locale);
|
|
80
|
+
seen.set(canonicalPath, locales);
|
|
81
|
+
};
|
|
82
|
+
if (!includeFiles && settings.files?.resolvedPaths.json) for (const filePath of settings.files.resolvedPaths.json) addTarget(filePath, settings.defaultLocale);
|
|
83
|
+
for (const [locale, filesMap] of Object.entries(fileMapping)) for (const filePath of Object.values(filesMap)) {
|
|
84
|
+
if (!filePath.endsWith(".json")) continue;
|
|
85
|
+
addTarget(filePath, locale);
|
|
86
|
+
}
|
|
87
|
+
for (const [filePath, locales] of seen.entries()) {
|
|
88
|
+
const localeHint = locales.size === 1 ? Array.from(locales)[0] : void 0;
|
|
89
|
+
targets.push({
|
|
90
|
+
path: filePath,
|
|
91
|
+
localeHint
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
return targets;
|
|
121
95
|
}
|
|
122
96
|
function isMintlifyDocsJson(filePath, json) {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
schema.includes('mintlify.com/mint.json'));
|
|
129
|
-
}
|
|
130
|
-
const base = path.basename(filePath);
|
|
131
|
-
return base === 'docs.json' || base === 'mint.json';
|
|
97
|
+
if (!isRecord(json)) return false;
|
|
98
|
+
const schema = json.$schema;
|
|
99
|
+
if (typeof schema === "string") return schema.includes("mintlify.com/docs.json") || schema.includes("mintlify.com/mint.json");
|
|
100
|
+
const base = path.basename(filePath);
|
|
101
|
+
return base === "docs.json" || base === "mint.json";
|
|
132
102
|
}
|
|
133
103
|
function rewriteDocsJsonOpenApi(content, filePath, localeHint, specs, fileMappingAbs, fileMappingRel, warnings, configDir, defaultLocale) {
|
|
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
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
visitNode(value, nextLocale);
|
|
190
|
-
}
|
|
191
|
-
};
|
|
192
|
-
visitNode(json, undefined);
|
|
193
|
-
if (!changed)
|
|
194
|
-
return null;
|
|
195
|
-
return { changed, content: JSON.stringify(json, null, 2) };
|
|
104
|
+
let json;
|
|
105
|
+
try {
|
|
106
|
+
json = JSON.parse(content);
|
|
107
|
+
} catch {
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
if (!isMintlifyDocsJson(filePath, json)) return null;
|
|
111
|
+
let changed = false;
|
|
112
|
+
const visitNode = (node, activeLocale) => {
|
|
113
|
+
if (Array.isArray(node)) {
|
|
114
|
+
node.forEach((item) => visitNode(item, activeLocale));
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
if (!isRecord(node)) return;
|
|
118
|
+
let nextLocale = activeLocale;
|
|
119
|
+
if (typeof node.language === "string") nextLocale = node.language;
|
|
120
|
+
const locale = nextLocale || localeHint || defaultLocale;
|
|
121
|
+
if (typeof node.openapi === "string") {
|
|
122
|
+
const sourceValue = node.openapi;
|
|
123
|
+
const localizedSource = localizeDocsJsonSpecPath(sourceValue, locale, filePath, specs, fileMappingAbs, fileMappingRel, warnings, configDir);
|
|
124
|
+
if (localizedSource && localizedSource !== sourceValue) {
|
|
125
|
+
node.openapi = localizedSource;
|
|
126
|
+
changed = true;
|
|
127
|
+
}
|
|
128
|
+
} else if (isRecord(node.openapi)) {
|
|
129
|
+
const openapiConfig = node.openapi;
|
|
130
|
+
const sourceValue = openapiConfig.source;
|
|
131
|
+
if (typeof sourceValue === "string") {
|
|
132
|
+
const localizedSource = localizeDocsJsonSpecPath(sourceValue, locale, filePath, specs, fileMappingAbs, fileMappingRel, warnings, configDir);
|
|
133
|
+
if (localizedSource && localizedSource !== sourceValue) {
|
|
134
|
+
openapiConfig.source = localizedSource;
|
|
135
|
+
changed = true;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (Array.isArray(node.pages)) {
|
|
140
|
+
const pages = node.pages;
|
|
141
|
+
for (let i = 0; i < pages.length; i += 1) {
|
|
142
|
+
const page = pages[i];
|
|
143
|
+
if (typeof page !== "string") continue;
|
|
144
|
+
const updated = stripLocaleFromOpenApiPage(page, locale);
|
|
145
|
+
if (updated !== page) {
|
|
146
|
+
pages[i] = updated;
|
|
147
|
+
changed = true;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
for (const value of Object.values(node)) visitNode(value, nextLocale);
|
|
152
|
+
};
|
|
153
|
+
visitNode(json, void 0);
|
|
154
|
+
if (!changed) return null;
|
|
155
|
+
return {
|
|
156
|
+
changed,
|
|
157
|
+
content: JSON.stringify(json, null, 2)
|
|
158
|
+
};
|
|
196
159
|
}
|
|
197
160
|
function stripLocaleFromOpenApiPage(value, locale) {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
if (!parsed)
|
|
205
|
-
return value;
|
|
206
|
-
return candidate;
|
|
161
|
+
const trimmed = value.trim();
|
|
162
|
+
const prefix = `${locale}/`;
|
|
163
|
+
if (!trimmed.startsWith(prefix)) return value;
|
|
164
|
+
const candidate = trimmed.slice(prefix.length);
|
|
165
|
+
if (!parseOpenApiValue(candidate)) return value;
|
|
166
|
+
return candidate;
|
|
207
167
|
}
|
|
208
168
|
function localizeDocsJsonSpecPath(source, locale, filePath, specs, fileMappingAbs, _fileMappingRel, warnings, configDir) {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
return source;
|
|
218
|
-
}
|
|
219
|
-
const rel = normalizeSlashes(path.relative(configDir, localizedAbs));
|
|
220
|
-
return formatSpecPathForDocsJson(rel, source);
|
|
169
|
+
const matched = matchSpecBySource(source, resolveDocsJsonSpecPath(source, filePath, configDir), specs, warnings);
|
|
170
|
+
if (!matched) return source;
|
|
171
|
+
const localizedAbs = resolveDocsJsonSpecPath(resolveLocalizedSpecPath(matched, locale, fileMappingAbs, configDir, source), filePath, configDir);
|
|
172
|
+
if (!fs.existsSync(localizedAbs)) {
|
|
173
|
+
warnings.add(`OpenAPI source "${source}" localized for locale "${locale}" points to a missing file (${localizedAbs}). Keeping original source.`);
|
|
174
|
+
return source;
|
|
175
|
+
}
|
|
176
|
+
return formatSpecPathForDocsJson(normalizeSlashes(path.relative(configDir, localizedAbs)), source);
|
|
221
177
|
}
|
|
222
178
|
function resolveDocsJsonSpecPath(source, filePath, configDir) {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
if (source.startsWith('./') || source.startsWith('../')) {
|
|
227
|
-
return path.resolve(path.dirname(filePath), source);
|
|
228
|
-
}
|
|
229
|
-
return path.resolve(configDir, source);
|
|
179
|
+
if (source.startsWith("/")) return path.resolve(configDir, source.replace(/^\/+/, ""));
|
|
180
|
+
if (source.startsWith("./") || source.startsWith("../")) return path.resolve(path.dirname(filePath), source);
|
|
181
|
+
return path.resolve(configDir, source);
|
|
230
182
|
}
|
|
231
183
|
function matchSpecBySource(source, resolvedAbs, specs, warnings) {
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
if (matches.length > 1) {
|
|
252
|
-
warnings.add(`OpenAPI source "${source}" matches multiple specs (${matches
|
|
253
|
-
.map((m) => m.configPath)
|
|
254
|
-
.join(', ')}). Using the first configured match (${matches[0].configPath}).`);
|
|
255
|
-
return matches[0];
|
|
256
|
-
}
|
|
257
|
-
return null;
|
|
184
|
+
const exact = specs.find((spec) => samePath(resolvedAbs, spec.absPath));
|
|
185
|
+
if (exact) return exact;
|
|
186
|
+
const normalizedExplicit = normalizeSlashes(source).replace(/^\.?\/+/, "");
|
|
187
|
+
const explicitWithoutExt = stripExtension(normalizedExplicit);
|
|
188
|
+
const explicitBase = path.basename(normalizedExplicit);
|
|
189
|
+
const explicitBaseWithoutExt = stripExtension(explicitBase);
|
|
190
|
+
const matches = specs.filter((spec) => {
|
|
191
|
+
const configPath = normalizeSlashes(spec.configPath).replace(/^\.?\/+/, "");
|
|
192
|
+
const configBase = path.basename(configPath);
|
|
193
|
+
const configPathNoExt = stripExtension(configPath);
|
|
194
|
+
const configBaseNoExt = stripExtension(configBase);
|
|
195
|
+
return configPath === normalizedExplicit || configPathNoExt === explicitWithoutExt || configBase === explicitBase || configBaseNoExt === explicitBaseWithoutExt;
|
|
196
|
+
});
|
|
197
|
+
if (matches.length === 1) return matches[0];
|
|
198
|
+
if (matches.length > 1) {
|
|
199
|
+
warnings.add(`OpenAPI source "${source}" matches multiple specs (${matches.map((m) => m.configPath).join(", ")}). Using the first configured match (${matches[0].configPath}).`);
|
|
200
|
+
return matches[0];
|
|
201
|
+
}
|
|
202
|
+
return null;
|
|
258
203
|
}
|
|
259
204
|
function formatSpecPathForDocsJson(relativePath, originalPathText) {
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
return normalized;
|
|
267
|
-
}
|
|
268
|
-
if (originalPathText.startsWith('./')) {
|
|
269
|
-
return `./${base.replace(/^\/+/, '')}`;
|
|
270
|
-
}
|
|
271
|
-
return base.replace(/^\/+/, '');
|
|
205
|
+
const normalized = normalizeSlashes(relativePath);
|
|
206
|
+
const base = normalized.replace(/^\.\//, "").replace(/\/+/g, "/");
|
|
207
|
+
if (originalPathText.startsWith("/")) return `/${base.replace(/^\/+/, "")}`;
|
|
208
|
+
if (originalPathText.startsWith("../")) return normalized;
|
|
209
|
+
if (originalPathText.startsWith("./")) return `./${base.replace(/^\/+/, "")}`;
|
|
210
|
+
return base.replace(/^\/+/, "");
|
|
272
211
|
}
|
|
273
212
|
/**
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
213
|
+
* Resolve configured OpenAPI files to absolute paths and collect the operations,
|
|
214
|
+
* schemas, and webhooks they expose. Warns and skips when files are missing,
|
|
215
|
+
* unsupported (non-JSON/YAML), or fail to parse so later steps can continue gracefully.
|
|
216
|
+
*/
|
|
278
217
|
function buildSpecAnalyses(openapiFiles, configDir) {
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
return analyses;
|
|
218
|
+
const analyses = [];
|
|
219
|
+
for (const configEntry of openapiFiles) {
|
|
220
|
+
const absPath = path.resolve(configDir, configEntry);
|
|
221
|
+
if (!fs.existsSync(absPath)) {
|
|
222
|
+
logger.warn(`OpenAPI file not found: ${configEntry}`);
|
|
223
|
+
continue;
|
|
224
|
+
}
|
|
225
|
+
const ext = path.extname(absPath).toLowerCase();
|
|
226
|
+
if (!OPENAPI_SPEC_EXTENSIONS.has(ext)) {
|
|
227
|
+
logger.warn(`Skipping OpenAPI file (only .json/.yml/.yaml supported): ${configEntry}`);
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
230
|
+
let spec;
|
|
231
|
+
try {
|
|
232
|
+
const raw = fs.readFileSync(absPath, "utf8");
|
|
233
|
+
spec = ext === ".json" ? JSON.parse(raw) : YAML.parse(raw);
|
|
234
|
+
} catch {
|
|
235
|
+
const format = ext === ".json" ? "JSON" : "YAML";
|
|
236
|
+
logger.warn(`Failed to parse OpenAPI ${format}: ${configEntry}`);
|
|
237
|
+
continue;
|
|
238
|
+
}
|
|
239
|
+
analyses.push({
|
|
240
|
+
absPath,
|
|
241
|
+
configPath: configEntry,
|
|
242
|
+
operations: extractOperations(spec),
|
|
243
|
+
schemas: extractSchemas(spec),
|
|
244
|
+
webhooks: extractWebhooks(spec)
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
return analyses;
|
|
310
248
|
}
|
|
311
249
|
function isRecord(val) {
|
|
312
|
-
|
|
250
|
+
return typeof val === "object" && val !== null;
|
|
313
251
|
}
|
|
314
252
|
/**
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
253
|
+
* Collect path+method identifiers (e.g., "POST /foo") from an OpenAPI spec.
|
|
254
|
+
* Safely no-ops when paths is missing or malformed.
|
|
255
|
+
*/
|
|
318
256
|
function extractOperations(spec) {
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
ops.add(`${upper} ${route}`);
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
return ops;
|
|
257
|
+
const ops = /* @__PURE__ */ new Set();
|
|
258
|
+
if (!isRecord(spec) || !isRecord(spec.paths)) return ops;
|
|
259
|
+
const paths = spec.paths;
|
|
260
|
+
for (const [route, methods] of Object.entries(paths)) {
|
|
261
|
+
if (!isRecord(methods)) continue;
|
|
262
|
+
for (const [method, operation] of Object.entries(methods)) {
|
|
263
|
+
if (!isRecord(operation)) continue;
|
|
264
|
+
const upper = method.toUpperCase();
|
|
265
|
+
if (!HTTP_METHODS.has(upper)) continue;
|
|
266
|
+
ops.add(`${upper} ${route}`);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
return ops;
|
|
336
270
|
}
|
|
337
271
|
/**
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
272
|
+
* Collect schema names from components.schemas.
|
|
273
|
+
* Returns empty set if components/schemas are missing or malformed.
|
|
274
|
+
*/
|
|
341
275
|
function extractSchemas(spec) {
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
return new Set();
|
|
347
|
-
return new Set(Object.keys(components.schemas));
|
|
276
|
+
if (!isRecord(spec) || !isRecord(spec.components)) return /* @__PURE__ */ new Set();
|
|
277
|
+
const components = spec.components;
|
|
278
|
+
if (!isRecord(components.schemas)) return /* @__PURE__ */ new Set();
|
|
279
|
+
return new Set(Object.keys(components.schemas));
|
|
348
280
|
}
|
|
349
281
|
/**
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
282
|
+
* Collect webhook names from webhooks (OpenAPI 3.1+).
|
|
283
|
+
* Returns empty set if webhooks is missing or malformed.
|
|
284
|
+
*/
|
|
353
285
|
function extractWebhooks(spec) {
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
return new Set(Object.keys(spec.webhooks));
|
|
286
|
+
if (!isRecord(spec) || !isRecord(spec.webhooks)) return /* @__PURE__ */ new Set();
|
|
287
|
+
return new Set(Object.keys(spec.webhooks));
|
|
357
288
|
}
|
|
358
289
|
/**
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
290
|
+
* Parse MDX/MD frontmatter, rewrite openapi/openapi-schema entries to the
|
|
291
|
+
* resolved (possibly localized) spec path, and return updated content.
|
|
292
|
+
* Uses remark to find the YAML node so the rest of the document remains
|
|
293
|
+
* untouched. When parsing fails or no relevant keys exist, it returns null.
|
|
294
|
+
*/
|
|
364
295
|
function rewriteFrontmatter(content, filePath, locale, specs, fileMapping, warnings, configDir) {
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
}
|
|
430
|
-
if (!changed)
|
|
431
|
-
return null;
|
|
432
|
-
const fmString = doc.toString().trimEnd();
|
|
433
|
-
const rebuilt = `${content.slice(0, start)}---\n${fmString}\n---${content.slice(end)}`;
|
|
434
|
-
return { changed, content: rebuilt };
|
|
296
|
+
let tree;
|
|
297
|
+
try {
|
|
298
|
+
tree = unified().use(remarkParse).use(remarkFrontmatter, ["yaml", "toml"]).parse(content);
|
|
299
|
+
} catch {
|
|
300
|
+
return null;
|
|
301
|
+
}
|
|
302
|
+
const yamlNode = tree.children.find((node) => node.type === "yaml");
|
|
303
|
+
if (!yamlNode || !yamlNode.position || yamlNode.position.start?.offset === void 0) return null;
|
|
304
|
+
const start = yamlNode.position.start.offset;
|
|
305
|
+
const end = yamlNode.position.end.offset;
|
|
306
|
+
const frontmatterRaw = yamlNode.value || "";
|
|
307
|
+
const doc = YAML.parseDocument(frontmatterRaw, {
|
|
308
|
+
prettyErrors: false,
|
|
309
|
+
keepSourceTokens: true
|
|
310
|
+
});
|
|
311
|
+
if (doc.errors?.length) return null;
|
|
312
|
+
if (!isMap(doc.contents)) return null;
|
|
313
|
+
let changed = false;
|
|
314
|
+
const openapiNode = doc.get("openapi", true);
|
|
315
|
+
if (isScalar(openapiNode) && typeof openapiNode.value === "string") {
|
|
316
|
+
const parsedValue = parseOpenApiValue(openapiNode.value);
|
|
317
|
+
if (parsedValue) {
|
|
318
|
+
const matchKey = parsedValue.kind === "operation" ? {
|
|
319
|
+
type: "operation",
|
|
320
|
+
key: `${parsedValue.method.toUpperCase()} ${parsedValue.operationPath}`
|
|
321
|
+
} : {
|
|
322
|
+
type: "webhook",
|
|
323
|
+
key: parsedValue.name
|
|
324
|
+
};
|
|
325
|
+
const spec = resolveSpec(parsedValue.specPath, specs, filePath, configDir, warnings, describeOpenApiRef(parsedValue), matchKey);
|
|
326
|
+
if (spec) {
|
|
327
|
+
const descriptor = formatOpenApiDescriptor(parsedValue);
|
|
328
|
+
const newValue = `${resolveLocalizedSpecPath(spec, locale, fileMapping, configDir, parsedValue.specPath || spec.configPath)} ${descriptor}`.trim();
|
|
329
|
+
if (newValue !== openapiNode.value) {
|
|
330
|
+
doc.set("openapi", newValue);
|
|
331
|
+
changed = true;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
const schemaNode = doc.get("openapi-schema", true);
|
|
337
|
+
if (isScalar(schemaNode) && typeof schemaNode.value === "string") {
|
|
338
|
+
const parsedValue = parseSchemaValue(schemaNode.value);
|
|
339
|
+
if (parsedValue) {
|
|
340
|
+
const spec = resolveSpec(parsedValue.specPath, specs, filePath, configDir, warnings, `schema "${parsedValue.schemaName}"`, {
|
|
341
|
+
type: "schema",
|
|
342
|
+
key: parsedValue.schemaName
|
|
343
|
+
});
|
|
344
|
+
if (spec) {
|
|
345
|
+
const newValue = `${resolveLocalizedSpecPath(spec, locale, fileMapping, configDir, parsedValue.specPath || spec.configPath)} ${parsedValue.schemaName}`.trim();
|
|
346
|
+
if (newValue !== schemaNode.value) {
|
|
347
|
+
doc.set("openapi-schema", newValue);
|
|
348
|
+
changed = true;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
if (!changed) return null;
|
|
354
|
+
const fmString = doc.toString().trimEnd();
|
|
355
|
+
const rebuilt = `${content.slice(0, start)}---\n${fmString}\n---${content.slice(end)}`;
|
|
356
|
+
return {
|
|
357
|
+
changed,
|
|
358
|
+
content: rebuilt
|
|
359
|
+
};
|
|
435
360
|
}
|
|
436
361
|
function stripWrappingQuotes(value) {
|
|
437
|
-
|
|
362
|
+
return value.trim().replace(/^['"]|['"]$/g, "");
|
|
438
363
|
}
|
|
439
364
|
/**
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
365
|
+
* Parse frontmatter openapi string into spec/method/path or webhook.
|
|
366
|
+
* Supports optional leading spec file, the webhook keyword, quoted values,
|
|
367
|
+
* and forgiving whitespace. Returns null when the structure is unrecognized.
|
|
368
|
+
*/
|
|
444
369
|
function parseOpenApiValue(value) {
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
return { kind: 'operation', specPath, method, operationPath };
|
|
370
|
+
const tokens = stripWrappingQuotes(value).split(/\s+/).filter(Boolean);
|
|
371
|
+
if (!tokens.length) return null;
|
|
372
|
+
let cursor = 0;
|
|
373
|
+
let specPath;
|
|
374
|
+
const first = tokens[0];
|
|
375
|
+
const second = tokens[1];
|
|
376
|
+
const methodCandidate = second?.toUpperCase();
|
|
377
|
+
if (hasOpenApiSpecExtension(first) || second && (second.toLowerCase() === "webhook" || methodCandidate && HTTP_METHODS.has(methodCandidate))) {
|
|
378
|
+
specPath = tokens[0];
|
|
379
|
+
cursor = 1;
|
|
380
|
+
}
|
|
381
|
+
if (cursor >= tokens.length) return null;
|
|
382
|
+
const keyword = tokens[cursor];
|
|
383
|
+
if (keyword.toLowerCase() === "webhook") {
|
|
384
|
+
const name = tokens.slice(cursor + 1).join(" ");
|
|
385
|
+
if (!name) return null;
|
|
386
|
+
return {
|
|
387
|
+
kind: "webhook",
|
|
388
|
+
specPath,
|
|
389
|
+
name
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
const method = keyword.toUpperCase();
|
|
393
|
+
if (!HTTP_METHODS.has(method)) return null;
|
|
394
|
+
const operationPath = tokens.slice(cursor + 1).join(" ");
|
|
395
|
+
if (!operationPath) return null;
|
|
396
|
+
return {
|
|
397
|
+
kind: "operation",
|
|
398
|
+
specPath,
|
|
399
|
+
method,
|
|
400
|
+
operationPath
|
|
401
|
+
};
|
|
478
402
|
}
|
|
479
403
|
/**
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
404
|
+
* Parse frontmatter openapi-schema string into spec/schemaName.
|
|
405
|
+
* Accepts optional leading spec file and quoted values; returns null on invalid
|
|
406
|
+
* shapes so callers can skip rewrites gracefully.
|
|
407
|
+
*/
|
|
484
408
|
function parseSchemaValue(value) {
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
409
|
+
const tokens = stripWrappingQuotes(value).split(/\s+/).filter(Boolean);
|
|
410
|
+
if (!tokens.length) return null;
|
|
411
|
+
let cursor = 0;
|
|
412
|
+
let specPath;
|
|
413
|
+
if (hasOpenApiSpecExtension(tokens[0])) {
|
|
414
|
+
specPath = tokens[0];
|
|
415
|
+
cursor = 1;
|
|
416
|
+
}
|
|
417
|
+
const schemaName = tokens.slice(cursor).join(" ");
|
|
418
|
+
if (!schemaName) return null;
|
|
419
|
+
return {
|
|
420
|
+
specPath,
|
|
421
|
+
schemaName
|
|
422
|
+
};
|
|
499
423
|
}
|
|
500
424
|
/**
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
425
|
+
* Choose which configured spec a reference should use.
|
|
426
|
+
* - If an explicit spec path is provided, resolve it relative to the config
|
|
427
|
+
* and the referencing file, warn when unknown, and bail.
|
|
428
|
+
* - Otherwise, try to match by operation/webhook/schema name; resolve
|
|
429
|
+
* ambiguity using config order and warn when ambiguous or missing.
|
|
430
|
+
*/
|
|
507
431
|
function resolveSpec(explicitPath, specs, filePath, configDir, warnings, refDescription, match) {
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
return null;
|
|
561
|
-
}
|
|
562
|
-
// No explicit spec: try to find by contents
|
|
563
|
-
const matches = specs.filter((spec) => {
|
|
564
|
-
if (match.type === 'schema') {
|
|
565
|
-
return spec.schemas.has(match.key);
|
|
566
|
-
}
|
|
567
|
-
if (match.type === 'webhook') {
|
|
568
|
-
return spec.webhooks.has(match.key);
|
|
569
|
-
}
|
|
570
|
-
// operation
|
|
571
|
-
return spec.operations.has(match.key);
|
|
572
|
-
});
|
|
573
|
-
if (matches.length === 1)
|
|
574
|
-
return matches[0];
|
|
575
|
-
if (matches.length > 1) {
|
|
576
|
-
warnings.add(`OpenAPI reference ${refDescription} in ${filePath} is available in multiple specs. Skipping localization for this reference.`);
|
|
577
|
-
return null;
|
|
578
|
-
}
|
|
579
|
-
warnings.add(`OpenAPI reference ${refDescription} in ${filePath} was not found in any configured spec. Skipping localization for this reference.`);
|
|
580
|
-
return null;
|
|
432
|
+
if (!specs.length) return null;
|
|
433
|
+
if (explicitPath) {
|
|
434
|
+
const normalizedExplicit = normalizeSlashes(explicitPath.replace(/^\.?\/+/, ""));
|
|
435
|
+
const candidates = [path.resolve(configDir, normalizedExplicit), path.resolve(path.dirname(filePath), normalizedExplicit)];
|
|
436
|
+
const foundSpec = specs.find((spec) => {
|
|
437
|
+
const normalizedSpecPath = normalizeSlashes(spec.absPath);
|
|
438
|
+
return candidates.some((candidate) => samePath(candidate, normalizedSpecPath));
|
|
439
|
+
});
|
|
440
|
+
if (foundSpec) {
|
|
441
|
+
if (specHasMatch(foundSpec, match)) return foundSpec;
|
|
442
|
+
const alternatives = specs.filter((spec) => spec !== foundSpec && specHasMatch(spec, match));
|
|
443
|
+
if (alternatives.length === 1) {
|
|
444
|
+
warnings.add(`OpenAPI reference ${refDescription} in ${filePath} points to ${foundSpec.configPath}, but the entry was not found there. Using ${alternatives[0].configPath} instead.`);
|
|
445
|
+
return alternatives[0];
|
|
446
|
+
}
|
|
447
|
+
if (alternatives.length > 1) {
|
|
448
|
+
warnings.add(`OpenAPI reference ${refDescription} in ${filePath} points to ${foundSpec.configPath}, but the entry was not found there and matches multiple specs (${alternatives.map((spec) => spec.configPath).join(", ")}). Skipping localization for this reference.`);
|
|
449
|
+
return null;
|
|
450
|
+
}
|
|
451
|
+
warnings.add(`OpenAPI reference ${refDescription} in ${filePath} points to ${foundSpec.configPath}, but the entry was not found in any configured spec. Skipping localization for this reference.`);
|
|
452
|
+
return null;
|
|
453
|
+
}
|
|
454
|
+
const explicitWithoutExt = stripExtension(normalizedExplicit);
|
|
455
|
+
const explicitBase = path.basename(normalizedExplicit);
|
|
456
|
+
const explicitBaseWithoutExt = stripExtension(explicitBase);
|
|
457
|
+
const matches = specs.filter((spec) => {
|
|
458
|
+
const configPath = normalizeSlashes(spec.configPath).replace(/^\.?\/+/, "");
|
|
459
|
+
const configBase = path.basename(configPath);
|
|
460
|
+
const configPathNoExt = stripExtension(configPath);
|
|
461
|
+
const configBaseNoExt = stripExtension(configBase);
|
|
462
|
+
return configPath === normalizedExplicit || configPathNoExt === explicitWithoutExt || configBase === explicitBase || configBaseNoExt === explicitBaseWithoutExt;
|
|
463
|
+
});
|
|
464
|
+
if (matches.length === 1) return matches[0];
|
|
465
|
+
if (matches.length > 1) {
|
|
466
|
+
warnings.add(`OpenAPI reference ${refDescription} in ${filePath} matches multiple specs (${matches.map((m) => m.configPath).join(", ")}). Using the first configured match (${matches[0].configPath}).`);
|
|
467
|
+
return matches[0];
|
|
468
|
+
}
|
|
469
|
+
warnings.add(`OpenAPI reference ${refDescription} in ${filePath} points to an unconfigured spec (${explicitPath}). Skipping localization for this reference.`);
|
|
470
|
+
return null;
|
|
471
|
+
}
|
|
472
|
+
const matches = specs.filter((spec) => {
|
|
473
|
+
if (match.type === "schema") return spec.schemas.has(match.key);
|
|
474
|
+
if (match.type === "webhook") return spec.webhooks.has(match.key);
|
|
475
|
+
return spec.operations.has(match.key);
|
|
476
|
+
});
|
|
477
|
+
if (matches.length === 1) return matches[0];
|
|
478
|
+
if (matches.length > 1) {
|
|
479
|
+
warnings.add(`OpenAPI reference ${refDescription} in ${filePath} is available in multiple specs. Skipping localization for this reference.`);
|
|
480
|
+
return null;
|
|
481
|
+
}
|
|
482
|
+
warnings.add(`OpenAPI reference ${refDescription} in ${filePath} was not found in any configured spec. Skipping localization for this reference.`);
|
|
483
|
+
return null;
|
|
581
484
|
}
|
|
582
485
|
function specHasMatch(spec, match) {
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
if (match.type === 'webhook') {
|
|
587
|
-
return spec.webhooks.has(match.key);
|
|
588
|
-
}
|
|
589
|
-
return spec.operations.has(match.key);
|
|
486
|
+
if (match.type === "schema") return spec.schemas.has(match.key);
|
|
487
|
+
if (match.type === "webhook") return spec.webhooks.has(match.key);
|
|
488
|
+
return spec.operations.has(match.key);
|
|
590
489
|
}
|
|
591
490
|
/**
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
491
|
+
* Map a spec to the locale-specific file path when available and normalize it
|
|
492
|
+
* for frontmatter. Falls back to the source spec when the locale copy does
|
|
493
|
+
* not exist to preserve deterministic behavior.
|
|
494
|
+
*/
|
|
596
495
|
function resolveLocalizedSpecPath(spec, locale, fileMapping, configDir, originalPathText) {
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
const rel = normalizeSlashes(path.relative(configDir, chosenAbs));
|
|
600
|
-
const rooted = `/${rel.replace(/^\/+/, '')}`;
|
|
601
|
-
return formatSpecPathForFrontmatter(rooted, originalPathText || spec.configPath);
|
|
496
|
+
const chosenAbs = fileMapping[locale]?.[spec.absPath] || spec.absPath;
|
|
497
|
+
return formatSpecPathForFrontmatter(`/${normalizeSlashes(path.relative(configDir, chosenAbs)).replace(/^\/+/, "")}`, originalPathText || spec.configPath);
|
|
602
498
|
}
|
|
603
499
|
/**
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
500
|
+
* Format the path that will be written back to frontmatter:
|
|
501
|
+
* - Preserve the user's absolute style when they used a leading slash.
|
|
502
|
+
* - Preserve upward relative references (../) exactly.
|
|
503
|
+
* - Otherwise return a repo-root-relative path with a leading slash so Mintlify
|
|
504
|
+
* resolves consistently regardless of the MDX file location.
|
|
505
|
+
*/
|
|
610
506
|
function formatSpecPathForFrontmatter(relativePath, originalPathText) {
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
}
|
|
617
|
-
if (originalPathText.startsWith('../')) {
|
|
618
|
-
// Preserve explicit relative upward references
|
|
619
|
-
return normalized;
|
|
620
|
-
}
|
|
621
|
-
// Default to repo-root relative with leading slash to avoid resolving relative to the MDX directory
|
|
622
|
-
return `/${base.replace(/^\/+/, '')}`;
|
|
507
|
+
const normalized = normalizeSlashes(relativePath);
|
|
508
|
+
const base = normalized.replace(/^\.\//, "").replace(/\/+/g, "/");
|
|
509
|
+
if (originalPathText.startsWith("/")) return `/${base.replace(/^\/+/, "")}`;
|
|
510
|
+
if (originalPathText.startsWith("../")) return normalized;
|
|
511
|
+
return `/${base.replace(/^\/+/, "")}`;
|
|
623
512
|
}
|
|
624
513
|
/** Normalize the descriptive portion after the spec path for frontmatter. */
|
|
625
514
|
function formatOpenApiDescriptor(value) {
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
return `${value.method.toUpperCase()} ${value.operationPath}`;
|
|
515
|
+
if (value.kind === "webhook") return `webhook ${value.name}`;
|
|
516
|
+
return `${value.method.toUpperCase()} ${value.operationPath}`;
|
|
629
517
|
}
|
|
630
518
|
/** Human-readable description a specific OpenAPI reference. */
|
|
631
519
|
function describeOpenApiRef(value) {
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
return `${value.method.toUpperCase()} ${value.operationPath}`;
|
|
520
|
+
if (value.kind === "webhook") return `webhook ${value.name}`;
|
|
521
|
+
return `${value.method.toUpperCase()} ${value.operationPath}`;
|
|
635
522
|
}
|
|
636
523
|
/** Remove a single trailing file extension while preserving directory segments. */
|
|
637
524
|
function stripExtension(p) {
|
|
638
|
-
|
|
639
|
-
|
|
525
|
+
const parsed = path.parse(p);
|
|
526
|
+
return normalizeSlashes(path.join(parsed.dir, parsed.name));
|
|
640
527
|
}
|
|
641
528
|
function hasOpenApiSpecExtension(value) {
|
|
642
|
-
|
|
529
|
+
return OPENAPI_SPEC_EXTENSIONS.has(path.extname(value).toLowerCase());
|
|
643
530
|
}
|
|
644
531
|
/** Normalize separators for stable comparisons and output. */
|
|
645
532
|
function normalizeSlashes(p) {
|
|
646
|
-
|
|
533
|
+
return p.replace(/\\/g, "/");
|
|
647
534
|
}
|
|
648
535
|
/** Compare paths after resolution to avoid casing/separator mismatches. */
|
|
649
536
|
function samePath(a, b) {
|
|
650
|
-
|
|
537
|
+
return path.resolve(a) === path.resolve(b);
|
|
651
538
|
}
|
|
539
|
+
//#endregion
|
|
540
|
+
export { processOpenApi as default };
|
|
541
|
+
|
|
542
|
+
//# sourceMappingURL=processOpenApi.js.map
|