diff --git a/components/convert-component.ts b/components/convert-component.ts index 3bbc664..cdec0d1 100644 --- a/components/convert-component.ts +++ b/components/convert-component.ts @@ -1,4 +1,4 @@ -import { +import { Application, Converter, ReflectionKind, @@ -68,7 +68,7 @@ export class ConvertComponent { */ this.mainDirToExport = options[Constants.CONVERT_OPTION]; - if(!this.fileOperations.ifDirectoryExists(this.mainDirToExport)) { + if (!this.fileOperations.ifDirectoryExists(this.mainDirToExport)) { this.fileOperations.createDir(this.mainDirToExport); } } @@ -112,7 +112,7 @@ export class ConvertComponent { /** * Write all collected data for all global functions into corresponding file. - */ + */ const funcObjKeys = Object.keys(this.globalFuncsJson); if (funcObjKeys.length) { this.fileOperations.appendFileData(this.mainDirToExport, null, Constants.GLOBAL_FUNCS_FILE_NAME, 'json', this.globalFuncsJson); @@ -125,7 +125,7 @@ export class ConvertComponent { * @param reflection */ private resolve(context, reflection) { - switch(reflection.kind) { + switch (reflection.kind) { case ReflectionKind.Enum: case ReflectionKind.Class: case ReflectionKind.Interface: @@ -163,12 +163,12 @@ export class ConvertComponent { this.factoryInstance.appendAttribute(this.jsonObjectName, reflection.kind, reflection.name, getData); break; case ReflectionKind.Function: - const funcData = this.getCommentInfo(reflection.signatures[0]); - const funcInstance = this.instanceBuilder(reflection.kind, reflection.name); - funcInstance.buildObjectStructure(funcData); - if (!funcInstance.isEmpty()) { - this.globalFuncsJson = Object.assign(funcInstance.getJsonContent(), this.globalFuncsJson); - } + const funcData = this.getCommentInfo(reflection.signatures[0]); + const funcInstance = this.instanceBuilder(reflection.kind, reflection.name); + funcInstance.buildObjectStructure(funcData); + if (!funcInstance.isEmpty()) { + this.globalFuncsJson = Object.assign(funcInstance.getJsonContent(), this.globalFuncsJson); + } break; case ReflectionKind.GetSignature: case ReflectionKind.SetSignature: @@ -194,7 +194,7 @@ export class ConvertComponent { let comment = this.getCommentData(reflection.comment); if (options[Constants.INCLUDE_TAGS_OPTION] && reflection.comment.tags) { - comment[Constants.COMMENT] = Object.assign(this.getTagsComments(reflection.comment), comment[Constants.COMMENT]); + comment[Constants.COMMENT] = Object.assign(this.getTagsComments(reflection.comment), comment[Constants.COMMENT]); } if (options[Constants.INCLUDE_PARAMS_OPTION] && reflection.parameters) { @@ -265,24 +265,8 @@ export class ConvertComponent { const comment = {}; comment[Constants.COMMENT] = {}; - - let splittedObj; - if(obj.text && obj.text.trim().length) { - splittedObj = this.parser.splitByCharacter(obj.text, '\n'); - comment[Constants.COMMENT][Constants.TEXT] = splittedObj; - } - - if(obj.shortText && obj.shortText.trim().length) { - splittedObj = this.parser.splitByCharacter(obj.shortText, '\n'); - comment[Constants.COMMENT][Constants.SHORT_TEXT] = splittedObj; - } - - if(obj.tagName) { - comment[Constants.COMMENT][Constants.TAG_NAME] = obj.tagName; - } - - if(obj.returns) { - comment[Constants.COMMENT][Constants.RETURNS] = obj.returns; + if (obj.summary) { + comment[Constants.COMMENT] = obj; } return comment; @@ -294,7 +278,7 @@ export class ConvertComponent { * @param objectName */ private instanceBuilder(objectType, objectName): BaseFactory { - switch(objectType) { + switch (objectType) { case ReflectionKind.Enum: return new EnumFactory(objectName); case ReflectionKind.Interface: diff --git a/components/render-component.ts b/components/render-component.ts index 9f40285..724f5d0 100644 --- a/components/render-component.ts +++ b/components/render-component.ts @@ -35,8 +35,8 @@ export class RenderComponenet { } public initialize() { - this.application.renderer.on(RendererEvent.BEGIN,this.onRenderBegin.bind(this)); - + this.application.renderer.on(RendererEvent.BEGIN, this.onRenderBegin.bind(this)); + this.fileOperations = new FileOperations(this.application.logger); this.parser = new Parser(); } @@ -64,57 +64,57 @@ export class RenderComponenet { } private processTheReflection(reflection) { - switch(reflection.kind) { + switch (reflection.kind) { case ReflectionKind.Class: case ReflectionKind.Enum: case ReflectionKind.Interface: - const filePath = reflection.sources[0].fileName; - let processedDir = this.mainDirOfJsons; - const parsedPath = this.fileOperations.getFileDir(filePath); - if (parsedPath) { - processedDir = path.join(processedDir, parsedPath); - } - this.data = this.fileOperations.getFileData(processedDir, reflection.name, 'json'); - if (this.data) { - this.updateComment(reflection, this.data[reflection.name]); - } + const filePath = reflection.sources[0].fileName; + let processedDir = this.mainDirOfJsons; + const parsedPath = this.fileOperations.getFileDir(filePath); + if (parsedPath) { + processedDir = path.join(processedDir, parsedPath); + } + this.data = this.fileOperations.getFileData(processedDir, reflection.name, 'json'); + if (this.data) { + this.updateComment(reflection, this.data[reflection.name]); + } break; case ReflectionKind.Property: case ReflectionKind.CallSignature: case ReflectionKind.EnumMember: - /** - * Skip reflections with type @ReflectionKind.Function because they are aslo @ReflectionKInd.CallSignature - * but the handling process here is not appropriate for them. - */ - if (reflection.parent === ReflectionKind.Function) { - break; - } - - const parent = this.getParentBasedOnType(reflection, reflection.kind); - const parentName = parent.name; - const attributeName = reflection.name; - const attributeData = this.getAttributeData(parentName, AttributeType[reflection.kind], attributeName); - if(attributeData) { - this.updateComment(reflection, attributeData); - } + /** + * Skip reflections with type @ReflectionKind.Function because they are aslo @ReflectionKInd.CallSignature + * but the handling process here is not appropriate for them. + */ + if (reflection.parent === ReflectionKind.Function) { + break; + } + + const parent = this.getParentBasedOnType(reflection, reflection.kind); + const parentName = parent.name; + const attributeName = reflection.name; + const attributeData = this.getAttributeData(parentName, AttributeType[reflection.kind], attributeName); + if (attributeData) { + this.updateComment(reflection, attributeData); + } break; case ReflectionKind.Function: - if (!this.globalFuncsData) { - break; - } - const funcName = reflection.name; - const funcData = this.globalFuncsData[funcName]; - this.updateComment(reflection.signatures[0], funcData); + if (!this.globalFuncsData) { + break; + } + const funcName = reflection.name; + const funcData = this.globalFuncsData[funcName]; + this.updateComment(reflection.signatures[0], funcData); break; case ReflectionKind.GetSignature: case ReflectionKind.SetSignature: - const accessorParent = this.getParentBasedOnType(reflection, reflection.kind); - const accessor = reflection.parent; - const accessorSignature = reflection.kind; - const data = this.getAccessorAttributeData(accessorParent.name, AttributeType[accessor.kind], accessor.name, AttributeType[accessorSignature]); - if (data) { - this.updateComment(reflection, data); - } + const accessorParent = this.getParentBasedOnType(reflection, reflection.kind); + const accessor = reflection.parent; + const accessorSignature = reflection.kind; + const data = this.getAccessorAttributeData(accessorParent.name, AttributeType[accessor.kind], accessor.name, AttributeType[accessorSignature]); + if (data) { + this.updateComment(reflection, data); + } break; default: return; @@ -142,52 +142,39 @@ export class RenderComponenet { } private updateComment(reflection, dataObj) { - if (!reflection.comment || (dataObj && !dataObj[Constants.COMMENT])) { - return; - } - - let parsed; - if (reflection.comment.text) { - parsed = this.parser.joinByCharacter(dataObj[Constants.COMMENT][Constants.TEXT], '\n'); - reflection.comment.text = parsed; - } - - if (reflection.comment.shortText) { - parsed = this.parser.joinByCharacter(dataObj[Constants.COMMENT][Constants.SHORT_TEXT], '\n'); - reflection.comment.shortText = parsed; - } - - if (reflection.comment.returns) { - parsed = this.parser.joinByCharacter(dataObj[Constants.COMMENT][Constants.RETURNS], '\n'); - reflection.comment.returns = parsed; - } - - if (reflection.comment.tags && dataObj[Constants.COMMENT][Constants.TAGS]) { - reflection.comment.tags.forEach(tag => { - const tagFromJson = dataObj[Constants.COMMENT][Constants.TAGS][tag.tagName]; - try { - tag.tagName = tagFromJson[Constants.COMMENT].tagName; - tag.text = this.parser.joinByCharacter(tagFromJson[Constants.COMMENT].text, '\n'); - } catch (e) { - if (this.warns) { - this.application.logger.log(`Could not find ${tag.tagName} tag of ${reflection.parent.name} in ${reflection.parent.parent.name}`, LogLevel.Warn); - } - } - }); - } - - if (reflection.parameters && dataObj[Constants.COMMENT][Constants.PARAMS]) { - reflection.parameters.forEach(param => { - const paramFromJson = dataObj[Constants.COMMENT][Constants.PARAMS][param.name]; - try { - param.comment.text = this.parser.joinByCharacter(paramFromJson[Constants.COMMENT].text, '\n'); - } catch(e) { - if (this.warns) { - this.application.logger.log(`Could not find ${param.name} parameter of ${reflection.parent.name} in ${reflection.parent.parent.name}`, LogLevel.Warn); - } - } - }); - } + if (!reflection.comment || (dataObj && !dataObj[Constants.COMMENT])) { + return; + } + + if (reflection.comment) { + reflection.comment.summary = dataObj[Constants.COMMENT][Constants.SUMMARY]; + } + + if (reflection.comment.blockTags && dataObj[Constants.COMMENT][Constants.BLOCK_TAGS]) { + reflection.comment.blockTags.forEach((blockTag, index) => { + const blockTagContent = dataObj[Constants.COMMENT][Constants.BLOCK_TAGS][index]; + if (blockTagContent && blockTagContent.content && blockTagContent.content.length > 0) { + blockTagContent.content.forEach((content, i) => { + const objContent = dataObj[Constants.COMMENT][Constants.BLOCK_TAGS][index].content[i].text; + reflection.comment.blockTags[index].content[i].text = objContent; + }) + } + }); + } + + if (reflection.parameters && dataObj && dataObj[Constants.COMMENT]) { + reflection.parameters.forEach(param => { + try { + if (param.comment) { + param.comment.summary = dataObj.comment.summary; + } + } catch (e) { + if (this.warns) { + this.application.logger.log(`Could not find ${param.name} parameter of ${reflection.parent.name} in ${reflection.parent.parent.name}`, LogLevel.Warn); + } + } + }); + } } /** @@ -196,10 +183,10 @@ export class RenderComponenet { * @param kind */ private getParentBasedOnType(reflection, kind) { - if (kind === ReflectionKind.CallSignature || - kind === ReflectionKind.GetSignature || + if (kind === ReflectionKind.CallSignature || + kind === ReflectionKind.GetSignature || kind === ReflectionKind.SetSignature) { - return reflection.parent.parent; + return reflection.parent.parent; } return reflection.parent; diff --git a/package-lock.json b/package-lock.json index 51d50cc..ac3e699 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,7 @@ }, "devDependencies": { "@types/node": "^18.11.0", - "typedoc": "^0.23.17", + "typedoc": "^0.23.21", "typescript": "^4.8.4" } }, @@ -115,9 +115,9 @@ } }, "node_modules/typedoc": { - "version": "0.23.17", - "resolved": "https://registry.npmjs.org/typedoc/-/typedoc-0.23.17.tgz", - "integrity": "sha512-3rtNubo1dK0pvs6ixpMAq4pESULd5/JNUqJbdyZoeilI14reb1RNVomN4fMgIadd0RMX1aenYjJSSMBOJ+/+0Q==", + "version": "0.23.21", + "resolved": "https://registry.npmjs.org/typedoc/-/typedoc-0.23.21.tgz", + "integrity": "sha512-VNE9Jv7BgclvyH9moi2mluneSviD43dCE9pY8RWkO88/DrEgJZk9KpUk7WO468c9WWs/+aG6dOnoH7ccjnErhg==", "dev": true, "dependencies": { "lunr": "^2.3.9", @@ -132,7 +132,7 @@ "node": ">= 14.14" }, "peerDependencies": { - "typescript": "4.6.x || 4.7.x || 4.8.x" + "typescript": "4.6.x || 4.7.x || 4.8.x || 4.9.x" } }, "node_modules/typescript": { @@ -254,9 +254,9 @@ } }, "typedoc": { - "version": "0.23.17", - "resolved": "https://registry.npmjs.org/typedoc/-/typedoc-0.23.17.tgz", - "integrity": "sha512-3rtNubo1dK0pvs6ixpMAq4pESULd5/JNUqJbdyZoeilI14reb1RNVomN4fMgIadd0RMX1aenYjJSSMBOJ+/+0Q==", + "version": "0.23.21", + "resolved": "https://registry.npmjs.org/typedoc/-/typedoc-0.23.21.tgz", + "integrity": "sha512-VNE9Jv7BgclvyH9moi2mluneSviD43dCE9pY8RWkO88/DrEgJZk9KpUk7WO468c9WWs/+aG6dOnoH7ccjnErhg==", "dev": true, "requires": { "lunr": "^2.3.9", diff --git a/package.json b/package.json index be5c591..c913314 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ }, "devDependencies": { "@types/node": "^18.11.0", - "typedoc": "^0.23.17", + "typedoc": "^0.23.21", "typescript": "^4.8.4" } } diff --git a/utils/constants.ts b/utils/constants.ts index ae300d5..a42f1f8 100644 --- a/utils/constants.ts +++ b/utils/constants.ts @@ -12,6 +12,8 @@ export class Constants { static readonly COMMENT = 'comment'; static readonly TEXT = 'text'; static readonly SHORT_TEXT = 'shortText'; + static readonly SUMMARY = 'summary'; + static readonly BLOCK_TAGS = 'blockTags'; /** * Options