@sarawebs/sb-bin
Version:
CLI tools for SaraWebs dev workflow
107 lines (75 loc) โข 2.75 kB
Markdown
# ๐งฑ `sb-gen` โ Simple Boilerplate Code Generator
A developer-friendly CLI utility to quickly scaffold React boilerplate files in your project structure.
Easily generate components, hooks, tests, pages, and context files using intuitive commands.
## ๐ Features
- ๐ง Generate React components with boilerplate
- ๐ช Create custom hooks with sensible defaults
- ๐งช Add test files for your components
- ๐ Scaffold page files for routing
- ๐ง Create React context providers and hooks
- โจ Supports multiple entries per type in a single command
- ๐ Automatically places files in the correct `src/` subfolders
## ๐ Folder Structure
```bash
src/
โโโ assets/ # images, logos, etc.
โโโ components/ # reusable components (Navbar, ProductCard, etc.)
โโโ context/ # global state with React context
โโโ hooks/ # custom React hooks
โโโ pages/ # main views like Home, Cart, Shop
โโโ tests/ # unit tests
```
## ๐ Installation
Install globally using npm:
```bash
npm install -g @sarawebs/sb-bin
```
This will make the `sb-gen` command available globally from your terminal.
## ๐ป Usage
```bash
sb-gen [flags] [names...]
```
### โ
Supported Flags
| Flag | Alias | Description | Target Directory |
| ------------- | ----- | -------------------------------- | ----------------- |
| `--component` | `-c` | Create React components | `src/components/` |
| `--hook` | `-h` | Create custom React hooks | `src/hooks/` |
| `--test` | `-t` | Create test files | `src/tests/` |
| `--page` | `-p` | Create React pages | `src/pages/` |
| `--context` | `-x` | Create React context boilerplate | `src/context/` |
## โจ Examples
```bash
sb-gen -c Navbar Footer -h auth fetchUser -t Navbar -p Home Shop -x Cart
```
๐ฆ This creates:
```
src/components/Navbar.jsx
src/components/Footer.jsx
src/hooks/useAuth.jsx
src/hooks/useFetchUser.jsx
src/tests/Navbar.test.jsx
src/pages/Home.jsx
src/pages/Shop.jsx
src/context/CartContext.jsx
```
## ๐ Boilerplate Overview
- **Component:** Functional React component
- **Hook:** Custom `useX` hook
- **Test:** React Testing Library setup
- **Page:** Basic functional component
- **Context:** Provider + custom hook for usage
## ๐ Notes
- Component and context names are automatically capitalized.
- Hook names are prefixed with `use` if not already.
- All files use `.jsx` extension.
- Works best inside a standard React app using the described folder structure.
## ๐งฉ License
MIT โ Feel free to use, modify, and contribute.