UNPKG

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
# 🐦 Budgie React > A flexible, interactive React project initializer β€” TypeScript by default, batteries included. [![npm version](https://img.shields.io/npm/v/budgie-react.svg)](https://www.npmjs.com/package/budgie-react) [![Node >=14](https://img.shields.io/badge/node-%3E%3D14-brightgreen)](https://nodejs.org) [![License: ISC](https://img.shields.io/badge/License-ISC-blue.svg)](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)