Skip to content

Commit

Permalink
feat(docgen): update typedoc
Browse files Browse the repository at this point in the history
  • Loading branch information
iCrawl committed Jun 10, 2022
1 parent 2791c86 commit b3346f4
Show file tree
Hide file tree
Showing 21 changed files with 663 additions and 486 deletions.
2 changes: 1 addition & 1 deletion packages/actions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"tslib": "^2.4.0"
},
"devDependencies": {
"@types/node": "^16.11.38",
"@types/node": "^16.11.39",
"@typescript-eslint/eslint-plugin": "^5.27.1",
"@typescript-eslint/parser": "^5.27.1",
"eslint": "^8.17.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/builders/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"dependencies": {
"@sapphire/shapeshift": "^3.1.0",
"@sindresorhus/is": "^4.6.0",
"discord-api-types": "^0.33.4",
"discord-api-types": "^0.33.5",
"fast-deep-equal": "^3.1.3",
"ts-mixer": "^6.0.1",
"tslib": "^2.4.0"
Expand All @@ -63,7 +63,7 @@
"@discordjs/docgen": "workspace:^",
"@discordjs/scripts": "workspace:^",
"@favware/cliff-jumper": "^1.8.3",
"@types/node": "^16.11.38",
"@types/node": "^16.11.39",
"@typescript-eslint/eslint-plugin": "^5.27.1",
"@typescript-eslint/parser": "^5.27.1",
"eslint": "^8.17.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/collection/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"@discordjs/docgen": "workspace:^",
"@discordjs/scripts": "workspace:^",
"@favware/cliff-jumper": "^1.8.3",
"@types/node": "^16.11.38",
"@types/node": "^16.11.39",
"@typescript-eslint/eslint-plugin": "^5.27.1",
"@typescript-eslint/parser": "^5.27.1",
"eslint": "^8.17.0",
Expand Down
8 changes: 4 additions & 4 deletions packages/discord.js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,25 @@
"@discordjs/rest": "workspace:^",
"@sapphire/snowflake": "^3.2.2",
"@types/ws": "^8.5.3",
"discord-api-types": "^0.33.4",
"discord-api-types": "^0.33.5",
"fast-deep-equal": "^3.1.3",
"lodash.snakecase": "^4.1.1",
"tslib": "^2.4.0",
"undici": "^5.4.0",
"ws": "^8.7.0"
"ws": "^8.8.0"
},
"devDependencies": {
"@discordjs/docgen": "workspace:^",
"@favware/cliff-jumper": "^1.8.3",
"@types/node": "^16.11.38",
"@types/node": "^16.11.39",
"dtslint": "^4.2.1",
"eslint": "^8.17.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-prettier": "^4.0.0",
"husky": "^8.0.1",
"is-ci": "^3.0.1",
"jest": "^28.1.0",
"jest": "^28.1.1",
"prettier": "^2.6.2",
"tsd": "^0.20.0",
"tslint": "^6.1.3",
Expand Down
4 changes: 2 additions & 2 deletions packages/docgen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@
"commander": "^9.3.0",
"jsdoc-to-markdown": "^7.1.1",
"tslib": "^2.4.0",
"typedoc": "^0.22.17"
"typedoc": "^0.23.0-beta.4"
},
"devDependencies": {
"@favware/cliff-jumper": "^1.8.3",
"@types/jsdoc-to-markdown": "^7.0.3",
"@types/node": "^16.11.38",
"@types/node": "^16.11.39",
"@typescript-eslint/eslint-plugin": "^5.27.1",
"@typescript-eslint/parser": "^5.27.1",
"eslint": "^8.17.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/docgen/src/documentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export class Documentation {
item = new DocumentedMember(member, this.config);
break;
}
case 'event': {
case 'Event': {
item = new DocumentedEvent(member, this.config);
break;
}
Expand Down
31 changes: 22 additions & 9 deletions packages/docgen/src/types/class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,32 +80,45 @@ export class DocumentedClass extends DocumentedItem<Class | DeclarationReflectio
public override serializer() {
if (this.config.typescript) {
const data = this.data as DeclarationReflection;
const signature = (data.signatures ?? [])[0] ?? data;
let meta;

const sources = data.sources?.[0];
if (sources) {
meta = new DocumentedItemMeta(sources, this.config).serialize();
}

// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
const see = signature.comment?.blockTags?.filter((t) => t.tag === '@see').length
? signature.comment.blockTags
.filter((t) => t.tag === '@see')
.map((t) => t.content.find((c) => c.kind === 'text')?.text.trim())
: undefined;

return {
// @ts-expect-error
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
name: data.name === 'default' ? parse(meta?.file ?? 'default').name : data.name,
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
description: data.comment?.shortText?.trim(),
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
see: data.comment?.tags?.filter((t) => t.tagName === 'see').map((t) => t.text.trim()),
name: signature.name === 'default' ? parse(meta?.file ?? 'default').name : signature.name,
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
description: signature.comment?.summary.reduce((prev, curr) => (prev += curr.text), '').trim() || undefined,
see,
extends: this.extends?.serialize(),
implements: this.implements?.serialize(),
access:
data.flags.isPrivate ||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
data.flags.isPrivate || data.comment?.tags?.some((t) => t.tagName === 'private' || t.tagName === 'internal')
signature.comment?.blockTags?.some((t) => t.tag === '@private' || t.tag === '@internal')
? 'private'
: undefined,
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing, @typescript-eslint/no-unnecessary-condition
abstract: signature.comment?.blockTags?.some((t) => t.tag === '@abstract') || undefined,
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
abstract: data.comment?.tags?.some((t) => t.tagName === 'abstract'),
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
deprecated: data.comment?.tags?.some((t) => t.tagName === 'deprecated'),
deprecated: signature.comment?.blockTags?.some((t) => t.tag === '@deprecated')
? signature.comment.blockTags
.find((t) => t.tag === '@deprecated')
?.content.reduce((prev, curr) => (prev += curr.text), '')
.trim() ?? true
: undefined,
construct: this.construct?.serialize(),
props: this.props.size ? this.props.map((p) => p.serialize()) : undefined,
methods: this.methods.size ? this.methods.map((m) => m.serialize()) : undefined,
Expand Down
18 changes: 12 additions & 6 deletions packages/docgen/src/types/constructor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,22 @@ export class DocumentedConstructor extends DocumentedItem<Constructor | Declarat
const data = this.data as DeclarationReflection;
const signature = (data.signatures ?? [])[0] ?? data;

// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
const see = signature.comment?.blockTags?.filter((t) => t.tag === '@see').length
? signature.comment.blockTags
.filter((t) => t.tag === '@see')
.map((t) => t.content.find((c) => c.kind === 'text')?.text.trim())
: undefined;

return {
name: data.name,
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
description: signature.comment?.shortText?.trim(),
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
see: signature.comment?.tags?.filter((t) => t.tagName === 'see').map((t) => t.text.trim()),
name: signature.name,
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, @typescript-eslint/prefer-nullish-coalescing
description: signature.comment?.summary?.reduce((prev, curr) => (prev += curr.text), '').trim() || undefined,
see,
access:
data.flags.isPrivate ||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
signature.comment?.tags?.some((t) => t.tagName === 'private' || t.tagName === 'internal')
signature.comment?.blockTags?.some((t) => t.tag === '@private' || t.tag === '@internal')
? 'private'
: undefined,
// @ts-expect-error
Expand Down
23 changes: 17 additions & 6 deletions packages/docgen/src/types/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,25 @@ export class DocumentedEvent extends DocumentedItem<Event | DeclarationReflectio
meta = new DocumentedItemMeta(sources, this.config).serialize();
}

// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
const see = signature.comment?.blockTags?.filter((t) => t.tag === '@see').length
? signature.comment.blockTags
.filter((t) => t.tag === '@see')
.map((t) => t.content.find((c) => c.kind === 'text')?.text.trim())
: undefined;

return {
name: data.name,
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
description: signature.comment?.shortText?.trim(),
name: signature.name,
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, @typescript-eslint/prefer-nullish-coalescing
description: signature.comment?.summary?.reduce((prev, curr) => (prev += curr.text), '').trim() || undefined,
see,
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
see: signature.comment?.tags?.filter((t) => t.tagName === 'see').map((t) => t.text.trim()),
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
deprecated: signature.comment?.tags?.some((t) => t.tagName === 'deprecated'),
deprecated: signature.comment?.blockTags?.some((t) => t.tag === '@deprecated')
? signature.comment.blockTags
.find((t) => t.tag === '@deprecated')
?.content.reduce((prev, curr) => (prev += curr.text), '')
.trim() ?? true
: undefined,
// @ts-expect-error
params: signature.parameters
? (signature as SignatureReflection).parameters?.map((p) => new DocumentedParam(p, this.config).serialize())
Expand Down
5 changes: 3 additions & 2 deletions packages/docgen/src/types/item-meta.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { basename, dirname, relative } from 'node:path';
import { basename, relative } from 'node:path';
import type { SourceReference } from 'typedoc';
import { DocumentedItem } from './item.js';
import type { Meta } from '../interfaces/index.js';
Expand All @@ -11,7 +11,8 @@ export class DocumentedItemMeta extends DocumentedItem<Meta | SourceReference> {
return {
line: data.line,
file: basename(data.fileName),
path: dirname(data.fileName),
path: undefined,
url: data.url,
};
}

Expand Down
108 changes: 65 additions & 43 deletions packages/docgen/src/types/member.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,55 @@ export class DocumentedMember extends DocumentedItem<Member | DeclarationReflect
public override serializer() {
if (this.config.typescript) {
const data = this.data as DeclarationReflection;
const signature = (data.signatures ?? [])[0] ?? data;
let meta;

const sources = data.sources?.[0];
if (sources) {
meta = new DocumentedItemMeta(sources, this.config).serialize();
}

// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
const see = signature.comment?.blockTags?.filter((t) => t.tag === '@see').length
? signature.comment.blockTags
.filter((t) => t.tag === '@see')
.map((t) => t.content.find((c) => c.kind === 'text')?.text.trim())
: undefined;

const base = {
name: data.name,
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
description: data.comment?.shortText?.trim(),
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
see: data.comment?.tags?.filter((t) => t.tagName === 'see').map((t) => t.text.trim()),
name: signature.name,
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, @typescript-eslint/prefer-nullish-coalescing
description: signature.comment?.summary?.reduce((prev, curr) => (prev += curr.text), '').trim() || undefined,
see,
scope: data.flags.isStatic ? 'static' : undefined,
access:
data.flags.isPrivate ||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
data.flags.isPrivate || data.comment?.tags?.some((t) => t.tagName === 'private' || t.tagName === 'internal')
signature.comment?.blockTags?.some((t) => t.tag === '@private' || t.tag === '@internal')
? 'private'
: undefined,
readonly: data.flags.isReadonly,
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, @typescript-eslint/prefer-nullish-coalescing
abstract: signature.comment?.blockTags?.some((t) => t.tag === '@abstract') || undefined,
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
abstract: data.comment?.tags?.some((t) => t.tagName === 'abstract'),
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
deprecated: data.comment?.tags?.some((t) => t.tagName === 'deprecated'),
deprecated: signature.comment?.blockTags?.some((t) => t.tag === '@deprecated')
? signature.comment.blockTags
.find((t) => t.tag === '@deprecated')
?.content.reduce((prev, curr) => (prev += curr.text), '')
.trim() ?? true
: undefined,
default:
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
data.comment?.tags?.find((t) => t.tagName === 'default')?.text.trim() ??
(data.defaultValue === '...' ? undefined : data.defaultValue),
type: data.type ? new DocumentedVarType({ names: [parseType(data.type)] }, this.config).serialize() : undefined,
(data.defaultValue === '...' ? undefined : data.defaultValue) ??
(signature.comment?.blockTags
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
?.find((t) => t.tag === '@default')
?.content.reduce((prev, curr) => (prev += curr.text), '')
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
.trim() ||
undefined),
type: signature.type
? new DocumentedVarType({ names: [parseType(signature.type)] }, this.config).serialize()
: undefined,
meta,
};

Expand All @@ -50,28 +70,47 @@ export class DocumentedMember extends DocumentedItem<Member | DeclarationReflect
throw new Error("Can't parse accessor without getter.");
}

if (!hasSetter) base.readonly = true;
if (!hasSetter) {
base.readonly = true;
}

// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
const see = getter.comment?.blockTags?.filter((t) => t.tag === '@see').length
? getter.comment.blockTags
.filter((t) => t.tag === '@see')
.map((t) => t.content.find((c) => c.kind === 'text')?.text.trim())
: undefined;

return {
...base,
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
description: getter.comment?.shortText?.trim(),
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
see: getter.comment?.tags?.filter((t) => t.tagName === 'see').map((t) => t.text.trim()),
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, @typescript-eslint/prefer-nullish-coalescing
description: getter.comment?.summary?.reduce((prev, curr) => (prev += curr.text), '').trim() || undefined,
see,
access:
getter.flags.isPrivate ||
getter.comment?.tags.some((t) => t.tagName === 'private' || t.tagName === 'internal')
data.flags.isPrivate ||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
getter.comment?.blockTags?.some((t) => t.tag === '@private' || t.tag === '@internal')
? 'private'
: undefined,
readonly: base.readonly || !hasSetter,
abstract: getter.comment?.tags.some((t) => t.tagName === 'abstract'),
deprecated: getter.comment?.tags.some((t) => t.tagName === 'deprecated'),
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, @typescript-eslint/prefer-nullish-coalescing
abstract: getter.comment?.blockTags?.some((t) => t.tag === '@abstract') || undefined,
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
deprecated: getter.comment?.blockTags?.some((t) => t.tag === '@deprecated')
? getter.comment.blockTags
.find((t) => t.tag === '@deprecated')
?.content.reduce((prev, curr) => (prev += curr.text), '')
.trim() ?? true
: undefined,
default:
base.default ??
getter.comment?.tags.find((t) => t.tagName === 'default')?.text.trim() ??
// @ts-expect-error
getter.defaultValue,
(getter.comment?.blockTags
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
?.find((t) => t.tag === '@default')
?.content.reduce((prev, curr) => (prev += curr.text), '')
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
.trim() ||
undefined),
type: getter.type ? parseType(getter.type) : undefined,
};
}
Expand Down Expand Up @@ -99,20 +138,3 @@ export class DocumentedMember extends DocumentedItem<Member | DeclarationReflect
};
}
}

/*
{ id: 'Client#rest',
longname: 'Client#rest',
name: 'rest',
scope: 'instance',
kind: 'member',
description: 'The REST manager of the client',
memberof: 'Client',
type: { names: [ 'RESTManager' ] },
access: 'private',
meta:
{ lineno: 32,
filename: 'Client.js',
path: 'src/client' },
order: 11 }
*/
Loading

1 comment on commit b3346f4

@vercel
Copy link

@vercel vercel bot commented on b3346f4 Jun 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.