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SACF;QAED,kBAAkB;QAClB,IAAI,2CAAqB,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE;YAChD,KAAK,MAAM,MAAM,IAAI,OAAO,CAAC,OAAO,EAAE;gBACpC,IAAI,CAAC,gBAAgB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;aACzC;SACF;IACH,CAAC;IAED;;;OAGG;IACK,kBAAkB,CAAC,gBAAkC,EAAE,gBAAkC;QAC/F,gBAAgB,CAAC,cAAc,GAAG,gBAAgB,CAAC,cAAc,CAAC;QAClE,gBAAgB,CAAC,YAAY,GAAG,gBAAgB,CAAC,YAAY,CAAC;QAE9D,gBAAgB,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QAChC,KAAK,MAAM,KAAK,IAAI,gBAAgB,CAAC,MAAM,EAAE;YAC3C,gBAAgB,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;SACpC;QACD,KAAK,MAAM,SAAS,IAAI,gBAAgB,CAAC,UAAU,EAAE;YACnD,gBAAgB,CAAC,UAAU,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;SAC5C;QACD,gBAAgB,CAAC,YAAY,GAAG,gBAAgB,CAAC,YAAY,CAAC;QAE9D,gBAAgB,CAAC,aAAa,GAAG,SAAS,CAAC;IAC7C,CAAC;CACF;AA/GD,gCA+GC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport * as path from 'path';\nimport * as tsdoc from '@microsoft/tsdoc';\nimport colors from 'colors';\n\nimport { CommandLineAction, CommandLineStringParameter } from '@rushstack/ts-command-line';\nimport { FileSystem } from '@rushstack/node-core-library';\nimport {\n ApiModel,\n ApiItem,\n ApiItemContainerMixin,\n ApiDocumentedItem,\n IResolveDeclarationReferenceResult\n} from '@microsoft/api-extractor-model';\n\nexport interface IBuildApiModelResult {\n apiModel: ApiModel;\n inputFolder: string;\n outputFolder: string;\n}\n\nexport abstract class BaseAction extends CommandLineAction {\n private _inputFolderParameter!: CommandLineStringParameter;\n private _outputFolderParameter!: CommandLineStringParameter;\n\n protected onDefineParameters(): void {\n // override\n this._inputFolderParameter = this.defineStringParameter({\n parameterLongName: '--input-folder',\n parameterShortName: '-i',\n argumentName: 'FOLDER1',\n description:\n `Specifies the input folder containing the *.api.json files to be processed.` +\n ` If omitted, the default is \"./input\"`\n });\n\n this._outputFolderParameter = this.defineStringParameter({\n parameterLongName: '--output-folder',\n parameterShortName: '-o',\n argumentName: 'FOLDER2',\n description:\n `Specifies the output folder where the documentation will be written.` +\n ` ANY EXISTING CONTENTS WILL BE DELETED!` +\n ` If omitted, the default is \"./${this.actionName}\"`\n });\n }\n\n protected buildApiModel(): IBuildApiModelResult {\n const apiModel: ApiModel = new ApiModel();\n\n const inputFolder: string = this._inputFolderParameter.value || './input';\n if (!FileSystem.exists(inputFolder)) {\n throw new Error('The input folder does not exist: ' + inputFolder);\n }\n\n const outputFolder: string = this._outputFolderParameter.value || `./${this.actionName}`;\n FileSystem.ensureFolder(outputFolder);\n\n for (const filename of FileSystem.readFolderItemNames(inputFolder)) {\n if (filename.match(/\\.api\\.json$/i)) {\n console.log(`Reading ${filename}`);\n const filenamePath: string = path.join(inputFolder, filename);\n apiModel.loadPackage(filenamePath);\n }\n }\n\n this._applyInheritDoc(apiModel, apiModel);\n\n return { apiModel, inputFolder, outputFolder };\n }\n\n // TODO: This is a temporary workaround. The long term plan is for API Extractor's DocCommentEnhancer\n // to apply all @inheritDoc tags before the .api.json file is written.\n // See DocCommentEnhancer._applyInheritDoc() for more info.\n private _applyInheritDoc(apiItem: ApiItem, apiModel: ApiModel): void {\n if (apiItem instanceof ApiDocumentedItem) {\n if (apiItem.tsdocComment) {\n const inheritDocTag: tsdoc.DocInheritDocTag | undefined = apiItem.tsdocComment.inheritDocTag;\n\n if (inheritDocTag && inheritDocTag.declarationReference) {\n // Attempt to resolve the declaration reference\n const result: IResolveDeclarationReferenceResult = apiModel.resolveDeclarationReference(\n inheritDocTag.declarationReference,\n apiItem\n );\n\n if (result.errorMessage) {\n console.log(\n colors.yellow(\n `Warning: Unresolved @inheritDoc tag for ${apiItem.displayName}: ` + result.errorMessage\n )\n );\n } else {\n if (\n result.resolvedApiItem instanceof ApiDocumentedItem &&\n result.resolvedApiItem.tsdocComment &&\n result.resolvedApiItem !== apiItem\n ) {\n this._copyInheritedDocs(apiItem.tsdocComment, result.resolvedApiItem.tsdocComment);\n }\n }\n }\n }\n }\n\n // Recurse members\n if (ApiItemContainerMixin.isBaseClassOf(apiItem)) {\n for (const member of apiItem.members) {\n this._applyInheritDoc(member, apiModel);\n }\n }\n }\n\n /**\n * Copy the content from `sourceDocComment` to `targetDocComment`.\n * This code is borrowed from DocCommentEnhancer as a temporary workaround.\n */\n private _copyInheritedDocs(targetDocComment: tsdoc.DocComment, sourceDocComment: tsdoc.DocComment): void {\n targetDocComment.summarySection = sourceDocComment.summarySection;\n targetDocComment.remarksBlock = sourceDocComment.remarksBlock;\n\n targetDocComment.params.clear();\n for (const param of sourceDocComment.params) {\n targetDocComment.params.add(param);\n }\n for (const typeParam of sourceDocComment.typeParams) {\n targetDocComment.typeParams.add(typeParam);\n }\n targetDocComment.returnsBlock = sourceDocComment.returnsBlock;\n\n targetDocComment.inheritDocTag = undefined;\n }\n}\n"]}
\No newline at end of file