refunjs
Version:
Modern React-based framework for building scalable web applications with enhanced developer experience
246 lines (175 loc) โข 5.4 kB
Markdown
# 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();
});
```