|
| 1 | +# Development |
| 2 | + |
| 3 | +This document describes how to set up a development environment for the Wokwi CLI and the Wokwi JS client. |
| 4 | + |
| 5 | +## Getting started |
| 6 | + |
| 7 | +Prerequisites: |
| 8 | +- Node.js (https://nodejs.org/) (version 20 or higher) |
| 9 | +- Git |
| 10 | +- PNPM (https://pnpm.io) |
| 11 | + |
| 12 | +We use PNPM workspaces to manage multiple packages in this repository. Install PNPM globally following the official instructions: https://pnpm.io/installation. |
| 13 | + |
| 14 | +## Setting up the repository |
| 15 | + |
| 16 | +Clone the repository and install dependencies: |
| 17 | + |
| 18 | +```bash |
| 19 | +git clone https://github.com/wokwi/wokwi-cli |
| 20 | +cd wokwi-cli |
| 21 | +pnpm install |
| 22 | +``` |
| 23 | + |
| 24 | +We use Playwright for end-to-end testing. Install the required browsers with: |
| 25 | + |
| 26 | +```bash |
| 27 | +pnpm exec playwright install |
| 28 | +``` |
| 29 | + |
| 30 | +## Packages |
| 31 | + |
| 32 | +The repository contains two main packages: |
| 33 | +- `wokwi-cli`: The command-line interface for Wokwi. |
| 34 | +- `wokwi-js`: The JavaScript client library used to interact with Wokwi from a browser iframe. |
| 35 | + |
| 36 | +When you run `pnpm` commands from the repository root, the monorepo configuration determines which packages the command runs in. For example, `pnpm build` runs the build across packages, while `pnpm lint` runs `eslint .` for the whole repository. |
| 37 | + |
| 38 | +If you want to build a single package, use the `--filter` flag. For example, to build only the `wokwi-cli` package: |
| 39 | + |
| 40 | +```bash |
| 41 | +pnpm --filter wokwi-cli build |
| 42 | +``` |
| 43 | + |
| 44 | +Or change into the package directory and run the command there: |
| 45 | + |
| 46 | +```bash |
| 47 | +cd packages/wokwi-cli |
| 48 | +pnpm build |
| 49 | +``` |
| 50 | + |
| 51 | +## Running the CLI in development mode |
| 52 | + |
| 53 | +Build the packages first: |
| 54 | + |
| 55 | +```bash |
| 56 | +pnpm build |
| 57 | +``` |
| 58 | + |
| 59 | +Then run the CLI from the `wokwi-cli` package directory: |
| 60 | + |
| 61 | +```bash |
| 62 | +cd packages/wokwi-cli |
| 63 | +pnpm cli [arguments] |
| 64 | + |
| 65 | +# Example: show the help screen |
| 66 | +pnpm cli -h |
| 67 | +``` |
| 68 | + |
| 69 | +Example output: |
| 70 | + |
| 71 | +```bash |
| 72 | +Wokwi CLI v0-development (f33d9d579b0a) |
| 73 | + |
| 74 | + USAGE |
| 75 | + |
| 76 | + $ wokwi-cli [options] [path/to/project] |
| 77 | + |
| 78 | + OPTIONS |
| 79 | + --help, -h Shows this help message and exit |
| 80 | +... |
| 81 | +``` |
| 82 | + |
| 83 | +## Running tests locally |
| 84 | + |
| 85 | +Before running tests, make sure you have built the packages and installed Playwright browsers: |
| 86 | + |
| 87 | +```bash |
| 88 | +pnpm build |
| 89 | +pnpm exec playwright install |
| 90 | +``` |
| 91 | + |
| 92 | +We have several types of tests: |
| 93 | +- Unit tests (Vitest) |
| 94 | +- End-to-end tests (Playwright) |
| 95 | +- Integration tests that run the CLI against real Wokwi projects |
| 96 | + |
| 97 | +To run all tests: |
| 98 | + |
| 99 | +```bash |
| 100 | +pnpm test |
| 101 | +``` |
| 102 | + |
| 103 | +To run tests separately, inspect the `scripts` section in the root `package.json`. |
| 104 | + |
| 105 | +## Automatic tests (CI) |
| 106 | + |
| 107 | +The repository uses GitHub Actions to run tests on every push and pull request. The workflow files live in `.github/workflows/` and contain steps to set up the environment, install dependencies, build packages, and run tests. |
| 108 | + |
| 109 | +If you fork the repository, you must enable GitHub Actions for your fork and add the `WOKWI_CLI_TOKEN` secret. |
| 110 | + |
| 111 | +Set the `WOKWI_CLI_TOKEN` secret in your fork under `Settings` > `Secrets and variables` > `Actions` > `New repository secret`. |
| 112 | + |
| 113 | +Instructions for obtaining the `WOKWI_CLI_TOKEN` are in the `README.md` (see the Usage section). |
0 commit comments