UNPKG

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
<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>