-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Components: Warn private API in auto-generated readmes
- Loading branch information
Showing
5 changed files
with
54 additions
and
3 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
bin/api-docs/gen-components-docs/get-tags-from-storybook.mjs
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,30 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import fs from 'node:fs/promises'; | ||
import babel from '@babel/core'; | ||
|
||
/** | ||
* Returns `meta.tags` from a Storybook file. | ||
* | ||
* @param {string} filePath | ||
* @return {Promise<string[]>} Array of tags. | ||
*/ | ||
export async function getTagsFromStorybook( filePath ) { | ||
const fileContent = await fs.readFile( filePath, 'utf8' ); | ||
const parsedFile = babel.parse( fileContent, { | ||
filename: filePath, | ||
} ); | ||
|
||
const meta = parsedFile.program.body.find( | ||
( node ) => | ||
node.type === 'VariableDeclaration' && | ||
node.declarations[ 0 ].id.name === 'meta' | ||
); | ||
|
||
return ( | ||
meta.declarations[ 0 ].init.properties | ||
.find( ( node ) => node.key.name === 'tags' ) | ||
?.value.elements.map( ( node ) => node.value ) ?? [] | ||
); | ||
} |
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
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