Skip to content

Commit c4a8a7e

Browse files
Separate to multiple packages wokwi-client-js and wokwi-cli (#35)
* refactor: integrate wokwi-client-js and enhance wokwi-cli functionality - Introduced a new package, wokwi-client-js, to encapsulate API client functionality and transport mechanisms. - Updated wokwi-cli to utilize the new wokwi-client-js for API interactions, improving modularity and maintainability. - Refactored various components in wokwi-cli to support the new client structure, including changes to file uploads and command handling. - Enhanced error handling and connection management in the WebSocket transport layer. - Added new bundling script for the CLI and improved project structure for better organization. - Updated package.json and lock files to reflect new dependencies and scripts. * feat: add Playwright testing support and enhance project structure - Introduced Playwright for end-to-end testing, including new test scripts and configurations. - Updated .gitignore to exclude Playwright reports and test results. - Enhanced ESLint configuration to ignore Playwright-related files. - Added new scripts in package.json for running Playwright tests. - Created a new Playwright configuration file and integrated it into the TypeScript setup. - Updated GitHub workflows to include Playwright browser installation and testing steps. - Refactored wokwi-cli to improve modularity and maintainability with new transport mechanisms. * chore: update testing setup and remove obsolete workflow - Updated the test command in package.json to include separate scripts for vitest and CLI integration tests. - Added a new script for running CLI integration tests. - Modified GitHub workflows to run tests in a more structured manner. - Removed the obsolete CLI integration test workflow file. - Updated .gitignore to exclude the new test project directory. * feat: enhance wokwi-client-js with browser bundling support * feat: add DEVELOPMENT.md for setup instructions and replace CLI integration test script with TypeScript version * feat: enhance release workflow and improve serial monitor functionality * feat: add format check to CI workflow, update .gitignore and .prettierignore, and improve code formatting across multiple files * fix: update lint-staged configuration to use pnpm scripts for formatting and linting
1 parent 357f613 commit c4a8a7e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1003
-327
lines changed

.github/workflows/cli-integration-test.yml

Lines changed: 0 additions & 65 deletions
This file was deleted.

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ jobs:
2727
sudo apt-get update
2828
sudo apt-get install -y binfmt-support qemu-user-static
2929
- name: 'Build'
30-
run: pnpm run package
30+
run: pnpm run build && pnpm --filter wokwi-cli run package
3131
- name: Upload Release
3232
uses: ncipollo/release-action@v1
3333
with:
34-
artifacts: 'dist/bin/wokwi-cli-*,dist/bin/version.json'
34+
artifacts: 'packages/wokwi-cli/dist/bin/wokwi-cli-*,packages/wokwi-cli/dist/bin/version.json'
3535
token: ${{ secrets.GITHUB_TOKEN }}
3636
generateReleaseNotes: true

.github/workflows/test.yml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: Tests
22

33
on:
44
push:
5-
branches: [main]
65
pull_request:
76
branches: [main]
7+
workflow_dispatch:
88

99
jobs:
1010
test:
@@ -20,5 +20,17 @@ jobs:
2020
cache: 'pnpm'
2121
- name: Install dependencies
2222
run: pnpm install --frozen-lockfile
23-
- name: Run tests
24-
run: pnpm test
23+
- name: Build packages
24+
run: pnpm run build
25+
- name: Install Playwright browsers
26+
run: pnpm exec playwright install --with-deps
27+
- name: Format check
28+
run: pnpm run format:check
29+
- name: Run vitest tests
30+
run: pnpm run test:vitest
31+
- name: Run Playwright embed tests
32+
run: pnpm run test:embed:playwright
33+
- name: Run CLI integration tests
34+
run: pnpm run test:cli:integration
35+
env:
36+
WOKWI_CLI_TOKEN: ${{ secrets.WOKWI_CLI_TOKEN }}

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@ wokwi.toml
44
*.bin
55
diagram.json
66
screenshot.png
7+
playwright-report/
8+
test-results/
9+
test-project/
10+
wokwi-part-tests/

.prettierignore

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Ignore node_modules
2+
node_modules/
3+
4+
# Ignore build outputs
5+
dist/
6+
build/
7+
8+
# Ignore logs
9+
*.log
10+
11+
# Ignore package-lock.json if present
12+
package-lock.json
13+
14+
# Ignore Arduino-specific files
15+
*.hex
16+
*.elf
17+
*.bin
18+
19+
# Ignore OS-specific files
20+
.DS_Store
21+
Thumbs.db
22+
23+
# repo specific ignores
24+
playwright-report/
25+
test-results/
26+
test-project/
27+
wokwi-part-tests/

DEVELOPMENT.md

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
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).

README.md

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,20 +74,7 @@ To configure your AI agent to use the MCP server, add the following to your agen
7474

7575
## Development
7676

77-
Clone the repository, install the npm depenedencies, and then run the CLI:
78-
79-
```bash
80-
git clone https://github.com/wokwi/wokwi-cli
81-
cd wokwi-cli
82-
npm install
83-
npm start
84-
```
85-
86-
To pass command line arguments to the cli, use `npm start -- [arguments]`. For example, to see the help screen, run:
87-
88-
```
89-
npm start -- -h
90-
```
77+
All information about developing the Wokwi CLI can be found in [DEVELOPMENT.md](DEVELOPMENT.md).
9178

