Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply typedoc breaking changes #68

Merged
merged 1 commit into from
Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 14 additions & 30 deletions components/convert-component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {
import {
Application,
Converter,
ReflectionKind,
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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);
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
Expand All @@ -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:
Expand Down
167 changes: 77 additions & 90 deletions components/render-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
});
}
}

/**
Expand All @@ -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;
Expand Down
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
},
"devDependencies": {
"@types/node": "^18.11.0",
"typedoc": "^0.23.17",
"typedoc": "^0.23.21",
"typescript": "^4.8.4"
}
}
2 changes: 2 additions & 0 deletions utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down