tachybase_todo/docs/guide/contributing.md

184 lines
4.1 KiB
Markdown
Raw Normal View History

2021-10-29 13:05:21 +08:00
---
order: 100
toc: menu
---
# Contributing
## Basic process
2021-10-31 09:44:52 +08:00
- Fork the source code to your own repository
- Modify source code
- Submit pull request
2021-10-29 13:05:21 +08:00
2021-10-29 14:49:04 +08:00
## Installation and start-up
2021-10-29 13:05:21 +08:00
```bash
2021-10-31 09:44:52 +08:00
# Replace the following git address with your own repo
2021-10-29 13:05:21 +08:00
git clone https://github.com/nocobase/nocobase.git
cd nocobase
cp .env.example .env
yarn install
yarn bootstrap
yarn build
yarn nocobase init --import-demo
yarn start
```
2021-10-31 09:44:52 +08:00
Open http://localhost:8000/ in your browser
2021-10-29 14:49:04 +08:00
2021-10-31 09:44:52 +08:00
<Alert title="Note">
Involved in core code development, the project starts with a documentation page, not the application's login page.
2021-10-29 14:49:04 +08:00
</Alert>
## Main scripts
### Startup and reboot
2021-10-31 09:44:52 +08:00
The above commands are only executed the first time, after that the project is restarted with
2021-10-29 14:49:04 +08:00
```bash
yarn start
```
### Reinstallation
2021-10-31 09:44:52 +08:00
If you want to clear and reinstall
2021-10-29 14:49:04 +08:00
```bash
2021-10-31 09:44:52 +08:00
### If you want to import demo data, you can add --import-demo
2021-10-29 14:49:04 +08:00
yarn nocobase init --import-demo
2021-10-31 09:44:52 +08:00
# After reinstallation, you also need to restart
2021-10-29 14:49:04 +08:00
yarn start
```
### Build
2021-10-29 13:05:21 +08:00
2021-10-31 09:44:52 +08:00
<Alert title="Note">
2021-10-29 13:05:21 +08:00
2021-10-31 09:44:52 +08:00
For integration testing or site-wide debugging, the following package changes need to be recompiled and repackaged.
2021-10-29 13:05:21 +08:00
- actions
- database
- resourcer
- server
- test
- utils
2021-10-31 09:44:52 +08:00
In addition to the compilation issues, there are many details of the project build that remain unresolved. If you have some good suggestions, you are welcome to discuss them on [GitHub Discussions](https://github.com/nocobase/nocobase/discussions).
2021-10-29 13:05:21 +08:00
</Alert>
```bash
# for all packages
yarn build
# for specific package
yarn build <package_name_1> <package_name_2>
# e.g.
# yarn build database
```
2021-10-29 14:49:04 +08:00
### Testing
2021-10-29 13:05:21 +08:00
2021-10-31 09:44:52 +08:00
<Alert title="Note">
2021-10-29 13:05:21 +08:00
2021-10-31 09:44:52 +08:00
After upgrading v0.5, some tests have not been fixed yet, and the ci tests are not available yet. The code tests are not perfect yet, more tests will be added and improved in phases...
2021-10-29 13:05:21 +08:00
</Alert>
```bash
# For all packages
yarn test
# For specific package
yarn test packages/<name>
```
2021-10-29 14:49:04 +08:00
### More scripts
2021-10-31 09:44:52 +08:00
View [scripts](https://github.com/nocobase/nocobase/blob/ff4d432c9fc3faa38cd65ab6d4dad250da02c2fd/package.json#L7) of package.json
2021-10-29 14:49:04 +08:00
2021-10-29 13:05:21 +08:00
## Document revision and translation
2021-10-31 09:44:52 +08:00
The documentation is in the [docs](https://github.com/nocobase/nocobase/tree/develop/docs) directory and follows Markdown syntax, defaults to English and ends with `.zh-CN.md` in Chinese, e.g.
2021-10-29 13:05:21 +08:00
```bash
|- /docs/
2021-10-31 09:44:52 +08:00
|- index.md # English document
|- index.zh-CN.md # Chinese document, when it is missing, the content of index.md is displayed
2021-10-29 13:05:21 +08:00
```
2021-10-31 09:44:52 +08:00
After modification, open http://localhost:8000/ in your browser to see the final effect.
2021-10-29 13:05:21 +08:00
## Back-end
2021-10-31 09:44:52 +08:00
Most of the changes on the back-end can be verified by the test command.
2021-10-29 13:05:21 +08:00
```bash
yarn test packages/<name>
```
2021-10-31 09:44:52 +08:00
Of course, if you are adding new content, you will need to write new tests. ``@nocobase/test`` provides ``mockDatabase`` and ``mockServer` for database and server testing, e.g.
2021-10-29 13:05:21 +08:00
```ts
import { mockServer, MockServer } from '@nocobase/test';
describe('mock server', () => {
let api: MockServer;
beforeEach(() => {
api = mockServer({
dataWrapping: false,
});
api.actions({
list: async (ctx, next) => {
ctx.body = [1, 2];
await next();
},
});
api.resource({
name: 'test',
});
});
afterEach(async () => {
return api.destroy();
});
it('agent.get', async () => {
const response = await api.agent().get('/test');
expect(response.body).toEqual([1, 2]);
});
it('agent.resource', async () => {
const response = await api.agent().resource('test').list();
expect(response.body).toEqual([1, 2]);
});
});
```
## Full-stack demo
2021-10-29 13:55:49 +08:00
http://localhost:8000/develop
2021-10-29 13:05:21 +08:00
2021-10-31 09:44:52 +08:00
To facilitate local debugging for developers, the full-stack demo is also an embedded demo, which can be opened full-screen by clicking on the new tab in the bottom left corner.
2021-10-29 13:05:21 +08:00
## Client components
2021-10-31 09:44:52 +08:00
<Alert title="Note">
The component library is still being organized...
2021-10-29 13:05:21 +08:00
</Alert>
2021-10-31 09:44:52 +08:00
Each component is independent, easy to debug and use. See the component list at http://localhost:8000/components
2021-10-29 13:05:21 +08:00
## Provide more examples
2021-10-31 09:44:52 +08:00
<Alert title="Note">
Examples are still being compiled...
2021-10-29 13:05:21 +08:00
</Alert>
2021-10-31 09:44:52 +08:00
Examples are available at http://localhost:8000/examples
2021-10-29 13:05:21 +08:00