9279
## License
9380

eslint.config.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { defineConfig } from 'eslint/config';
22
import eslint from '@eslint/js';
3-
import eslintConfigPrettier from 'eslint-config-prettier';
43
import tseslint from 'typescript-eslint';
54

65
export default defineConfig(
@@ -18,6 +17,8 @@ export default defineConfig(
1817
'**/.git/**',
1918
'**/coverage/**',
2019
'**/*.min.js',
20+
'**/playwright-report/**',
21+
'**/test-results/**',
2122
],
2223
},
2324

@@ -64,7 +65,4 @@ export default defineConfig(
6465
'no-undef': 'off',
6566
},
6667
},
67-
68-
// Prettier config (must be last to override conflicting rules)
69-
eslintConfigPrettier,
7068
);

package.json

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,14 @@
99
"clean": "pnpm -r run clean",
1010
"lint": "eslint .",
1111
"lint:fix": "eslint . --fix",
12-
"test": "npm run lint && vitest --run",
12+
"format": "prettier --write packages scripts test",
13+
"format:check": "prettier --check packages scripts test",
14+
"test": "pnpm run test:vitest && pnpm run test:embed:playwright && pnpm run test:cli:integration",
15+
"test:vitest": "pnpm run lint && vitest --run",
16+
"test:embed:playwright": "playwright test test/wokwi-embed",
17+
"test:embed:playwright:ui": "playwright test test/wokwi-embed --ui",
18+
"test:cli:integration": "pnpm exec tsx scripts/test-cli-integration.ts",
19+
"package": "pnpm --filter wokwi-cli run package",
1320
"cli": "tsx packages/wokwi-cli/src/main.ts",
1421
"prepare": "husky install"
1522
},
@@ -19,26 +26,15 @@
1926
"type": "git",
2027
"url": "https://github.com/wokwi/wokwi-cli"
2128
},
22-
"dependencies": {
23-
"@clack/prompts": "^0.7.0",
24-
"@iarna/toml": "2.2.5",
25-
"@modelcontextprotocol/sdk": "^1.0.0",
26-
"arg": "^5.0.2",
27-
"chalk": "^5.3.0",
28-
"chalk-template": "^1.1.0",
29-
"pngjs": "^7.0.0",
30-
"ws": "^8.13.0",
31-
"yaml": "^2.3.1"
32-
},
3329
"devDependencies": {
3430
"@eslint/js": "^9.39.1",
31+
"@playwright/test": "^1.48.0",
3532
"esbuild": "^0.25.2",
3633
"eslint": "^9.39.1",
37-
"eslint-config-prettier": "^10.1.8",
3834
"husky": "^8.0.0",
3935
"jiti": "^2.6.1",
4036
"lint-staged": "^15.4.3",
41-
"prettier": "^3.5.0",
37+
"prettier": "^3.6.2",
4238
"rimraf": "^5.0.0",
4339
"tsx": "^4.19.2",
4440
"typescript": "^5.9.3",
@@ -47,8 +43,8 @@
4743
},
4844
"lint-staged": {
4945
"*.{js,ts}": [
50-
"prettier --write",
51-
"eslint"
46+
"pnpm run format:check",
47+
"pnpm run lint"
5248
]
5349
}
5450
}

packages/wokwi-cli/package.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,15 @@
55
"main": "index.js",
66
"type": "module",
77
"scripts": {
8-
"build": "node tools/build.js",
9-
"package": "npm run build && pkg --public -o dist/bin/wokwi-cli -t node20-linuxstatic-arm64,node20-linuxstatic-x64,node20-macos-arm64,node20-macos-x64,node20-win-x64 dist/cli.cjs",
8+
"prebuild": "pnpm run clean",
9+
"build": "tsc && pnpm run bundle",
10+
"bundle": "node tools/bundle.js",
11+
"package": "pnpm run build && pkg --public -o dist/bin/wokwi-cli -t node20-linuxstatic-arm64,node20-linuxstatic-x64,node20-macos-arm64,node20-macos-x64,node20-win-x64 dist/cli.cjs",
12+
"clean": "rimraf dist",
13+
"lint": "eslint src/**/*.ts",
14+
"lint:fix": "eslint src/**/*.ts --fix",
1015
"cli": "tsx src/main.ts",
11-
"test": "npm run lint && vitest --run",
16+
"test": "pnpm run lint && vitest --run",
1217
"test:watch": "vitest --watch"
1318
},
1419
"keywords": [
@@ -41,6 +46,7 @@
4146
"chalk": "^5.3.0",
4247
"chalk-template": "^1.1.0",
4348
"pngjs": "^7.0.0",
49+
"wokwi-client-js": "workspace:*",
4450
"ws": "^8.13.0",
4551
"yaml": "^2.3.1"
4652
},

0 commit comments

Comments
 (0)