Library Usage
import { componentsToMarkdown } from 'components-to-markdown';
async function componentsToMarkdown(options: ConfigOptions);
ConfigOptions
sources
string[]
Source directories for the React components.
patterns
string[]
[
'**/*.{js,jsx,ts,tsx}',
'!**/__tests__/**',
'!**/*.{test,spec}.{js,jsx,ts,tsx}',
'!**/*.d.ts',
];
A glob pattern to filter the files in sources
.
output
string;
Path to output markdown files.
template
BuiltinTemplate | string;
'brachiosaurus';
Path to template file or the name of the built-in template.
watch
boolean;
false;
Whether to watch the files for changes and regenerate.
loglevel
LogLevel;
'info';
Log level. See LogLevel for more information.
grouped
boolean;
false;
Components in the same file will be grouped in the same output file.
outputExtension
string;
'md';
Extension of output files.
hooks
ConfigHook;
Functions to customize the result. See ConfigHook for more information.
helpers
TemplateHelper;
[];
Custom template helpers. See TemplateHelper for more information.
BuiltinTemplate
type BuiltinTemplate = 'brachiosaurus' | 'stegosaurus';
LogLevel
type LogLevel = 'silent' | 'error' | 'warn' | 'info' | 'debug' | 'trace';
Priority | Level | Description |
---|---|---|
0 | silent | No logs will be displayed |
1 | error | Critical errors |
2 | warn | Alerts about possible issues |
3 | info | Default log information |
4 | debug | Details about file processing |
5 | trace | Detailed information for each step |
ConfigHook
outputFileName
(fileName: string, fileExtension: string) => string;
Used to format the name of output files.
function outputFileName(fileName, fileExtension) {
return `${fileName}.${fileExtension}`;
}
It is possible to define directories to be concatenated with output dir. For example:
const groups = {
Button: 'Inputs',
Select: 'Inputs',
Alert: 'Feedback',
Snackbar: 'Feedback',
};
/**
* Result:
* "Inputs/Button.md"
* "Inputs/Select.md"
* "Feedback/Alert.md"
* "Feedback/Snackbar.md"
*/
function outputFileName(fileName, fileExtension) {
return `${groups[filename]}/${fileName}.${fileExtension}`;
}
moduleName
(filePath: string, metadata: ModuleNameMetadata) => string;
Used to extract the module name. This function will populate the ComponentData.name property.
This name will be use as the output file name if grouped is true
.
import { parse } from 'path';
function moduleName(filePath) {
return parse(filePath).name;
}
TemplateHelper
import type { HelperDelegate } from 'handlebars';
interface TemplateHelper {
name: string;
helper: HelperDelegate;
}