UNPKG

refunjs

Version:

Modern React-based framework for building scalable web applications with enhanced developer experience

246 lines (175 loc) โ€ข 5.4 kB
# RefunJS ๐Ÿš€ Quick start for React applications with TypeScript, file-based routing, and modern development tools. ## Features - โšก **Quick Start** โ€” ready-to-use React + TypeScript with minimal configuration - ๐ŸŽฏ **File-based Routing** โ€” automatic routing based on the `pages/` folder structure - ๐ŸŽจ **CSS Modules** โ€” isolated styles with CSS variables and dark theme support - ๐Ÿ“ฆ **Pre-installed Libraries** โ€” React Query, Zustand, React Router included - ๐Ÿ”ง **TypeScript** โ€” full TypeScript support with pre-configuration - ๐Ÿš€ **Vite** โ€” blazingly fast dev server and optimized build - ๐ŸŒ **i18n (optional)** โ€” multi-language support - ๐Ÿงช **Tests (optional)** โ€” Jest with testing configuration ## Quick Start Create a new project with a single command: ```bash npx refunjs my-app cd my-app npm run dev ``` ## Usage ### Creating a Project ```bash npx refunjs <project-name> ``` During project creation, you can select additional features: - **Tests (Jest)** โ€” configuration for unit testing - **i18n** โ€” localization support ### CLI Commands #### `create` Creates a new project with base structure. ```bash npx refunjs create my-app # or simply npx refunjs my-app ``` #### `add-page` Adds a new page with proper file structure. ```bash # Simple page npx refunjs add-page about # Nested page npx refunjs add-page blog/article # Dynamic route (use escape characters to properly generate pages) npx refunjs add-page blog/\[id\] ``` Creates: - `src/pages/<name>/index.tsx` โ€” React page component - `src/pages/<name>/<name>.module.css` โ€” CSS module **Note:** page names should be in kebab-case format (e.g., `my-page`, `user-profile`) #### `add-component` Adds a new component. ```bash npx refunjs add-component Button ``` Creates: - `src/components/<ComponentName>/<ComponentName>.tsx` - `src/components/<ComponentName>/<ComponentName>.module.css` **Note:** component names should be in PascalCase format (e.g., `UserCard`, `NavBar`) #### `help` Shows help for available commands. ```bash npx refunjs help ``` ## Project Structure ``` my-app/ โ”œโ”€โ”€ src/ โ”‚ โ”œโ”€โ”€ .refunjs/ # Framework system files โ”‚ โ”œโ”€โ”€ components/ # Reusable components โ”‚ โ”‚ โ”œโ”€โ”€ Button/ โ”‚ โ”‚ โ”œโ”€โ”€ Card/ โ”‚ โ”‚ โ””โ”€โ”€ Header/ โ”‚ โ”œโ”€โ”€ pages/ # File-based routing โ”‚ โ”‚ โ””โ”€โ”€ index.tsx # Home page (/) โ”‚ โ”œโ”€โ”€ hooks/ # Custom React hooks โ”‚ โ”œโ”€โ”€ utils/ # Helper functions โ”‚ โ”œโ”€โ”€ styles/ # Global styles โ”‚ โ”œโ”€โ”€ App.tsx # Main application component โ”‚ โ””โ”€โ”€ main.tsx # Entry point โ”œโ”€โ”€ public/ # Static files โ”œโ”€โ”€ package.json โ”œโ”€โ”€ tsconfig.json โ””โ”€โ”€ vite.config.ts ``` ## File-based Routing The `pages/` folder structure is automatically converted to routes: ``` src/pages/ โ”œโ”€โ”€ index.tsx โ†’ / โ”œโ”€โ”€ about/ โ”‚ โ””โ”€โ”€ index.tsx โ†’ /about โ”œโ”€โ”€ blog/ โ”‚ โ”œโ”€โ”€ index.tsx โ†’ /blog โ”‚ โ””โ”€โ”€ [id]/ โ”‚ โ””โ”€โ”€ index.tsx โ†’ /blog/:id โ””โ”€โ”€ users/ โ””โ”€โ”€ [userId]/ โ””โ”€โ”€ profile/ โ””โ”€โ”€ index.tsx โ†’ /users/:userId/profile ``` ## Available Scripts After creating a project, the following commands are available: ```bash npm run dev # Start dev server npm run build # Build for production npm run preview # Preview production build npm run lint # Check code with ESLint npm run format # Format code with Prettier npm run test # Run tests (if selected during creation) ``` ## Technologies - **React** โ€” library for building UI - **TypeScript** โ€” JavaScript with types - **Vite** โ€” build tool - **React Router** โ€” routing - **React Query** โ€” server state management - **Zustand** โ€” client state management - **CSS Modules** โ€” modular styles - **ESLint** โ€” code linting - **Prettier** โ€” code formatting ### Optional Features - **Jest** โ€” testing framework - **i18next** โ€” internationalization ## Usage Examples ### Creating a Simple Page ```bash npx refunjs add-page contact ``` Generated file `src/pages/contact/index.tsx`: ```tsx import React from "react"; import styles from "./contact.module.css"; const Contact = () => { return <h1>Contact</h1>; }; export default Contact; ``` ### Creating a Component ```bash npx refunjs add-component UserCard ``` Generated file `src/components/UserCard/UserCard.tsx`: ```tsx import React from "react"; import styles from "./UserCard.module.css"; const UserCard = () => { return <div>UserCard</div>; }; export default UserCard; ``` ## Localization (i18n) If you selected the i18n feature during project creation: ```typescript import { useTranslation } from "react-i18next"; const MyComponent = () => { const { t } = useTranslation(); return <h1>{t("home.title")}</h1>; }; ``` Translation files are located in `src/locales/`: - `src/locales/en.json` - `src/locales/uk.json` ## Testing If you selected the Tests feature during project creation: ```bash npm run test ``` Example test: ```typescript import { render, screen } from "@testing-library/react"; import HomePage from "./HomePage"; test("renders home page", () => { render(<HomePage />); expect(screen.getByText(/Build React applications/i)).toBeInTheDocument(); }); ```