Files
o11y-components/apps/docs/utils/generateDocs.ts
Shaheer KochaiandGitHub adcb90f2c3 feat: component documentation in storybook (#60)
* feat: util for generating documentation based on component name and example usage

* feat: add documentation for button component

* feat: add documentation to input, pagination, and tooltip

* chore: minor copy change

* chore: remove unnecessary prop

* chore: add documentation to tabs component

* feat: add documentation to the remaining components

* feat: add support for generating documentation on adding a new package

* chore: format example code in badge and toggle group stories for better readability

* chore: update imports in code examples to use '@signozhq/icons' instead of 'lucide-react'
2025-06-16 11:03:17 +04:30

49 lines
1011 B
TypeScript

interface PackageDocConfig {
packageName: string;
description: string;
examples: string[];
installation?: {
npm?: boolean;
yarn?: boolean;
pnpm?: boolean;
};
}
export function generateDocs(config: PackageDocConfig): string {
const {
packageName,
description,
examples,
installation = { npm: true, yarn: true, pnpm: true },
} = config;
// Generate installation instructions
const installCommands: string[] = [];
if (installation.npm) installCommands.push(`npm install ${packageName}`);
if (installation.yarn) installCommands.push(`yarn add ${packageName}`);
if (installation.pnpm) installCommands.push(`pnpm add ${packageName}`);
const installationDocs = `
## Installation
${installCommands.map((cmd) => `\`\`\`bash\n${cmd}\n\`\`\``).join('\n\n')}
`;
// Generate usage examples
const usage = `
## Example usage
${examples.map((example) => `\`\`\`jsx\n${example}\n\`\`\``).join('\n\n')}
`;
// Combine all sections
return `
${description}
${installationDocs}
${usage}
`;
}