Skip to content

Commit

Permalink
docs(contributing): update guidelines for better clarity and structure
Browse files Browse the repository at this point in the history
- Reorganize the contribution guide for easier navigation and understanding.
- Add details on Alova's mission and design concept to inspire contributors.
- Provide clearer instructions for various contribution points like bug reports,
  feature proposals, pull requests, and translations.
- Improve the language and formatting throughout the document for better readability.
- Add a new section on project structure and coding standards for developers.
- Update the development guidelines with the latest tools and recommendations.
- Encourage contributors to get involved in community discussions and reviews.
- Emphasize the importance of testing and document updates in the development process.
- Clarify the steps for becoming a core team member and the version requirements.
  • Loading branch information
JOU-amjs committed Jul 24, 2024
1 parent a5ecf6c commit de004d0
Show file tree
Hide file tree
Showing 23 changed files with 173 additions and 1,706 deletions.
137 changes: 72 additions & 65 deletions docs/contributing/01-overview.md

Large diffs are not rendered by default.

141 changes: 62 additions & 79 deletions docs/contributing/03-developing-guidelines.md
Original file line number Diff line number Diff line change
@@ -1,137 +1,120 @@
---
title: Developing Guidelines
title: Development Guidelines
---

:::info version required
:::info Version requirements

Node.js 16+, npm 8+
Node.js 18+, pnpm 9+

:::

## 1. Fork repository

