This repository provides a Node.js CLI application that leverages OpenAI to automatically generate Storybook stories from your component code.
- Reads your component source code (TypeScript currently supported).
- Generates comprehensive stories.ts files for Storybook.
- Integrates with existing stories.ts files in the same directory for context.
- Offers robust error handling and informative messages.
- Prerequisites:
- Node.js and npm installed on your system (https://nodejs.org/)
-
Obtain OpenAI API Key:
-
Create an OpenAI account and access your API Keys (https://beta.openai.com/account/api-keys).
-
Create a
.env
file in the project root directory and add the following line, replacingYOUR_OPENAI_API_KEY
with your actual key:OPENAI_API_KEY=YOUR_OPENAI_API_KEY
-
-
Run the script:
Using npx (without installing globally):
npx github:AmazeeLabs/ai-stories-generator [path/to/your/component/ts]
Replace
path/to/your/component.ts
with the actual path to your component source code file (e.g.,example.ts
). -
(Optional) Install Globally:
Clone the repo and then:
npm install -g .
This allows you to run the script from anywhere using
ai-story-creator path/to/your/component.ts
.
The script generates a new stories.ts
file in the same directory as your component code file, containing the automatically generated Storybook stories.
The script reads existing .stories.ts
files in the same directory and provides snippets of the first 10 lines to OpenAI for context. This can help the model generate more consistent stories that align with existing behavior.
- The script currently supports TypeScript component code.
- Consider adding comments and descriptions to the generated stories.ts file for better maintainability.
We welcome contributions to this project! Please see the CONTRIBUTING.md file for guidelines.
This project is licensed under the MIT License (see LICENSE.md).