react-basic-component-generator
v0.0.2
Published
a set of commands to generate a basic structure for react components
Downloads
11
Maintainers
Readme
React Component Generator
A powerful CLI tool to generate React components with support for both CSS Modules and Styled Components. This generator helps streamline your React development workflow by creating consistent, well-structured component files.
Features
- 🚀 Generate React components with a single command
- 🎨 Support for both CSS Modules and Styled Components
- 📁 Creates organized folder structure
- 📝 TypeScript-ready templates
- 🔧 Customizable template system
- 🛠️ Includes utility functions file
- ✅ Consistent code style across components
Installation
Global Installation (Recommended)
npm install -g react-component-generatorLocal Installation
npm install --save-dev react-component-generatorUsage
Basic Usage
# Generate component with CSS Modules (default)
generate-component ComponentName
# Generate component with Styled Components
generate-component ComponentName styledUsing with npx
# Without installing
npx react-component-generator ComponentName
# With Styled Components
npx react-component-generator ComponentName styledLocal Installation Usage
If installed locally, add a script to your package.json:
{
"scripts": {
"generate": "generate-component"
}
}Then run:
npm run generate ComponentNameGenerated Structure
With CSS Modules (Default)
components/
└── ComponentName/
├── index.tsx
├── styles.module.css
└── functions.tsWith Styled Components
components/
└── ComponentName/
├── index.tsx
├── styles.tsx
└── functions.tsTemplates
CSS Modules Template
index.tsx
import styles from "./styles.module.css";
import { HelloWorld } from "./functions";
export const ComponentName = () => {
return (
<div className={styles.container}>
<HelloWorld />
</div>
);
};styles.module.css
.container {
display: flex;
justify-items: center;
align-items: center;
}functions.ts
export const HelloWorld: string = () => {
return "Hello World";
};Styled Components Template
index.tsx
import React from "react";
import { ComponentName } from "./styles";
export function ComponentName() {
return <ComponentName></ComponentName>;
}styles.tsx
import styled from "styled-components";
export const ComponentName = styled.div`
flex: 1;
display: flex;
justify-content: center;
align-items: center;
`;Customization
You can customize the templates by modifying the files in the templates directory:
- Clone the repository
- Modify the template files in the
templatesfolder - Install your customized version globally
API Reference
Command Line Options
generate-component <ComponentName> [styled]
Arguments:
ComponentName Name of the component to generate (PascalCase recommended)
styled Optional flag to use Styled Components instead of CSS ModulesContributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the project
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Development
To set up the development environment:
- Clone the repository
git clone https://github.com/stsmuniz/react-component-generator.git
cd react-component-generator- Install dependencies
npm install- Link for local development
npm linkTesting
To test the generator:
# Test CSS Modules generation
node generate-component.js TestComponent
# Test Styled Components generation
node generate-component.js TestComponent styled
# Test error handling
node generate-component.jsLicense
This project is licensed under the GPLv3 License - see the LICENSE file for details.
Author
Salustiano Muniz
- GitHub: @stsmuniz
- Repository: https://github.com/stsmuniz/react-component-generator
Support
If you encounter any issues or have questions, please file an issue on the GitHub issue tracker.
Changelog
v1.0.0
- Initial release
- Support for CSS Modules and Styled Components
- Basic template structure
- Command-line interface
Roadmap
- [ ] Add TypeScript types generation
- [ ] Support for different testing frameworks (Jest, Testing Library)
- [ ] Option to generate storybook stories
- [ ] Custom template path configuration
- [ ] Interactive mode with prompts
Acknowledgments
- Inspired by the need for consistent component structure in React projects
- Thanks to the React community for best practices and patterns