[Open alova fork page](https://github.com/alovajs/alova/fork), click "Create fork" and clone the forked repository to local.
[Open the alova repository fork page](https://github.com/alovajs/alova/fork), click "Create fork" to fork the repository, and clone the forked repository to your local machine.

## 2. Clone to local
## 2. Clone the project to your local machine

Use the `git clone` command line, or the `Github Desktop` application to clone forked project.
Use the `git clone` command, or the `Github Desktop` application to clone the project.

## 3. New pull request
## 3. Create a pull request

You can [create pull request through a forked repo](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request-from-a-fork) after writing code. You can also commit code in arbitrary batches, without commiting a complete code.
You can create a pull request by forking the repository after writing the code, or you can submit the code in any number of commits instead of submitting the entire code at once.

## 4. Code something in your computer
## 4. Code locally

### Install dependencies

Install dependencies using `npm install`.
Use `pnpm install` to install dependencies.

### Install the recommended plugin(vscode)
### Install recommended plugins (vscode)

If you are using vscode, it is recommended that you install the following plugins:
If you use vscode, you will be recommended to install the following plugins:

- eslint: check code quality.
- prettier: formatting code.
- jest: Automatically execute unit test cases, and execute individual collection or unit test cases.
- EditorConfig: Make sure the file format is consistent.
- eslint: Check code quality

### Project Structure
- prettier: Format code

- jest: Automatically execute unit test cases, and execute a single collection or unit test case

- EditorConfig: Ensure consistent file format

### Project structure

alova is a monorepo project with the following structure:

```
|-.github
| |-ISSUE_TEMPLATE -> github issues template
| |-workflows -> github action
| |-DISCUSSION_TEMPLATE -> github discussion template
| |-pull_request_template -> github pull request template
|-.changeset -> changeset configuration
|-.husky -> husky configuration
|-.vscode -> vscode configuration
|-config -> rollup package files
|-src -> source code
|-test -> unit test suits
| |-browser -> browser environment unit test suits
| |-server -> SSR unit test suits
| |-components -> Unit test components
| |-mockServer.ts -> mock apis (msw)
|-typings -> ts declaration
|- Other configuration files
|-examples -> alova example project
|-internal -> Public module for test cases
|-packages -> Project source code
|-scripts -> alova-scripts scripts
|-Other configuration files
```

### Coding specifications
### Coding standards

#### Code format

If you install the `prettier` plugin, it will automatically format codes every time you save files, so you don't have to worry about the format.
Please install the recommended plugins. `prettier` and `eslint` will automatically format the code every time you save the file, so you don't have to worry about the format.

#### Minimize code
#### Reuse code as much as possible

Lightweight is one of the alova's features, so it is necessary to minimize the amount of coding when coding. Here are a few coding specifications that need to be followed:
Public variables and methods are defined in `packages/shared`. Please browse them first and reuse them as much as possible.

1. Avoid the same code block, which can reduce the amount of code in the library, but two lines of code may not be worth encapsulating;
2. Use a variable declarator to aggregate variable declarations, for example:
#### Typescript

```javascript
//
const a = 1;
const b = 2;
1. When writing typescript types, please try to write appropriate types and narrow the type range.

//
const a = 1,
b = 2;
```
2. The types of `packages/alova` and `packages/client` packages are manually written. When modifying them, please make sure that `typings` of `packages/alova` and `packages/client` are also updated synchronously.

3. Use constants to save js built-in values and prototype methods to reduce the amount of code in the compilation phase of `uglify`. built-in values and prototype methods that often used are defined in `src/utils/variables.ts`.

```javascript
//
if (a === false) {
//...
}
arr.forEach(item => {
//...
});

//
import { falseValue, forEach } from '@/utils/variables';
if (a === falseValue) {
//...
}
forEach(arr, item => {
//...
});
```
## 5. Unit test guide

## 5. Unit Testing Guidelines
After writing the code, add the corresponding unit test cases and try to include tests for edge cases.

After finish code, it is necessary to add corresponding unit tests.
The alova project uses jest as the unit testing framework and msw as the mock server. It is recommended to use the TDD mode. After each code modification, run the corresponding unit test and pass it.

The alova project uses **jest** as the unit test framework, and msw as the mock server. It is recommended to use the TDD mode. After modifying code every time, please pass the corresponding unit test.
:::warning Important

:::warning IMPORTANT

When you're ready to commit your code, make sure all your unit tests are passed. When you're working on a pull request, you can have multiple small commits, and GitHub can automatically squash them before merging them.
When you create a pull request to submit code, please make sure that all unit tests pass. If you find any problems, you can submit it again, and the GitHub action will automatically run again.

:::

1. To add browser-related unit test cases, please add them to the corresponding test collection in `test/browser`, if there is no suitable test suits, you can create one by yourself;
2. Add SSR-related unit test cases, please add them to the corresponding test collection in `test/server`, if there is no suitable test suits, you can create one by yourself;
### Add test cases

Unit test cases for each package are stored in the `packages/[packageName]/test` folder. Please find the corresponding test case file and add your test case. If there is no suitable test collection, you can create it yourself;

### Run and debug a single test case or collection

It is recommended to use the **jest** plug-in (one of the plug-ins recommended above) to test a single test case or collection. You can right-click in the test case to run the specified test case, select `Run Test` to run this test case, and select `Debug Test` to debug this test case, as shown in the figure:

![image](/img/run-single-test.png)

### Run and debug a single unit test or suits
### Run all test cases

It is recommended to use the **jest** plugin (one of the plugins recommended above) to test a single use case or a suit. You can right-click the specified unit test, select `Run Test` to run it, and select `Debug Test` to debug it with breakpoint.
1. Use the **jest** plug-in to run, as shown below:

![image](https://github.com/alovajs/alova/assets/29848971/a94ba9db-c100-472f-b870-6bcecb031bea)
![image](/img/run-all-test.png)

### Run all unit tests
2. You can also run unit tests through the command line `pnpm run test`

1. Use the **jest** plugin to run:
## 6. Submit code

![image](https://github.com/alovajs/alova/assets/29848971/5af3ff15-16b7-4b28-9ae6-d0b5a236b181)
alova uses [changesets](https://github.com/changesets/changesets) as a release tool, which can help us automatically generate `CHANGELOG` to increase the version number and release, but you need to submit the code according to the following process.

2. Run the browser unit tests with command line `npm run test:browser`, run the SSR unit tests with `npm run test:node`, and run both at the same time with `npm run test`.
1. Tell changeset which packages have been changed. Use the `pnpm run changeset` command, which will guide you to fill it out in an interactive way.

## 6. Commit codes
2. Submit the code to the remote repository. You need to make sure that the message format of the submission follows the [Commit Information Convention](https://www.conventionalcommits.org/zh-hans/v1.0.0/). It is recommended that you try to use `pnpm run commit` to automatically generate a git message that meets the specification.

alova uses [semantic-release](https://semantic-release.gitbook.io) as an automatic release tool, which can automatically release new version packages after merging code into `main` , and generate `CHANGELOG`, but you need to ensure that the committed message format follows [commit information convention](https://www.conventionalcommits.org/en/v1.0.0/), it is recommended that use `npm run commit` to automatically generate a git message that conforms to the specification.
3. Create a pull request and wait for merging.

## 7. Writing docs
## 7. Add documents

If you are adding a new feature, you can try to add the relevant documentation of the new feature. For details, please read [Correcting or add docs](/contributing/overview#correct-or-add-docs), otherwise please explain it in the pull request.
If you are adding new features, try to add relevant documentation for the new features. Please read [Correct or add docs](/contributing/overview#correct-or-add-docs) for details. Otherwise, please explain it in the pull request.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ title: 贡献指南

alova 的使命为它指出了明确的发展方向,它清晰地定义了 alova 什么应该做。

alova 是一个轻量级的请求策略库**它的使命就是让开发者在编写少量代码的同时,也能实现更高效地 Client-Server 数据交互**
alova 是一个以全 JS 环境可运行的,请求策略为主要方向的请求工具,主要帮助开发者极致地减少 API 的消费流程,提升效率,我们认为这是下一代请求工具的方向**它的使命就是让开发者在编写少量代码的同时,也能实现更高效地 Client-Server 数据交互**

对于开发者来说,alova 为他们提供了简单的 api 和开箱即用的高级请求功能,以及各种简单的、高性能的请求策略模块,对于应用的用户来说,它们可以享受到 alova 的高性能数据交互带来的流畅体验,因此,alova 具备了以下特性:

Expand All @@ -54,8 +54,8 @@ alova 是一个轻量级的请求策略库,**它的使命就是让开发者在
设计理念指出了它应该如何设计,以下为 alova 的核心设计理念。

1. Method 代理设计,高聚合、平台无关的设计,贯穿请求始终,你在任意请求函数中都应该可以访问到它,从另一个角度说,与请求相关的信息也应该被放在 method 实例中;
2. 轻量级,在编码中尽量保持源码简洁,例如避免重复代码、合并变量声明、原型链函数封装、无相似 api、tree shaking,但长变量名是被允许的,因为在编译时它将会被单个字母替代;
3. 高扩展性设计,其一,alova 的设计中大量使用了适配器模式和钩子函数,例如适配器有`requestAdapter``storageAdapter`等,钩子函数有`beforeRequest``reseponded``transform``cacheFor`等,而且大多存在默认行为,这样设计的目的是为了在保留高扩展性的同时,使用也足够简单;其二,全局请求参数可覆盖,例如`timeout``shareRequest`等,对于特别的请求可单独设置这些参数。
2. state 代理设计,这是我们实现 UI 框架无关的关键技术,它可以让 alova 的 useHooks 在不同 UI 框架中运行,因此在编写 useHooks 时请使用 state 代理;
3. 高扩展性设计,其一,alova 的设计中大量使用了适配器模式和钩子函数,例如适配器有`requestAdapter``l1Cache/l2Cache`等,钩子函数有`beforeRequest``reseponded``transform``cacheFor`等,而且大多存在默认行为,这样设计的目的是为了在保留高扩展性的同时,使用也足够简单;其二,全局请求参数可覆盖,例如`timeout``shareRequest`等,对于特别的请求可单独设置这些参数。
4. api 设计具有普适性,其一,它表示此 api 的功能具有较高的抽象层级,而不是针对某一个具体业务而提出的;其二,api 设计具有可扩展性,以适应 api 的迭代

> api 普适性设计仅适用于 alova 库,如果你正在构思一个请求策略,那么可以根据具体业务来设计。
Expand Down Expand Up @@ -118,13 +118,13 @@ alova 提供了高扩展特性,你可以基于它编写自己的 js 库。
自定义各类适配器以满足不同环境下的运行要求,以下几个方向可供参考:

1. 自定义 statesHook,满足在不同 UI 框架下执行,例如`solid/qwik`,目前内置支持`react/vue/svelte`,请阅读[自定义 statesHook](/tutorial/advanced/custom/stateshook)
2. 自定义请求适配器,让 alova 可以与更多请求方案协作,例如`GraphQL/SSE`等;
3. 自定义存储适配器,满足不同环境的存储,例如`react-native`
4. 以上任意的组合,例如官方的[uniapp 适配器](https://github.com/alovajs/adapter-uniapp),其中包含了请求适配器、存储适配器。
2. 自定义请求适配器,让 alova 可以与更多请求方案协作,例如`GraphQL/SSE`,请阅读[自定义请求适配器](/tutorial/advanced/custom/http-adapter)
3. 自定义存储适配器,满足不同环境的存储,例如`react-native`,请阅读[自定义存储适配器](/tutorial/advanced/custom/storage-adapter)
4. 以上任意的组合,例如官方的[uniapp 适配器](https://github.com/alovajs/alova/tree/main/packages/adapter-uniapp),其中包含了请求适配器、存储适配器。

#### 自定义请求策略

请求策略可以帮助开发者更高效地编写出高性能功能,虽然官方的 [alova/scene](/tutorial/client/strategy) 提供了一些常用的请求策略,但还不足以满足广大开发者各种请求相关的业务场景,基于 alova 自定义你自己的可复用请求策略是一个不错的选择,也可以将它们发布到 npm 上给大家使用。
请求策略可以帮助开发者更高效地编写出高性能功能,虽然官方的 [alova/client](/tutorial/client/strategy) [alova/server](/tutorial/server/strategy)提供了一些常用的请求策略,但还不足以满足广大开发者各种请求相关的业务场景,基于 alova 自定义你自己的可复用请求策略是一个不错的选择,也可以将它们发布到 npm 上给大家使用,请阅读[自定义客户端策略](/tutorial/advanced/custom/client-strategy)[自定义服务端策略](/tutorial/advanced/custom/server-strategy)

:::tip 提交你的项目

Expand All @@ -134,7 +134,7 @@ alova 提供了高扩展特性,你可以基于它编写自己的 js 库。

### 参与社区交流/PR review

如果你对技术交流感兴趣,那么参与更多的社区交流可能更适合你,你可以在 Github issues 中参与 bug 和新特性的讨论,也可以在[Github Disscussion](https://github.com/alovajs/alova/discussions)中、[Discord](https://discord.gg/S47QGJgkVb)[QQ 频道](https://pd.qq.com/s/1cdjx0nnw)中为别人解答问题,这可以让你与世界各地的人交流,是一件很有趣的事情。
如果你对技术交流感兴趣,那么参与更多的社区交流可能更适合你,你可以在 Github issues 中参与 bug 和新特性的讨论,也可以在[Github Disscussion](https://github.com/alovajs/alova/discussions)中、[Discord](https://discord.gg/S47QGJgkVb)[微信群聊](/img/wechat_qrcode.jpg)中为别人解答问题,这可以让你与世界各地的人交流,是一件很有趣的事情。

同时,你也可以在[pull request](https://github.com/alovajs/alova/pulls)中参与 PR review,这也是一种交流的主题。

Expand All @@ -158,7 +158,7 @@ alova 提供了高扩展特性,你可以基于它编写自己的 js 库。

您可以在以下三个渠道为项目捐赠,捐赠特权说明请进入捐赠页面查看。

1. [Github sponsors](https://github.com/alovajs)
1. [Github sponsors](https://github.com/sponsors/alovajs)
2. [OpenCollective](https://opencollective.com/alova)
3. [afdian](https://afdian.net/a/huzhen555)

Expand Down
Loading

0 comments on commit de004d0

Please sign in to comment.