Skip to content

Commit

Permalink
feat(api-markdown-documenter): Add api item name to document nodes (#…
Browse files Browse the repository at this point in the history
…17113)

Gives consumers of the document nodes a bit more contextual information
about what the document represents in terms of the API model. Useful for
generating derived metadata, etc.

Also makes a couple of misc. logging improvements.
  • Loading branch information
Josmithr authored Aug 31, 2023
1 parent c5dccc6 commit a7c481c
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ export type DocumentBoundaries = ApiMemberKind[];
// @public
export class DocumentNode implements Parent<SectionNode>, DocumentNodeProps {
constructor(props: DocumentNodeProps);
readonly apiItemName: string;
readonly children: SectionNode[];
readonly filePath: string;
readonly frontMatter?: string;
Expand All @@ -227,6 +228,7 @@ export class DocumentNode implements Parent<SectionNode>, DocumentNodeProps {

// @public
export interface DocumentNodeProps {
readonly apiItemName: string;
readonly children: SectionNode[];
readonly filePath: string;
readonly frontMatter?: string;
Expand Down
2 changes: 1 addition & 1 deletion tools/api-markdown-documenter/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fluid-tools/api-markdown-documenter",
"version": "0.7.1",
"version": "0.7.2",
"description": "Processes .api.json files generated by API-Extractor and generates Markdown documentation from them.",
"homepage": "https://fluidframework.com",
"repository": {
Expand Down
7 changes: 6 additions & 1 deletion tools/api-markdown-documenter/src/RenderMarkdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ export async function renderDocumentsAsMarkdown(
config: MarkdownRenderConfiguration,
outputDirectoryPath: string,
): Promise<void> {
const { logger } = config;

logger?.verbose("Rendering documents as Markdown and writing to disk...");

const completeRenderConfig = getMarkdownRenderConfigurationWithDefaults(config);

await FileSystem.ensureEmptyFolderAsync(outputDirectoryPath);
Expand All @@ -80,5 +84,6 @@ export async function renderDocumentsAsMarkdown(
});
}),
);
console.log("Documents written to disk.");

logger?.success("Markdown documents written to disk.");
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function transformApiModel(
const config = getApiItemTransformationConfigurationWithDefaults(transformConfig);
const { apiModel, logger, skipPackage } = config;

logger.info(`Generating Markdown documentation for API Model ${apiModel.displayName}...`);
logger.verbose(`Generating documentation for API Model...`);

// If a package has multiple entry-points, it's possible for the same API item to appear under more than one
// entry-point (i.e., we are traversing a graph, rather than a tree).
Expand Down Expand Up @@ -112,7 +112,7 @@ export function transformApiModel(
}
}

logger.success("Documents generated!");
logger.success("API Model documents generated!");

return [...documents.values()];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export function createDocument(
}

return new DocumentNode({
apiItemName: documentItem.displayName,
children: contents,
filePath: getFilePathForApiItem(documentItem, config),
frontMatter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ describe("ApiItem to Documentation transformation tests", () => {
// The model-level doc in this case isn't particularly interesting, so we will skip evaluating it.

const expectedPackageDoc = new DocumentNode({
apiItemName: "test-package",
filePath: "test-package.md",
children: [
new SectionNode(
Expand Down Expand Up @@ -401,6 +402,7 @@ describe("ApiItem to Documentation transformation tests", () => {
expect(documents[1]).to.deep.equal(expectedPackageDoc);

const expectedEntryPointADoc = new DocumentNode({
apiItemName: "entry-point-a",
filePath: "test-package/entry-point-a-entrypoint.md",
children: [
new SectionNode(
Expand Down Expand Up @@ -484,6 +486,7 @@ describe("ApiItem to Documentation transformation tests", () => {
expect(documents[2]).to.deep.equal(expectedEntryPointADoc);

const expectedEntryPointBDoc = new DocumentNode({
apiItemName: "entry-point-b",
filePath: "test-package/entry-point-b-entrypoint.md",
children: [
new SectionNode(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ import { SectionNode } from "./SectionNode";
* {@link DocumentNode} construction properties.
*/
export interface DocumentNodeProps {
/**
* Name of the API item from which this document node was generated.
*/
readonly apiItemName: string;

/**
* Child nodes.
*
Expand Down Expand Up @@ -43,6 +48,11 @@ export class DocumentNode implements UnistParent<SectionNode>, DocumentNodeProps
*/
public readonly type = DocumentationNodeType.Document;

/**
* {@inheritDoc DocumentNodeProps.apiItemName}
*/
public readonly apiItemName: string;

/**
* {@inheritDoc DocumentNodeProps.children}
*/
Expand All @@ -59,6 +69,7 @@ export class DocumentNode implements UnistParent<SectionNode>, DocumentNodeProps
public readonly frontMatter?: string;

public constructor(props: DocumentNodeProps) {
this.apiItemName = props.apiItemName;
this.children = props.children;
this.filePath = props.filePath;
this.frontMatter = props.frontMatter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { getRenderConfigurationWithDefaults } from "../configuration";
describe("Document rendering tests", () => {
it("Renders a simple document", () => {
const document = new DocumentNode({
apiItemName: "Foo",
children: [
new SectionNode(
[
Expand Down

0 comments on commit a7c481c

Please sign in to comment.