react-folder-generator
Version:
A CLI tool to generate React component folders with TypeScript/JavaScript and CSS/SCSS files with modular or scoped styling options
234 lines (163 loc) โข 4.71 kB
Markdown
<h1 align="center">๐ Component Generator CLI</h1>
<p align="center">A powerful Node.js CLI tool to scaffold React components with flexible architecture options.</p>
## โจ Features
- โ๏ธ Supports **JavaScript (.jsx)** and **TypeScript (.tsx)**
- ๐จ Multiple styling options: **CSS, SCSS, CSS Modules, SCSS Modules**
- ๐ก Scoped styling capability
- ๐ Configurable folder structure
- โ
Input validation and overwrite protection
## ๐ Prerequisites
### ๐ฅ System Requirements
- Node.js **โฅ16.0.0**
- npm **โฅ7.0.0** or **yarn**
### ๐ฆ Project Dependencies
| Feature | Required Packages |
|---------------|--------------------------------|
| TypeScript | `typescript`, `@types/react` |
| SCSS | `sass` |
| CSS Modules | Build tool configuration |
## ๐ Installation
```bash
npm install -g react-folder-generator
# or for project-specific
npm install react-folder-generator --save-dev
```
## ๐ Folder Structure Conventions
### ๐ Naming Patterns
**Kebab-case (Recommended)**
```
src/components/my-component/
โโโ index.tsx
โโโ index.module.scss
```
**PascalCase**
```
src/components/MyComponent/
โโโ MyComponent.tsx
โโโ MyComponent.module.scss
```
**Flat Structure**
```
src/components/
โโโ MyComponent.tsx
โโโ MyComponent.module.scss
```
## ๐ฏ Scoped vs Non-Scoped Styles
| Type | File Pattern | Usage Scenario |
|------------|---------------------|-------------------------|
| Scoped | `ComponentName.ext` | Component-specific |
| Non-Scoped | `index.ext` | Shared/global styles |
## ๐ What is Scoped Styling?
Scoped styling creates component-specific style files following naming patterns like:
๐ **File Naming**
- Component: `Button.tsx`
- Style: `Button.module.scss` (when using `--scoped-style`)
๐ฏ **Benefits**
- Prevents style leakage
- Explicit component-style association
- Better large-scale project organization
๐ก **Example**
```tsx
// Button.tsx
import styles from './Button.module.scss';
const Button = () => (
<button className={styles.root}>
Click me
</button>
);
```
```scss
// Button.module.scss
.root {
padding: 1rem 2rem;
background: blue;
&:hover {
background: darkblue;
}
}
```
## ๐ก Usage Options
### ๐ง Basic Command
```bash
react-folder-generator ComponentName [options]
```
### ๐งพ Option Matrix
| Option | File Pattern | Requires |
|------------------|---------------------|----------------------|
| `--ts` | `.tsx` | TypeScript |
| `--scss` | `.scss` | `sass` |
| `--module-scss` | `.module.scss` | CSS Modules config |
| `--scoped-style` | Component-named | - |
## ๐ Example Outputs
### โ
Standard Component
```bash
react-folder-generator sidebar --scss
```
```
components/
sidebar/
โโโ index.jsx
โโโ index.scss
```
### โ
Scoped TypeScript Module
```bash
react-folder-generator AuthForm --ts --module-scss --scoped-style
```
```
components/
auth-form/
โโโ AuthForm.tsx
โโโ AuthForm.module.scss
โโโ index.ts
```
## โ๏ธ Build System Config
### ๐ฆ Webpack CSS Modules Setup
```js
{
test: /\.module\.scss$/,
use: [
'style-loader',
{
loader: 'css-loader',
options: {
modules: {
localIdentName: '[name]__[local]--[hash:base64:5]'
}
}
},
'sass-loader'
]
}
```
## โ FAQ
### ๐ก When should I use scoped styles?
Recommended for:
- Large codebases
- Component libraries
- Teams with multiple developers
### ๐ก What's the difference between `index.scss` and `Component.module.scss`?
- `index.scss`: Global/shared styles
- `Component.module.scss`: Locally scoped styles for a component
## ๐จโ๐ป Author
**Afriduzzaman**
Senior Frontend Engineer
GitHub [@Thetourist2051](https://github.com/Thetourist2051) | Email [thetourist2051@gmail.com](mailto:thetourist2051@gmail.com)
## ๐ License
MIT ยฉ 2025 Afriduzzaman
> This README follows technical writing best practices for clarity, visual hierarchy, and developer usability.
<p align="center">
<img src="https://img.shields.io/npm/v/react-folder-generator?color=blue&style=flat-square" alt="npm version" />
</p>