Skip to content

Commit

Permalink
fix doc generation (..until 1.9.0 breaks it again)
Browse files Browse the repository at this point in the history
  • Loading branch information
DonovanDMC committed Sep 19, 2023
1 parent 6dd393b commit 4873ef8
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 21 deletions.
5 changes: 4 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"extends": "@uwu-codes/eslint-config/esm"
"extends": "@uwu-codes/eslint-config/esm",
"rules": {
"unicorn/switch-case-braces": "off"
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"morgan": "^1.10.0",
"oceanic.js": "1.8.1-dev.08d3811",
"semver": "^7.5.1",
"typedoc": "^0.23.28"
"typedoc": "^0.24.8"
},
"devDependencies": {
"@swc/core": "^1.3.60",
Expand Down
18 changes: 9 additions & 9 deletions pnpm-lock.yaml

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

10 changes: 7 additions & 3 deletions src/docs/convertType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function resolveArrayType(type: JSONOutput.ArrayType, level = 1): { level: numbe

export default function convertType(type: JSONOutput.SomeType): string {
if ("name" in type && type.name === "default" && "id" in type && type.id !== undefined) {
type.name = getName(type.id);
type.name = getName((type as {id: number; }).id);
}
switch (type.type) {
case "array": {
Expand Down Expand Up @@ -51,7 +51,7 @@ export default function convertType(type: JSONOutput.SomeType): string {
return `{ [${readonlyModifier ? "readonly " : ""}${nameType ? `${convertType(nameType)} in ` : ""}${parameter}${optionalModifier ? "?" : ""}: ${convertType(parameterType)}]${templateType ? ` extends ${convertType(templateType)}` : ""} }`;
}

case "named-tuple-member": {
case "namedTupleMember": {
const { name, isOptional, element } = type;
return `${name}${isOptional ? "?" : ""}: ${convertType(element)}`;
}
Expand All @@ -77,6 +77,9 @@ export default function convertType(type: JSONOutput.SomeType): string {
}

case "reference": {
if ("name" in type && type.name === "default" && "target" in type && type.target !== undefined) {
type.name = typeof type.target === "object" ? type.target.qualifiedName : getName(type.target);
}
const { name, typeArguments } = type;
return `${name}${typeArguments ? `<${typeArguments.map(convertType).join(", ")}>` : ""}`;
}
Expand Down Expand Up @@ -110,7 +113,7 @@ export default function convertType(type: JSONOutput.SomeType): string {
return `...${convertType(type.elementType)}`;
}

case "template-literal": {
case "templateLiteral": {
const { head, tail } = type;
return `\`${head}${tail.map(([t, literal]) => `\${${convertType(t)}}${literal}`).join("")}\``;
}
Expand All @@ -133,6 +136,7 @@ export default function convertType(type: JSONOutput.SomeType): string {
}

default: {
console.log(`TODO Type: ${(type as { type: string; }).type}`);
return `TODO: ${(type as { type: string; }).type}`;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/docs/idToName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export function getMap() {
export function getName(id: number) {
if (!nameMap.has(id)) {
console.log(`Missing name for ${id}`);
console.debug(new TypeError(`Missing name for ${id}`).stack);
}
return nameMap.get(id) ?? `default[${id}]`;
}
Expand Down
2 changes: 1 addition & 1 deletion src/docs/process/accessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default function processAccessor(data: JSONOutput.DeclarationReflection)
return;
}
if (data.getSignature.type && "name" in data.getSignature.type && data.getSignature.type.name === "default" && "id" in data.getSignature.type && data.getSignature.type.id !== undefined) {
data.getSignature.type.name = getName(data.getSignature.type.id);
data.getSignature.type.name = getName((data.getSignature.type as { id: number; }).id);
}
return {
comment: data.getSignature.comment?.summary.reduce((a, b) => a + b.text, ""),
Expand Down
2 changes: 1 addition & 1 deletion src/docs/process/constructor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default function processConstructor(data: JSONOutput.DeclarationReflectio
continue;
}
if (param.type && "name" in param.type && param.type.name === "default" && "id" in param.type && param.type.id !== undefined) {
param.type.name = getName(param.type.id);
param.type.name = getName((param.type as { id: number; }).id);
}
construct.parameters.push({
name: param.name,
Expand Down
2 changes: 1 addition & 1 deletion src/docs/process/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default function processFunction(data: JSONOutput.DeclarationReflection,
continue;
}
if (param.type && "name" in param.type && param.type.name === "default" && "id" in param.type && param.type.id !== undefined) {
param.type.name = getName(param.type.id);
param.type.name = getName((param.type as { id: number; }).id);
}
func.parameters.push({
name: param.name,
Expand Down
2 changes: 1 addition & 1 deletion src/docs/process/method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default function processMethod(data: JSONOutput.DeclarationReflection) {
continue;
}
if (param.type && "name" in param.type && param.type.name === "default" && "id" in param.type && param.type.id !== undefined) {
param.type.name = getName(param.type.id);
param.type.name = getName((param.type as { id: number; }).id);
}
overload.parameters.push({
name: param.name,
Expand Down
2 changes: 1 addition & 1 deletion src/docs/process/property.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default function processProperty(data: JSONOutput.DeclarationReflection)
return;
}
if (data.type && "name" in data.type && data.type.name === "default" && "id" in data.type && data.type.id !== undefined) {
data.type.name = getName(data.type.id);
data.type.name = getName((data.type as { id: number; }).id);
}
const prop: Property = {
comment: data.comment?.summary.reduce((a, b) => a + b.text, ""),
Expand Down
25 changes: 24 additions & 1 deletion src/docs/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,26 @@ export default async function run(data: JSONOutput.ProjectReflection, version: s
if (data.children) {
for (const child of data.children) {
if (child.kind !== ReflectionKind.Module) {
throw new Error(`Expected ${ReflectionKind[ReflectionKind.Module]} (${ReflectionKind.Module}), got ${ReflectionKind[child.kind]} (${child.kind}) for ${child.name} (${child.id})`);
switch (child.kind) {
case ReflectionKind.Class: {
const clazz = processClass(child, child.name);
root.classes.push(clazz);
break;
}

case ReflectionKind.Interface: {
const iface = processInterface(child, child.name);
root.interfaces.push(iface);
break;
}

default: {
throw new Error(`Unexpected kind ${ReflectionKind[child.kind]} (${child.kind}) for ${child.name} (${child.id})`);
}
}
continue;
}

if (!child.children) {
continue;
}
Expand Down Expand Up @@ -79,11 +97,16 @@ export default async function run(data: JSONOutput.ProjectReflection, version: s
}

case ReflectionKind.Reference: {
if (child2.variant !== "reference") {
console.debug(`Skipping ${child2.variant} ${ReflectionKind[child2.kind]} (${child2.kind}) for ${child2.name} (${child2.id})`);
continue;
}
const ref = processReference(child2 as JSONOutput.ReferenceReflection);
root.references.push(ref);
break;
}


// I can't be bothered to handle this right now
case ReflectionKind.Namespace: {
console.debug(`Skipping namespace ${child2.name} (${child2.id})`);
Expand Down
2 changes: 1 addition & 1 deletion src/docs/saveNames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { type JSONOutput, ReflectionKind } from "typedoc";
export default function saveNames(project: JSONOutput.ProjectReflection) {
if (project.children) {
for (const child of project.children) {
if (child.kind !== ReflectionKind.Module) {
if (![ReflectionKind.Module, ReflectionKind.Class, ReflectionKind.Interface].includes(child.kind)) {
throw new Error(`Expected ${ReflectionKind[ReflectionKind.Module]} (${ReflectionKind.Module}), got ${ReflectionKind[child.kind]} (${child.kind}) for ${child.name} (${child.id})`);
}
setName(child.id, child.name);
Expand Down
4 changes: 4 additions & 0 deletions src/util/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ export interface IConfig {
};
cookieSecret: string;
dataDir: string;
degenerateWebhook: {
id: string;
token: string;
};
docsWebhook: {
id: string;
token: string;
Expand Down

0 comments on commit 4873ef8

Please sign in to comment.