Skip to content

Commit

Permalink
fix: using split-by-submodule omits documentation for anything in the…
Browse files Browse the repository at this point in the history
… root of the project

Extend the "index" page to contain a list of submodules and the reference for any symbols in the root namespace.
  • Loading branch information
mrgrain committed Dec 19, 2023
1 parent 1ae3fdc commit 9f7f4bd
Show file tree
Hide file tree
Showing 4 changed files with 1,111 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/docgen/render/markdown-render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,11 @@ export class MarkdownRenderer {
public visitSubmodules(submodules: readonly reflect.Submodule[], fileSuffix: string): MarkdownDocument {
const md = new MarkdownDocument({ header: { title: 'Submodules' }, id: 'submodules' });
md.lines('The following submodules are available:');
md.lines('');
for (const submodule of submodules) {
md.lines(`- [${submoduleRelName(submodule)}](./${submoduleRelName(submodule)}.${fileSuffix})`);
}
md.lines('');
return md;
}

Expand Down
32 changes: 30 additions & 2 deletions src/docgen/view/documentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,40 @@ export class Documentation {

public async toIndexMarkdown(fileSuffix:string, options: RenderOptions) {
const assembly = await this.createAssembly(undefined, { loose: true, validate: false });

return MarkdownRenderer.fromSubmodules(await this.listSubmodules(), fileSuffix, {
const submodules = await this.listSubmodules();
const schema = (await this.toJson({
...options,
submodule: undefined,
allSubmodules: false,
})).content;

const ref = new MarkdownDocument({ header: { title: 'API Reference' }, id: 'api-reference' });

if (schema.version !== CURRENT_SCHEMA_VERSION) {
throw new Error(`Unexpected schema version: ${schema.version}`);
}

const renderer = new MarkdownRenderer({
language: options.language,
packageName: assembly.name,
packageVersion: assembly.version,
});

if (submodules.length) {
ref.section(renderer.visitSubmodules(submodules, fileSuffix));
}

if (schema.apiReference) {
ref.section(renderer.visitConstructs(schema.apiReference.constructs));
ref.section(renderer.visitStructs(schema.apiReference.structs));
ref.section(renderer.visitClasses(schema.apiReference.classes));
ref.section(renderer.visitInterfaces(schema.apiReference.interfaces));
ref.section(renderer.visitEnums(schema.apiReference.enums));
}

const documentation = new MarkdownDocument();
documentation.section(ref);
return documentation;
}

/**
Expand Down
Loading

0 comments on commit 9f7f4bd

Please sign in to comment.