collab/mermaid/docs/community/contributing.mdblame
View source
6dd74de1> **Warning**
6dd74de2>
6dd74de3> ## THIS IS AN AUTOGENERATED FILE. DO NOT EDIT.
6dd74de4>
6dd74de5> ## Please edit the corresponding file in [/packages/mermaid/src/docs/community/contributing.md](../../packages/mermaid/src/docs/community/contributing.md).
6dd74de6
6dd74de7# Mermaid Contributing Guide
6dd74de8
6dd74de9You decided to take part in the development? Welcome!
6dd74de10
6dd74de11We are trying to make our guidelines for you as explicit and detailed as possible.
6dd74de12
6dd74de13## Initial Setup
6dd74de14
6dd74de15Initial setup consists of 3 main steps:
6dd74de16
6dd74de17```mermaid
6dd74de18flowchart LR
6dd74de19 source --> requirements --> setup
6dd74de20
6dd74de21 source[Get the Source Code]
6dd74de22 requirements[Install the Requirements]
6dd74de23 setup[Install Packages]
6dd74de24```
6dd74de25
6dd74de26### Get the Source Code
6dd74de27
6dd74de28In GitHub, you first [**fork a mermaid repository**](https://github.com/mermaid-js/mermaid/fork) when you are going to make changes and submit pull requests.
6dd74de29
6dd74de30Then you **clone** a copy to your local development machine (e.g. where you code) to make a copy with all the files to work with.
6dd74de31
6dd74de32> **💡 Tip**
6dd74de33> [Here is a GitHub document that gives an overview of the process](https://docs.github.com/en/get-started/quickstart/fork-a-repo).
6dd74de34
6dd74de35```bash
6dd74de36git clone git@github.com/your-fork/mermaid
6dd74de37```
6dd74de38
6dd74de39Once you have cloned the repository onto your development machine, change into the `mermaid` project folder (the top level directory of the mermaid project repository)
6dd74de40
6dd74de41```bash
6dd74de42cd mermaid
6dd74de43```
6dd74de44
6dd74de45### Install Requirements
6dd74de46
6dd74de47We support **development within Docker** environment along with **host setup**. You may choose it up to your preferences.
6dd74de48
6dd74de49**Host**
6dd74de50
6dd74de51These are the tools we use for working with the code and documentation:
6dd74de52
6dd74de53- [Node.js](https://nodejs.org/en/).
6dd74de54- [pnpm](https://pnpm.io/) package manager.
6dd74de55
6dd74de56The following commands must be sufficient enough to start with:
6dd74de57
6dd74de58```bash
6dd74de59curl -fsSL https://get.pnpm.io/install.sh | sh -
6dd74de60pnpm env use --global 20
6dd74de61```
6dd74de62
6dd74de63You may also need to reload `.shrc` or `.bashrc` afterwards.
6dd74de64
6dd74de65**Docker**
6dd74de66
6dd74de67[Install Docker](https://docs.docker.com/engine/install/). And that is pretty much all you need.
6dd74de68
6dd74de69Optionally, to run GUI (Cypress) within Docker you will also need an X11 server installed.
6dd74de70You might already have it installed, so check this by running:
6dd74de71
6dd74de72```bash
6dd74de73echo $DISPLAY
6dd74de74```
6dd74de75
6dd74de76If the `$DISPLAY` variable is not empty, then an X11 server is running. Otherwise you may need to install one.
6dd74de77
6dd74de78### Install Packages
6dd74de79
6dd74de80**Host**
6dd74de81
6dd74de82Install packages:
6dd74de83
6dd74de84```bash
6dd74de85pnpm install
6dd74de86```
6dd74de87
6dd74de88**Docker**
6dd74de89
6dd74de90For development using Docker there is a self-documented `run` bash script, which provides convenient aliases for `docker compose` commands.
6dd74de91
6dd74de92Make sure that `./run` script is executable:
6dd74de93
6dd74de94```bash
6dd74de95chmod +x run
6dd74de96```
6dd74de97
6dd74de98> **💡 Tip**
6dd74de99> To get detailed help simply type `./run` or `./run help`.
6dd74de100>
6dd74de101> It also has short _Development quick start guide_ embedded.
6dd74de102
6dd74de103Then install packages:
6dd74de104
6dd74de105```bash
6dd74de106./run pnpm install
6dd74de107```
6dd74de108
6dd74de109### Verify Everything Works
6dd74de110
6dd74de111This step is optional, but it helps to make sure that everything in development branch was OK before you started making any changes.
6dd74de112
6dd74de113You can run the `test` script to verify that pnpm is working _and_ that the repository has been cloned correctly:
6dd74de114
6dd74de115**Host**
6dd74de116
6dd74de117```bash
6dd74de118pnpm test
6dd74de119```
6dd74de120
6dd74de121**Docker**
6dd74de122
6dd74de123```bash
6dd74de124./run pnpm test
6dd74de125```
6dd74de126
6dd74de127The `test` script and others are in the top-level `package.json` file.
6dd74de128
6dd74de129All tests should run successfully without any errors or failures.
6dd74de130
6dd74de131> **Note**
6dd74de132> You might see _lint_ or _formatting_ warnings. Those are ok during this step.
6dd74de133
6dd74de134## Workflow
6dd74de135
6dd74de136Contributing process is very simple and straightforward:
6dd74de137
6dd74de138```mermaid
6dd74de139 flowchart LR
6dd74de140
6dd74de141 branch --> changes --> submit
6dd74de142 branch[Checkout a New Branch]
6dd74de143 changes[Make Changes]
6dd74de144 submit[Submit a PR]
6dd74de145```
6dd74de146
6dd74de147Mermaid uses a [Git Flow](https://guides.github.com/introduction/flow/)–inspired approach to branching.
6dd74de148
6dd74de149Development is done in the `develop` branch.
6dd74de150
6dd74de151```mermaid
6dd74de152---
6dd74de153config:
6dd74de154 gitGraph:
6dd74de155 mainBranchName: develop
6dd74de156---
6dd74de157gitGraph LR:
6dd74de158 commit
6dd74de159 commit
6dd74de160 branch "docs/2910_update-guidelines" order: 1
6dd74de161 commit
6dd74de162 commit
6dd74de163 commit
6dd74de164 checkout develop
6dd74de165 merge "docs/2910_update-guidelines"
6dd74de166 commit
6dd74de167```
6dd74de168
6dd74de169To prepare a new version for release the maintainers create a `release/vX.X.X` branch from `develop` for testing. Once the release happens we add a tag to the `release` branch and merge it with `master`. The live product and on-line documentation are what is in the `master` branch.
6dd74de170
6dd74de171## Checkout a New Branch
6dd74de172
6dd74de173> **💡 Tip**
6dd74de174> All new work should be based on the `develop` branch.
6dd74de175
6dd74de176Make sure you have the most up-to-date version of the `develop` branch.
6dd74de177
6dd74de178Check out the `develop` branch, then `fetch` or `pull` to update it:
6dd74de179
6dd74de180```bash
6dd74de181git checkout develop
6dd74de182git fetch # or `git pull`
6dd74de183```
6dd74de184
6dd74de185Create a new branch for your work:
6dd74de186
6dd74de187```bash
6dd74de188git checkout -b docs/2910_update-contributing-guidelines
6dd74de189```
6dd74de190
6dd74de191We use the following naming convention for branches:
6dd74de192
6dd74de193```txt
6dd74de194[feature | bug | chore | docs]/[issue number]_[short-description]
6dd74de195```
6dd74de196
6dd74de197You can always check current [configuration of labelling and branch prefixes](https://github.com/mermaid-js/mermaid/blob/develop/.github/pr-labeler.yml)
6dd74de198
6dd74de199- The first part is the **type** of change: a `feature`, `bug`, `chore`, `docs`
6dd74de200- followed by a **slash** (`/`),which helps to group like types together in many git tools
6dd74de201- followed by the **issue number**, e.g. `2910`
6dd74de202- followed by an **underscore** (`_`)
6dd74de203- followed by a **short description** with dashes (`-`) or underscores (`_`) instead of spaces
6dd74de204
6dd74de205```mermaid
6dd74de206flowchart LR
6dd74de207 feature --> slash
6dd74de208 bug --> slash
6dd74de209 chore --> slash
6dd74de210 docs --> slash
6dd74de211 slash --> 2945 --> underscore
6dd74de212 slash --> 1123 --> underscore
6dd74de213 underscore --> short_description_1
6dd74de214 underscore --> short_description_2
6dd74de215
6dd74de216 underscore["_"]
6dd74de217 slash["/"]
6dd74de218
6dd74de219 short_description_1["state-diagram-new-arrow-florbs"]
6dd74de220 short_description_2["fix_random_ugly_red_text"]
6dd74de221```
6dd74de222
6dd74de223If your work is specific to a single diagram type, it is a good idea to put the diagram type at the start of the description. This will help us keep release notes organized by a diagram type.
6dd74de224
6dd74de225> **Note**
6dd74de226> A new feature described in issue 2945 that adds a new arrow type called 'florbs' to state diagrams
6dd74de227>
6dd74de228> `feature/2945_state-diagram-new-arrow-florbs`
6dd74de229
6dd74de230> **💡 Tip**
6dd74de231> A bug described in issue 1123 that causes random ugly red text in multiple diagram types
6dd74de232>
6dd74de233> `bug/1123_fix_random_ugly_red_text`
6dd74de234
6dd74de235## Contributing Code
6dd74de236
6dd74de237Code is the heart of every software project. We strive to make it better. Who if not us?
6dd74de238
6dd74de239### Where is the Code Located?
6dd74de240
6dd74de241The core of Mermaid is located under `packages/mermaid/src`.
6dd74de242
6dd74de243### Building Mermaid Locally
6dd74de244
6dd74de245**Host**
6dd74de246
6dd74de247```bash
6dd74de248pnpm run build
6dd74de249```
6dd74de250
6dd74de251**Docker**
6dd74de252
6dd74de253```bash
6dd74de254./run build
6dd74de255```
6dd74de256
6dd74de257This will build the Mermaid library and the documentation site.
6dd74de258
6dd74de259### Running Mermaid Locally
6dd74de260
6dd74de261**Host**
6dd74de262
6dd74de263```bash
6dd74de264pnpm run dev
6dd74de265```
6dd74de266
6dd74de267**Docker**
6dd74de268
6dd74de269```bash
6dd74de270./run dev
6dd74de271```
6dd74de272
6dd74de273After starting the dev server open <http://localhost:9000> in your browser.
6dd74de274
6dd74de275Now you are ready to make your changes!
6dd74de276
6dd74de277Note: By default, the Mermaid service will run on port 9000. To use a different port, change the environment variable `MERMAID_PORT` in the file `.env`. You should only need to do this if you are using port 9000 to run other projects.
6dd74de278
6dd74de279### Make Changes
6dd74de280
6dd74de281Have a look at <http://localhost:9000>. There is a list of demos that can be used to see and test your changes.
6dd74de282
6dd74de283If you need a specific diagram, you can duplicate the `example.html` file in `/demos/dev` and add your own mermaid code to your copy.
6dd74de284
6dd74de285That will be served at <http://localhost:9000/dev/your-file-name.html>.
6dd74de286After making code changes, the dev server will rebuild the mermaid library and automatically reload the page.
6dd74de287
6dd74de288Edit files in `packages/mermaid/src` as required.
6dd74de289
6dd74de290### Write Tests
6dd74de291
6dd74de292Tests ensure that each function, module, or part of code does what it says it will do. This is critically important when other changes are made to ensure that existing code is not broken (no regression).
6dd74de293
6dd74de294Just as important, the tests act as _specifications:_ they specify what the code does (or should do).
6dd74de295Whenever someone is new to a section of code, they should be able to read the tests to get a thorough understanding of what it does and why.
6dd74de296
6dd74de297If you are fixing a bug, you should add tests to ensure that your code has actually fixed the bug, to specify/describe what the code is doing, and to ensure the bug doesn't happen again.
6dd74de298(If there had been a test for the situation, the bug never would have happened in the first place.)
6dd74de299You may need to change existing tests if they were inaccurate.
6dd74de300
6dd74de301If you are adding a feature, you will definitely need to add tests. Depending on the size of your feature, you may need to add integration tests.
6dd74de302
6dd74de303#### Unit Tests
6dd74de304
6dd74de305Unit tests are tests that test a single function or module. They are the easiest to write and the fastest to run.
6dd74de306
6dd74de307Unit tests are mandatory for all code except the layout tests. (The layouts are tested with integration tests.)
6dd74de308
6dd74de309We use [Vitest](https://vitest.dev) to run unit tests.
6dd74de310
6dd74de311**Host**
6dd74de312
6dd74de313You can use the following command to run the unit tests:
6dd74de314
6dd74de315```sh
6dd74de316pnpm test
6dd74de317```
6dd74de318
6dd74de319When writing new tests, it's easier to have the tests automatically run as you make changes. You can do this by running the following command:
6dd74de320
6dd74de321```sh
6dd74de322pnpm test:watch
6dd74de323```
6dd74de324
6dd74de325**Docker**
6dd74de326
6dd74de327When using Docker prepend your command with `./run`:
6dd74de328
6dd74de329```sh
6dd74de330./run pnpm test
6dd74de331```
6dd74de332
6dd74de333##### Testing the DOM
6dd74de334
6dd74de335One can use `jsdomIt` to test any part of Mermaid that interacts with the DOM, as long as it is not related to the layout.
6dd74de336
6dd74de337The function `jsdomIt` ([developed in utils.ts](../../tests/util.ts)) overrides `it` from `vitest`, and creates a pseudo-browser environment that works almost like the real deal for the duration of the test. It uses JSDOM to create a DOM, and adds objects `window` and `document` to `global` to mock the browser environment.
6dd74de338
6dd74de339> \[!NOTE]
6dd74de340> The layout cannot work in `jsdomIt` tests because JSDOM has no rendering engine, hence the pseudo-browser environment.
6dd74de341
6dd74de342Example :
6dd74de343
6dd74de344```typescript
6dd74de345import { ensureNodeFromSelector, jsdomIt } from './tests/util.js';
6dd74de346
6dd74de347jsdomIt('should add element "thing" in the SVG', ({ svg }) => {
6dd74de348 // Code in this block runs in a pseudo-browser environment
6dd74de349 addThing(svg); // The svg item is the D3 selection of the SVG node
6dd74de350 const svgNode = ensureNodeFromSelector('svg'); // Retrieve the DOM node using the DOM API
6dd74de351 expect(svgNode.querySelector('thing')).not.toBeNull(); // Test the structure of the SVG
6dd74de352});
6dd74de353```
6dd74de354
6dd74de355They can be used to test any method that interacts with the DOM, including for testing renderers. For renderers, additional integration testing is necessary to test the layout though.
6dd74de356
6dd74de357#### Integration / End-to-End (E2E) Tests
6dd74de358
6dd74de359These test the rendering and visual appearance of the diagrams.
6dd74de360
6dd74de361This ensures that the rendering of that feature in the E2E will be reviewed in the release process going forward. Less chance that it breaks!
6dd74de362
6dd74de363To start working with the E2E tests:
6dd74de364
6dd74de365**Host**
6dd74de366
6dd74de367- Run `pnpm dev` to start the dev server
6dd74de368- Start **Cypress** by running `pnpm cypress:open`
6dd74de369
6dd74de370**Docker**
6dd74de371
6dd74de372- Enable local connections for x11 server `xhost +local:`
6dd74de373- Run `./run pnpm dev` to start the dev server
6dd74de374- Start **Cypress** by running `./run pnpm cypress:open --project .`
6dd74de375
6dd74de376The rendering tests are very straightforward to create. There is a function `imgSnapshotTest`, which takes a diagram in text form and the mermaid options, and it renders that diagram in Cypress.
6dd74de377
6dd74de378When running in CI it will take a snapshot of the rendered diagram and compare it with the snapshot from last build and flag it for review if it differs.
6dd74de379
6dd74de380This is what a rendering test looks like:
6dd74de381
6dd74de382```js
6dd74de383it('should render forks and joins', () => {
6dd74de384 imgSnapshotTest(
6dd74de385 `
6dd74de386 stateDiagram
6dd74de387 state fork_state &lt;&lt;fork&gt;&gt;
6dd74de388 [*] --> fork_state
6dd74de389 fork_state --> State2
6dd74de390 fork_state --> State3
6dd74de391
6dd74de392 state join_state &lt;&lt;join&gt;&gt;
6dd74de393 State2 --> join_state
6dd74de394 State3 --> join_state
6dd74de395 join_state --> State4
6dd74de396 State4 --> [*]
6dd74de397 `,
6dd74de398 { logLevel: 0 }
6dd74de399 );
6dd74de400});
6dd74de401```
6dd74de402
6dd74de403<!-- **_[TODO - running the tests against what is expected in development. ]_** -->
6dd74de404
6dd74de405<!-- **_[TODO - how to generate new screenshots]_** -->
6dd74de406
6dd74de407### Update Documentation
6dd74de408
6dd74de409> **💡 Tip**
6dd74de410> Our documentation is managed in `packages/mermaid/src/docs`. Details on how to edit is in the [documentation section](#contributing-documentation)
6dd74de411
6dd74de412If the users have no way to know that things have changed, then you haven't really _fixed_ anything for the users; you've just added to making Mermaid feel broken.
6dd74de413Likewise, if users don't know that there is a new feature that you've implemented, it will forever remain unknown and unused.
6dd74de414
6dd74de415The documentation has to be updated for users to know that things have been changed and added!
6dd74de416If you are adding a new feature, add `(v<MERMAID_RELEASE_VERSION>+)` in the title or description. It will be replaced automatically with the current version number when the release happens.
6dd74de417
6dd74de418eg: `# Feature Name (v<MERMAID_RELEASE_VERSION>+)`
6dd74de419
6dd74de420We know it can sometimes be hard to code _and_ write user documentation.
6dd74de421
6dd74de422Create another issue specifically for the documentation.
6dd74de423You will need to help with the PR, but definitely ask for help if you feel stuck.
6dd74de424When it feels hard to write stuff out, explaining it to someone and having that person ask you clarifying questions can often be 80% of the work!
6dd74de425
6dd74de426When in doubt, write up and submit what you can. It can be clarified and refined later. (With documentation, something is better than nothing!)
6dd74de427
6dd74de428## Contributing Documentation
6dd74de429
6dd74de430If it is not in the documentation, it's like it never happened. Wouldn't that be sad? With all the effort that was put into the feature?
6dd74de431
6dd74de432### Where is the Documentation Located?
6dd74de433
6dd74de434> **Warning**
6dd74de435> DO NOT CHANGE FILES IN `/docs`
6dd74de436>
6dd74de437> The `docs` folder will be automatically generated when committing to `packages/mermaid/src/docs` and **should not** be edited manually.
6dd74de438
6dd74de439Documentation is located in the [`packages/mermaid/src/docs`](https://github.com/mermaid-js/mermaid/tree/develop/packages/mermaid/src/docs) folder. Just pick the right section and start typing.
6dd74de440
6dd74de441The contents of [mermaid.js.org](https://mermaid.js.org/) are based on the docs from the `master` branch. Updates committed to the `master` branch are reflected in the [Mermaid Docs](https://mermaid.js.org/) once published.
6dd74de442
6dd74de443```mermaid-example
6dd74de444flowchart LR
6dd74de445 classDef default fill:#fff,color:black,stroke:black
6dd74de446
6dd74de447 source["Edit /packages/mermaid/src/docs"] -- automatic processing--> published["View /docs which will be published on Official Website"]
6dd74de448```
6dd74de449
6dd74de450```mermaid
6dd74de451flowchart LR
6dd74de452 classDef default fill:#fff,color:black,stroke:black
6dd74de453
6dd74de454 source["Edit /packages/mermaid/src/docs"] -- automatic processing--> published["View /docs which will be published on Official Website"]
6dd74de455```
6dd74de456
6dd74de457### Running the Documentation Website Locally
6dd74de458
6dd74de459**[The mermaid documentation site](https://mermaid.js.org/) is powered by [Vitepress](https://vitepress.vuejs.org/).**
6dd74de460
6dd74de461Start development server for the documentation site
6dd74de462
6dd74de463**Host**
6dd74de464
6dd74de465```bash
6dd74de466pnpm --filter mermaid run docs:dev
6dd74de467```
6dd74de468
6dd74de469or
6dd74de470
6dd74de471```bash
6dd74de472cd packages/mermaid
6dd74de473pnpm docs:dev
6dd74de474```
6dd74de475
6dd74de476**Docker**
6dd74de477
6dd74de478```bash
6dd74de479./run docs:dev
6dd74de480```
6dd74de481
6dd74de482Open <http://localhost:3333/> in your browser.
6dd74de483
6dd74de484### Formatting
6dd74de485
6dd74de486The documentation is written in Markdown. To get acquainted with its syntax [see the GitHub Markdown help page](https://help.github.com/en/github/writing-on-github/basic-writing-and-formatting-syntax).
6dd74de487
6dd74de488You can use `note`, `tip`, `warning` and `danger` in triple backticks to add a note, tip, warning or danger box.
6dd74de489
6dd74de490> **‼️ Danger**
6dd74de491> Do not use vitepress specific markdown syntax `::: warning` as it will not be processed correctly.
6dd74de492
6dd74de493Here are a few examples:
6dd74de494
6dd74de495````markdown
6dd74de496```note
6dd74de497This is a note
6dd74de498```
6dd74de499
6dd74de500```tip
6dd74de501This is a tip
6dd74de502```
6dd74de503
6dd74de504```warning
6dd74de505This is a warning
6dd74de506```
6dd74de507
6dd74de508```danger
6dd74de509This is a danger alert
6dd74de510```
6dd74de511````
6dd74de512
6dd74de513> **Note**
6dd74de514> This is a note
6dd74de515
6dd74de516> **💡 Tip**
6dd74de517> This is a tip
6dd74de518
6dd74de519> **Warning**
6dd74de520> This is a warning
6dd74de521
6dd74de522> **‼️ Danger**
6dd74de523> This is a danger alert
6dd74de524
6dd74de525### Navigation
6dd74de526
6dd74de527If you want to propose changes to how the documentation is _organized_, such as adding a new section or re-arranging or renaming a section, you must update the **sidebar navigation**, which is defined in [the vitepress config](../.vitepress/config.ts). The same goes for **topbar**.
6dd74de528
6dd74de529### Build Docs
6dd74de530
6dd74de531The content of `/docs` folder is built with GitHub Actions.
6dd74de532
6dd74de533> **Warning**
6dd74de534> So as to allow automatic compilation of documentation pages you have to enable GitHub Actions on your fork first
6dd74de535
6dd74de536## Submit your pull request
6dd74de537
6dd74de538> **Note**
6dd74de539> Do not forget to push your changes
6dd74de540>
6dd74de541> ```bash
6dd74de542> git push -u origin docs/2910_update-guidelines
6dd74de543> ```
6dd74de544
6dd74de545We make all changes via Pull Requests (PRs). Open a new one.
6dd74de546
6dd74de547Right now we are not following any strict rules about naming PRs. Give it a representative title and short description. There is also a [pull request template](https://github.com/mermaid-js/mermaid/blob/develop/.github/pull_request_template.md) which will help you with it.
6dd74de548
6dd74de549In case in its description contains a [magic comment](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue) your PR will be automatically attached to the issue:
6dd74de550
6dd74de551```markdown
6dd74de552Resolves #<your issue ID here>
6dd74de553```
6dd74de554
6dd74de555## Congratulations
6dd74de556
6dd74de557You have successfully submitted your improvements! What is next?
6dd74de558
6dd74de559- PRs will be reviewed by active maintainers, who will provide feedback and request changes as needed.
6dd74de560- The maintainers will request a review from _knsv_, if necessary.
6dd74de561- Once the PR is approved, the maintainers will merge the PR into the `develop` branch.
6dd74de562- When a release is ready, the `release/x.x.x` branch will be created, extensively tested and knsv will be in charge of the release process.
6dd74de563
6dd74de564Thanks for you help!
6dd74de565
6dd74de566<!--- cspell:ignore florbs --->