Skip to content

Commit 9c2d362

Browse files
committed
docs: add contributing
1 parent c5f8946 commit 9c2d362

4 files changed

Lines changed: 693 additions & 0 deletions

File tree

CONTRIBUTING.md

Lines changed: 343 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,343 @@
1+
# Contributing Guide
2+
3+
Thank you for your interest in contributing to `vite-plugin-mock-dev-server`! This document provides guidelines and instructions to help you get started.
4+
5+
English | [简体中文](./CONTRIBUTING.zh-CN.md)
6+
7+
## Table of Contents
8+
9+
- [Code of Conduct](#code-of-conduct)
10+
- [Getting Started](#getting-started)
11+
- [Prerequisites](#prerequisites)
12+
- [Repository Setup](#repository-setup)
13+
- [Development Workflow](#development-workflow)
14+
- [Project Structure](#project-structure)
15+
- [Development Commands](#development-commands)
16+
- [Running Tests](#running-tests)
17+
- [Debugging](#debugging)
18+
- [Coding Guidelines](#coding-guidelines)
19+
- [Code Style](#code-style)
20+
- [TypeScript Guidelines](#typescript-guidelines)
21+
- [JSDoc Documentation](#jsdoc-documentation)
22+
- [Commit Convention](#commit-convention)
23+
- [Pull Request Process](#pull-request-process)
24+
- [Release Process](#release-process)
25+
26+
## Code of Conduct
27+
28+
This project adheres to the [Contributor Covenant Code of Conduct](./CODE_OF_CONDUCT.md). By participating, you are expected to uphold this code.
29+
30+
## Getting Started
31+
32+
### Prerequisites
33+
34+
- **Node.js**: Version `^20 || >=22`
35+
- **pnpm**: Version `>=10.30.1` (this project uses pnpm workspaces)
36+
- **Git**: For version control
37+
38+
### Repository Setup
39+
40+
1. **Fork the repository**
41+
42+
Click the "Fork" button on the GitHub repository page to create your own fork.
43+
44+
2. **Clone your fork**
45+
46+
```bash
47+
git clone https://github.com/YOUR_USERNAME/vite-plugin-mock-dev-server.git
48+
cd vite-plugin-mock-dev-server
49+
```
50+
51+
3. **Install dependencies**
52+
53+
```bash
54+
pnpm install
55+
```
56+
57+
4. **Verify setup**
58+
59+
```bash
60+
# Run linting
61+
pnpm lint
62+
63+
# Run tests
64+
pnpm test
65+
```
66+
67+
## Development Workflow
68+
69+
### Project Structure
70+
71+
This is a monorepo managed by pnpm workspaces:
72+
73+
```txt
74+
vite-plugin-mock-dev-server/
75+
├── vite-plugin-mock-dev-server/ # Core plugin package
76+
│ ├── src/ # Source code
77+
│ │ ├── build/ # Standalone mock server build
78+
│ │ ├── compiler/ # Mock file compiler (esbuild/rolldown)
79+
│ │ ├── cookies/ # Cookie handling
80+
│ │ ├── core/ # Core plugin logic
81+
│ │ ├── helpers/ # Helper functions
82+
│ │ ├── mockHttp/ # HTTP mock middleware
83+
│ │ ├── mockWebsocket/ # WebSocket mock support
84+
│ │ ├── types/ # TypeScript type definitions
85+
│ │ └── utils/ # Utility functions
86+
│ ├── __tests__/ # Unit tests
87+
│ └── package.json
88+
├── docs/ # VitePress documentation site
89+
├── example/ # Example project for testing
90+
├── package.json # Root package.json
91+
└── pnpm-workspace.yaml # pnpm workspace configuration
92+
```
93+
94+
### Development Commands
95+
96+
```bash
97+
# Build the plugin
98+
pnpm build
99+
100+
# Start development mode with example project
101+
pnpm dev
102+
103+
# Build example project
104+
pnpm example:build
105+
106+
# Run documentation site in development mode
107+
pnpm docs:dev
108+
109+
# Build documentation site
110+
pnpm docs:build
111+
112+
# Run linting
113+
pnpm lint
114+
115+
# Run tests
116+
pnpm test
117+
118+
# Run tests in watch mode
119+
pnpm test --watch
120+
```
121+
122+
### Running Tests
123+
124+
The project uses [Vitest](https://vitest.dev/) for testing.
125+
126+
```bash
127+
# Run all tests
128+
pnpm test
129+
130+
# Run tests with coverage
131+
pnpm test --coverage
132+
133+
# Run tests in watch mode (useful during development)
134+
pnpm test --watch
135+
136+
# Run specific test file
137+
pnpm test src/__tests__/compiler.spec.ts
138+
```
139+
140+
### Debugging
141+
142+
To debug the plugin during development:
143+
144+
1. **Using the example project**
145+
146+
The `example/` directory contains a test project that uses the plugin:
147+
148+
```bash
149+
pnpm dev
150+
```
151+
152+
This starts the example Vite project with the plugin loaded.
153+
154+
2. **Adding debug logs**
155+
156+
The project uses the `debug` package. Enable debug logs:
157+
158+
```bash
159+
DEBUG=vite-plugin-mock-dev-server pnpm dev
160+
```
161+
162+
3. **VS Code debugging**
163+
164+
Create a `.vscode/launch.json` file:
165+
166+
```json
167+
{
168+
"version": "0.2.0",
169+
"configurations": [
170+
{
171+
"type": "node",
172+
"request": "launch",
173+
"name": "Debug Example",
174+
"runtimeExecutable": "pnpm",
175+
"runtimeArgs": ["dev"],
176+
"cwd": "${workspaceFolder}",
177+
"console": "integratedTerminal"
178+
}
179+
]
180+
}
181+
```
182+
183+
## Coding Guidelines
184+
185+
### Code Style
186+
187+
This project uses ESLint with `@pengzhanbo/eslint-config` for code linting.
188+
189+
```bash
190+
# Check code style
191+
pnpm lint
192+
193+
# Auto-fix linting issues
194+
pnpm lint -- --fix
195+
```
196+
197+
Key style rules:
198+
199+
- Use single quotes for strings
200+
- No trailing semicolons
201+
- 2 spaces indentation
202+
- Maximum line length: 120 characters
203+
204+
### TypeScript Guidelines
205+
206+
- **Strict mode enabled**: All code must be type-safe
207+
- **Explicit return types**: Public APIs should have explicit return type annotations
208+
- **No `any`**: Avoid using `any` type; use `unknown` with type guards when necessary
209+
210+
### JSDoc Documentation
211+
212+
All public APIs must include JSDoc comments in the following format:
213+
214+
```typescript
215+
/**
216+
* English description
217+
*
218+
* 中文描述
219+
*
220+
* @param paramName - English description / 中文描述
221+
* @returns English description / 中文描述
222+
* @example
223+
*/
224+
```
225+
226+
Example:
227+
228+
```typescript
229+
/**
230+
* Define mock data that can be shared across multiple mock files
231+
*
232+
* 定义可在多个 mock 文件间共享的 mock 数据
233+
*
234+
* @param key - Unique identifier for the data / 数据的唯一标识符
235+
* @param initialData - Initial value of the data / 数据的初始值
236+
* @returns A mock data object with getter, setter, and value properties / 包含 getter、setter 和 value 属性的 mock 数据对象
237+
* @example
238+
* ```ts
239+
* export default defineMockData('posts', [])
240+
* ```
241+
*/
242+
export function defineMockData<T>(key: string, initialData: T): MockData<T>
243+
```
244+
245+
## Commit Convention
246+
247+
We follow the [Angular Commit Convention](./.github/commit-convention.md). Each commit message should follow this format:
248+
249+
```txt
250+
<type>(<scope>): <subject>
251+
```
252+
253+
Types:
254+
255+
- `feat`: New feature
256+
- `fix`: Bug fix
257+
- `docs`: Documentation changes
258+
- `style`: Code style changes (formatting, semicolons, etc.)
259+
- `refactor`: Code refactoring
260+
- `perf`: Performance improvements
261+
- `test`: Adding or updating tests
262+
- `build`: Build system changes
263+
- `ci`: CI/CD changes
264+
- `chore`: Other changes
265+
266+
Examples:
267+
268+
```txt
269+
feat(compiler): add support for json5 files
270+
fix(http): resolve cookie parsing issue
271+
docs: update API documentation
272+
```
273+
274+
## Pull Request Process
275+
276+
1. **Create a branch**
277+
278+
```bash
279+
git checkout -b feat/your-feature-name
280+
# or
281+
git checkout -b fix/your-bug-fix
282+
```
283+
284+
2. **Make your changes**
285+
286+
- Write clear, concise code
287+
- Add tests for new features
288+
- Update documentation if needed
289+
- Ensure all tests pass
290+
291+
3. **Commit your changes**
292+
293+
```bash
294+
git add .
295+
git commit -m "feat(scope): your commit message"
296+
```
297+
298+
4. **Push to your fork**
299+
300+
```bash
301+
git push origin feat/your-feature-name
302+
```
303+
304+
5. **Create a Pull Request**
305+
306+
- Go to the original repository on GitHub
307+
- Click "New Pull Request"
308+
- Select your fork and branch
309+
- Fill in the PR template with:
310+
- Clear description of changes
311+
- Related issue numbers (if any)
312+
- Screenshots (if UI changes)
313+
314+
6. **PR Review**
315+
316+
- Maintainers will review your PR
317+
- Address any requested changes
318+
- Once approved, your PR will be merged
319+
320+
## Release Process
321+
322+
> **Note**: Only maintainers can perform releases.
323+
324+
The project uses [bumpp](https://github.com/antfu/bumpp) for version management and [conventional-changelog](https://github.com/conventional-changelog/conventional-changelog) for changelog generation.
325+
326+
```bash
327+
# Bump version, generate changelog, commit, tag, and push
328+
pnpm release
329+
330+
# Publish to npm
331+
pnpm release:publish
332+
```
333+
334+
---
335+
336+
## Questions?
337+
338+
If you have any questions or need help, feel free to:
339+
340+
- Open an [issue](https://github.com/pengzhanbo/vite-plugin-mock-dev-server/issues)
341+
- Start a [discussion](https://github.com/pengzhanbo/vite-plugin-mock-dev-server/discussions)
342+
343+
Thank you for contributing! 🎉

0 commit comments

Comments
 (0)