budgie-react
Version:
π¦ Flexible React project initializer β TypeScript, Redux Toolkit, React Router v6, Error Boundaries, Axios and more.
214 lines (162 loc) β’ 7.16 kB
Markdown
# π¦ Budgie React
> A flexible, interactive React project initializer β TypeScript by default, batteries included.
[](https://www.npmjs.com/package/budgie-react)
[](https://nodejs.org)
[](https://opensource.org/licenses/ISC)
## Quick Start
```bash
# Run interactively via npx (no install needed)
npx budgie-react my-app
# Or install globally once
npm install -g budgie-react
budgie-react my-app
```
You'll be guided through an interactive CLI to pick exactly what you need.
## What It Does
Budgie React scaffolds a fully configured React project in seconds. After answering a few prompts, you get a production-ready boilerplate with only the features you actually want.
```
? Project description (optional):
? Author name (optional):
? Select features to include:
βββββ¬ββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β # β Feature β Description β
βββββΌββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β 1 β Redux Toolkit β State management with @reduxjs/toolkit + react-redux β
β 2 β React Router v6 β Client-side routing with react-router-dom β
β 3 β Error Boundaries β Global error boundary component + fallback UI β
β 4 β Axios HTTP Client β Pre-configured Axios instance with interceptors β
β 5 β Environment Config β .env.development / .env.production + dotenv-webpack β
β 6 β ESLint + Prettier β Airbnb TypeScript rules + auto-format on save β
β 7 β Jest + Testing Libraryβ Unit test setup with @testing-library/react β
βββββ΄ββββββββββββββββββββββββ΄ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
> 1,2,3,5 β comma-separated numbers, "all", or Enter to skip
```
## Features
| Feature | Always included |
|---|---|
| β‘ Webpack 5 + HMR | β
|
| π· TypeScript (strict) | β
|
| π·οΈ Path aliases (`@/*`, `@components/*`, β¦) | β
|
| π¨ CSS Modules-ready | β
|
| π¦ Vendor code-splitting | β
|
| Feature | Optional |
|---|---|
| ποΈ Redux Toolkit + typed hooks | `--redux` |
| π§ React Router v6 (lazy pages) | `--routing` |
| π‘οΈ Error Boundary + fallback UI | `--error-boundary` |
| π Axios + interceptors | `--axios` |
| π dotenv-webpack env config | `--env-config` |
| π― ESLint (Airbnb TS) + Prettier | `--eslint` |
| π§ͺ Jest + Testing Library | `--jest` |
## Generated Project Structure
```
my-app/
βββ public/
β βββ index.html
βββ src/
β βββ index.tsx β entry point (wires up Provider, BrowserRouter, etc.)
β βββ App.tsx
β βββ styles/
β β βββ globals.css
β βββ store/ β (Redux) configureStore + RootState types
β β βββ index.ts
β β βββ rootReducer.ts
β βββ features/ β (Redux) slices
β β βββ counter/
β β βββ counterSlice.ts
β βββ hooks/ β (Redux) useAppDispatch + useAppSelector
β β βββ index.ts
β βββ routes/ β (Router) AppRoutes + lazy page loading
β β βββ index.tsx
β βββ pages/ β (Router) Home, About, NotFound
β βββ components/ β (Error Boundary) ErrorBoundary, ErrorFallback
β βββ services/ β (Axios) api.ts + types.ts
β βββ __tests__/ β (Jest) App.test.tsx
βββ webpack.config.js
βββ tsconfig.json
βββ .babelrc
βββ .eslintrc.js β (ESLint)
βββ .prettierrc β (Prettier)
βββ jest.config.js β (Jest)
βββ .env.development β (Env Config)
βββ .env.production
βββ package.json
```
## Available Scripts (in generated project)
| Script | What it does |
|---|---|
| `npm run dev` | Start dev server on `localhost:3000` with HMR |
| `npm run build` | Production build (minified, content-hashed) |
| `npm run type-check` | Run TypeScript compiler check (no emit) |
| `npm run lint` | Run ESLint on `src/` |
| `npm run lint:fix` | Auto-fix ESLint errors |
| `npm run format` | Format code with Prettier |
| `npm test` | Run Jest test suite |
| `npm run test:watch` | Jest in watch mode |
| `npm run test:coverage` | Jest with coverage report |
## TypeScript Path Aliases
The following path aliases work out of the box in both webpack and TypeScript:
```ts
import { useAppSelector } from '@hooks';
import HomePage from '@pages/Home';
import api from '@services/api';
import { store } from '@store';
```
## Redux Usage
Typed hooks are pre-wired so you never need to cast manually:
```tsx
import { useAppSelector, useAppDispatch } from '@hooks';
import { increment, incrementByAmount } from '@features/counter/counterSlice';
const Counter = () => {
const count = useAppSelector((state) => state.counter.value);
const dispatch = useAppDispatch();
return (
<div>
<span>{count}</span>
<button onClick={() => dispatch(increment())}>+1</button>
<button onClick={() => dispatch(incrementByAmount(5))}>+5</button>
</div>
);
};
```
Add new slices under `src/features/` and register them in `src/store/rootReducer.ts`.
## Axios Usage
The Axios instance reads `REACT_APP_API_URL` from your env file and attaches `Authorization` headers automatically:
```ts
import api from '@services/api';
// GET
const { data } = await api.get<User[]>('/users');
// POST
const { data: newUser } = await api.post<User>('/users', { name: 'Alice' });
```
## Error Boundary Usage
`ErrorBoundary` is wired at the root in `src/index.tsx`. You can also nest it around individual components:
```tsx
import ErrorBoundary from '@components/ErrorBoundary';
<ErrorBoundary
fallback={(error, reset) => (
<div>
<p>{error.message}</p>
<button onClick={reset}>Retry</button>
</div>
)}
onError={(err, info) => logToSentry(err, info)}
>
<RiskyComponent />
</ErrorBoundary>
```
## Powered by budgie-console π¦
The CLI output is styled using [`budgie-console`](https://www.npmjs.com/package/budgie-console) β colored logs, spinners, progress bars, and bordered tables, all with zero dependencies.
## License
ISC Β© [Yash Datir](https://github.com/yashdatir)