Skip to content

Commit 4365e1e

Browse files
committed
feat: add React Component Generator Guide with usage instructions and prompts explanation
1 parent c0ab0b8 commit 4365e1e

File tree

3 files changed

+63
-2
lines changed

3 files changed

+63
-2
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
- uses: actions/setup-node@v4
1717
with:
1818
node-version: 20
19-
- run: npm i -g pnpm && pnpm i
19+
- run: npm i -g pnpm && pnpm i --no-frozen-lockfile
2020
name: Install dependencies
2121
- name: Run unit tests
2222
run: pnpm test

README.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,32 @@ Compared to the default scaffold from create-turbo, this template offers:
7272
- GitHub actions/workflows to auto-publish your package when the version changes
7373
- GitHub action/workflow + pre-install scripts to automatically rebrand your repo on creation
7474

75-
### 🤩 Don't forget to star [this repository](https://github.com/react18-tools/turborepo-template)!
75+
## 🧱 Generate New Components
76+
77+
This project uses [`plop`](https://plopjs.com/) to scaffold reusable React components under the `lib` or `packages/shared` directory.
78+
79+
To generate a new component, run:
80+
81+
```bash
82+
pnpm plop
83+
```
84+
85+
You’ll be prompted to choose:
86+
87+
- The **target package** (`lib` or `packages/shared`)
88+
- The **component name** (e.g., `Card`, or nested like `forms/Input`)
89+
- Whether it’s a **client component** (adds `"use client"` directive)
90+
- Whether to include a **`.module.scss` file**
91+
- Whether to generate a **test stub**
92+
- An optional **description** (used as JSDoc)
93+
94+
🧠 The generator:
95+
96+
- Creates a folder with `.tsx`, optional `.module.scss`, and `.test.tsx`
97+
- Updates `index.ts` files recursively
98+
- Adds `exports` to `package.json` automatically
99+
100+
## 🤩 Don't forget to star [this repository](https://github.com/react18-tools/turborepo-template)!
76101

77102
Looking for a hands-on course to get started with Turborepo? Check out [React and Next.js with TypeScript](https://mayank-chaudhari.vercel.app/courses/react-and-next-js-with-typescript) and [The Game of Chess with Next.js, React, and TypeScript](https://www.udemy.com/course/game-of-chess-with-nextjs-react-and-typescript/?referralCode=851A28F10B254A8523FE)
78103

component-generator.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# 🧱 React Component Generator Guide
2+
3+
This generator helps you scaffold components consistently.
4+
5+
### Usage
6+
7+
```bash
8+
pnpm plop rc
9+
```
10+
11+
### Prompts Explained
12+
13+
| Prompt | Description |
14+
| --------------------- | ----------------------------------------------- |
15+
| Package Path | Target package to add the component to |
16+
| Component Name | Supports nested paths like `form/InputText` |
17+
| Is Client Component | Adds `"use client"` directive |
18+
| Create .module.scss | Adds a scoped SCSS module |
19+
| Create Unit Test File | Adds a Jest + React Testing Library stub |
20+
| Description | Added to the top of the component file as JSDoc |
21+
22+
### Example Output
23+
24+
For a component named `form/InputText`, files generated:
25+
26+
```
27+
lib/src/client/form/input-text/
28+
├── input-text.tsx
29+
├── input-text.module.scss
30+
├── input-text.test.tsx
31+
└── index.ts <-- export file
32+
```
33+
34+
Nested `index.ts` files are created as needed, and exports are appended.
35+
36+
The generator also modifies your `package.json` to expose these components.

0 commit comments

Comments
 (0)