Skip to content
This repository has been archived by the owner on Jun 8, 2022. It is now read-only.

feat: add namespace support & add extendedDescription property & add examples on class #1

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
12 changes: 12 additions & 0 deletions src/documentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import path from 'path';
import type { JSONOutput } from 'typedoc';
import type { customSettings, ProjectData } from './index';
import { ClassDoc, parseClass } from './util/class';
import { parseNamespace } from './util/namespace';
import { TypedefDoc, parseTypedef } from './util/typedef';
import { version } from '../package.json';

Expand All @@ -26,13 +27,15 @@ interface CodeDoc {
// interfaces: unknown[]
// external: unknown[]
typedefs: TypedefDoc[];
namespaces: TypedefDoc[];
}

export function generateDocs(data: ProjectData): CodeDoc {
const classes = [];
// interfaces = [], // not using this at the moment
// externals = [], // ???
const typedefs = [];
const namespaces = [];

for (const c of data.children ?? []) {
const { type, value } = parseRootElement(c);
Expand All @@ -41,6 +44,7 @@ export function generateDocs(data: ProjectData): CodeDoc {
if (type === 'class') classes.push(value);
// if (type == 'interface') interfaces.push(value)
if (type === 'typedef') typedefs.push(value);
if (type === 'namespace') namespaces.push(value);
// if (type == 'external') externals.push(value)
}

Expand All @@ -49,6 +53,7 @@ export function generateDocs(data: ProjectData): CodeDoc {
// interfaces,
// externals,
typedefs,
namespaces,
};
}

Expand All @@ -67,6 +72,11 @@ function parseRootElement(element: DeclarationReflection) {
type: 'typedef',
value: parseTypedef(element),
};
case 'Namespace':
return {
type: 'namespace',
value: parseNamespace(element),
};

// Externals?

Expand All @@ -91,4 +101,6 @@ export function parseMeta(element: DeclarationReflection): DocMeta | undefined {
path: path.dirname(meta.fileName),
};
}

return undefined;
}
30 changes: 30 additions & 0 deletions src/util/namespace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { DocMeta, parseMeta, type DeclarationReflection } from '../documentation';
import { parseTypedef, TypedefDoc } from './typedef';

export interface NamespaceDoc {
name: string;
description?: string | undefined;
see?: string[] | undefined;
deprecated?: boolean | undefined;
typeAliases?: TypedefDoc[] | undefined;
interfaces?: TypedefDoc[] | undefined;
enumerations?: TypedefDoc[] | undefined;
meta?: DocMeta | undefined;
}

export function parseNamespace(element: DeclarationReflection): NamespaceDoc {
const typeAliases = element.children?.filter((c) => c.kindString === 'Type alias');
const interfaces = element.children?.filter((c) => c.kindString === 'Interface');
const enumerations = element.children?.filter((c) => c.kindString === 'Enumeration');

return {
name: element.name,
description: element.comment?.shortText?.trim(),
see: element.comment?.tags?.filter((t) => t.tag === 'see').map((t) => t.text.trim()),
deprecated: element.comment?.tags?.some((t) => t.tag === 'deprecated'),
typeAliases: typeAliases && typeAliases.length > 0 ? typeAliases.map(parseTypedef) : undefined,
interfaces: interfaces && interfaces.length > 0 ? interfaces.map(parseTypedef) : undefined,
enumerations: enumerations && enumerations.length > 0 ? enumerations.map(parseTypedef) : undefined,
meta: parseMeta(element),
};
}