|
2 | 2 | title: "Contributing" |
3 | 3 | description: "Introduction to developing OpenMarch" |
4 | 4 | sidebar: |
5 | | - order: -1 |
| 5 | + order: -1 |
6 | 6 | --- |
7 | 7 |
|
8 | | -import { LinkCard } from '@astrojs/starlight/components'; |
| 8 | +import { LinkCard } from "@astrojs/starlight/components"; |
| 9 | +import { Steps } from "@astrojs/starlight/components"; |
9 | 10 |
|
10 | 11 | Get in here and contribute to OpenMarch! Learn our stack and codebase here. |
11 | 12 |
|
12 | 13 | We'd reccommend to take a look at all of our [tasks](https://github.com/OpenMarch/OpenMarch/issues), and pick some you'd like to work on. The ones with `good first issue` and `help wanted` tags are good for getting started. |
13 | 14 |
|
14 | 15 | Feel free to ask questions in the Discord if you're having problems with anything. |
15 | 16 |
|
16 | | -<LinkCard |
17 | | - title="Stack" |
18 | | - href="/developers/stack/" |
19 | | -/> |
| 17 | +<LinkCard title="Stack" href="/developers/stack/" /> |
20 | 18 | <LinkCard |
21 | 19 | title="Discord" |
22 | 20 | href="https://discord.com/invite/eTsQ98uZzq" |
23 | 21 | description="Go to #developers for support!" |
24 | 22 | /> |
25 | 23 |
|
26 | | -## Running the Dev Environment |
| 24 | +## Running the Dev Environment |
| 25 | + |
| 26 | +<Steps> |
27 | 27 |
|
28 | 28 | 1. Download & install [Node.js](https://nodejs.org/en) |
29 | 29 | 2. Download the code via git from the main branch (if you're contributing, [make a fork](https://github.com/OpenMarch/OpenMarch/fork) and clone your own repo): `git clone https://github.com/OpenMarch/OpenMarch.git` |
30 | | - - You might need to download git for this. You can also use other methods like the GitHub CLI |
| 30 | + - You might need to download git for this. You can also use other methods like the GitHub CLI |
31 | 31 | 3. Install dependencies: `npm install` (may take a while) |
32 | | - - You might get a bunch of scary npm errors after installing. If running the app doesn't work after, follow [these steps](https://github.com/Automattic/node-canvas?tab=readme-ov-file#compiling) to fix it. |
| 32 | + - You might get a bunch of scary npm errors after installing. If running the app doesn't work after, follow [these steps](https://github.com/Automattic/node-canvas?tab=readme-ov-file#compiling) to fix it. |
33 | 33 | 4. Run the dev environment: `npm run dev` |
| 34 | + - If you see a bunch of errors, you may need to run `npm run app:prepare` first. More on this in the [running tests](#running-tests) section |
| 35 | + |
| 36 | +</Steps> |
34 | 37 |
|
35 | 38 | ## Codebase Structure |
36 | 39 |
|
37 | 40 | Our simplified directory structure: |
38 | 41 |
|
39 | 42 | - `/electron` - The "main" process, the backend of the app, with database and system functionality |
40 | | - - /database |
41 | | - - /main |
42 | | - - /preload - Preload script for IPC |
| 43 | + - /database |
| 44 | + - /main |
| 45 | + - /preload - Preload script for IPC |
43 | 46 | - `/src` - the "renderer" process, this is our react frontend. |
44 | | - - `/components` - In here you find all the components of OpenMarch, the sidebars, titlebar, dialogs, UI component primitives. All of them are in their subfolder. |
45 | | - - `/context` - React Context for the app of some sort of state/value |
46 | | - - `/global` - Classes, objects and functions for various items in the app, such as Page, Marcher, MarcherShape, etc. |
47 | | - - `/stores` - Global stores for certain items and actions, such as the list of Pages and Marchers |
48 | | - - `App.tsx` - the main app file |
| 47 | + - `/components` - In here you find all the components of OpenMarch, the sidebars, titlebar, dialogs, UI component primitives. All of them are in their subfolder. |
| 48 | + - `/context` - React Context for the app of some sort of state/value |
| 49 | + - `/global` - Classes, objects and functions for various items in the app, such as Page, Marcher, MarcherShape, etc. |
| 50 | + - `/stores` - Global stores for certain items and actions, such as the list of Pages and Marchers |
| 51 | + - `App.tsx` - the main app file |
49 | 52 |
|
50 | 53 | Most of the directories like `stores`, `context`, `database` also have a `__test__` directory. These are [Vitest](https://vitest.dev/) or [Playwright](https://playwright.dev/) tests, which test the functionalites of certain things. Tests are important, please write them! |
| 54 | + |
| 55 | +## Running Tests |
| 56 | + |
| 57 | +Since Electron has to rebuild `better-sqlite3` (the package used to interact with the database), we must follow a few steps when transitioning between running automated tests and running the app. |
| 58 | + |
| 59 | +### Prepare for testing |
| 60 | + |
| 61 | +These steps only apply for tests involving database interactions. |
| 62 | +You don't need to rebuild any packages if you're only testing frontend components. |
| 63 | +If you don't, though, the entire test suite will not pass. |
| 64 | + |
| 65 | +> For frontend specific tests, ignore the steps below and just run `npm run test`. |
| 66 | +> |
| 67 | +> Using the `Vitest` extension in VSCode is also handy. |
| 68 | +
|
| 69 | +<Steps> |
| 70 | + |
| 71 | +1. Close the app if it's running |
| 72 | +1. Rebuild the `better-sqlite3` package |
| 73 | + |
| 74 | + ```bash |
| 75 | + npm run test:prepare |
| 76 | + ``` |
| 77 | + |
| 78 | + - This will rebuild `better-sqlite3` to run on the same version of Node.js that the rest of the packages are on |
| 79 | + |
| 80 | +1. If the tests didn't start, run them again |
| 81 | + |
| 82 | + ```bash |
| 83 | + npm run test |
| 84 | + ``` |
| 85 | + |
| 86 | +1. You can see other test scripts in the `package.json` |
| 87 | + |
| 88 | +</Steps> |
| 89 | + |
| 90 | +### Running the app after testing |
| 91 | + |
| 92 | +Since we rebuilt `better-sqlite3` with `npm`, we must rebuild it so that it can run in our Electron main process. |
| 93 | + |
| 94 | +> Also do this if you ever see this error. It indicates that `better-sqlite3` has not been rebuilt with the same version of Node.js as the Electron main process: |
| 95 | +> |
| 96 | +> ``` |
| 97 | +> Failed to connect to database: |
| 98 | +> PLEASE RUN 'node_modules/.bin/electron-rebuild -f -w better-sqlite3' to resolve this |
| 99 | +> ``` |
| 100 | +
|
| 101 | +<Steps> |
| 102 | +
|
| 103 | +1. Stop any tests if they are running. |
| 104 | +1. Rebuild `better-sqlite3` for Electron |
| 105 | +
|
| 106 | + ```bash |
| 107 | + npm run app:prepare |
| 108 | + ``` |
| 109 | +
|
| 110 | + - This will rebuild `better-sqlite3` to run on the same version of Node.js that the Electron main process is on |
| 111 | + |
| 112 | +1. The app should launch on its own, but if it doesn't you can run `npm run dev` to launch it. |
| 113 | + |
| 114 | +</Steps> |
0 commit comments