import { Project , SyntaxKind , JSDocableNode } from 'ts-morph' ; const JS_DOCTAG_REGEX = /\/\*\*\s*\n([^\*]|(\*(?!\/)))*\*\// ; export const setReleaseTags = async ( dtsPath , releaseTag = 'internal' ) => { const project = new Project ( { } ) ; const sourceFiles = project . addSourceFilesAtPaths ( dtsPath + '/**/*.d.ts' ) ; for ( let sourceFile of sourceFiles ) { sourceFile . forEachDescendant ( ( node , traversal ) => { const leadingCommentRanges = node . getLeadingCommentRanges ( ) ; const comment = leadingCommentRanges . pop ( ) ; if ( comment ?. getText ( ) . match ( JS_DOCTAG_REGEX ) ) { return ; } switch ( node . getKind ( ) ) { case SyntaxKind . PropertyDeclaration : case SyntaxKind . ClassDeclaration : case SyntaxKind . MethodDeclaration : case SyntaxKind . Constructor : case SyntaxKind . VariableStatement : case SyntaxKind . TypeAliasDeclaration : case SyntaxKind . InterfaceDeclaration : ( < JSDocableNode > < unknown > node ) . addJsDoc ( { description : `@${ releaseTag }` } ) ; traversal . skip ( ) ; } } ) ; } return await project . save ( ) ; } ;