-
Notifications
You must be signed in to change notification settings - Fork 792
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(docs-readme): add overview to readme
this commit adds an 'Overview' section to the generated `README.md` file for a component. this implementation is simple (and arguably naive) intentionally. there is quite a bit that folks could do in the context of a JSDoc. rather than attempting to capture every use case and potentially overcomplicate our solution, we start simple and can iterate from there.
- Loading branch information
1 parent
af55016
commit 241e8f1
Showing
3 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* Generate an 'Overview' section for a markdown file | ||
* @param overview a component-level comment string to place in a markdown file | ||
* @returns The generated Overview section. If the provided overview is empty, return an empty list | ||
*/ | ||
export const overviewToMarkdown = (overview: string): ReadonlyArray<string> => { | ||
if (!overview) { | ||
return []; | ||
} | ||
|
||
const content: string[] = []; | ||
content.push(`## Overview`); | ||
content.push(''); | ||
content.push(`${overview.trim()}`); | ||
content.push(''); | ||
|
||
return content; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { overviewToMarkdown } from '../readme/markdown-overview'; | ||
|
||
describe('markdown-overview', () => { | ||
describe('overviewToMarkdown', () => { | ||
it('returns an empty string if no docs exist on the component', () => { | ||
const generatedOverview = overviewToMarkdown('').join('\n'); | ||
|
||
expect(generatedOverview).toBe(''); | ||
}); | ||
|
||
it('generates a single line overview', () => { | ||
const generatedOverview = overviewToMarkdown('This is a custom button component').join('\n'); | ||
|
||
expect(generatedOverview).toBe(`## Overview | ||
This is a custom button component | ||
`); | ||
}); | ||
|
||
it('generates a multi-line overview', () => { | ||
const description = `This is a custom button component. | ||
It is to be used throughout the design system. | ||
This is a comment followed by an extra newline. | ||
`; | ||
const generatedOverview = overviewToMarkdown(description).join('\n'); | ||
|
||
expect(generatedOverview).toBe(`## Overview | ||
This is a custom button component. | ||
It is to be used throughout the design system. | ||
This is a comment followed by an extra newline. | ||
`); | ||
}); | ||
|
||
it('trims leading & trailing newlines single lines', () => { | ||
const description = ` | ||
This is a custom button component. | ||
`; | ||
const generatedOverview = overviewToMarkdown(description).join('\n'); | ||
|
||
expect(generatedOverview).toBe(`## Overview | ||
This is a custom button component. | ||
`); | ||
}); | ||
}); | ||
}); |