Skip to content

Commit ee45800

Browse files
authored
docs(dart_frog_cli): Add methods usage examples (#1051)
1 parent acca0a5 commit ee45800

File tree

1 file changed

+135
-0
lines changed

1 file changed

+135
-0
lines changed

docs/docs/advanced/daemon.md

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ application instances of the same project if necessary.
1010

1111
To start using it, install the Dart Frog CLI and run the `dart_frog daemon` command. Once running, communicating with it can be done via [JSON-RPC](https://www.jsonrpc.org/) over stdin/stdout to receive and send messages.
1212

13+
:::note
14+
For a concrete sample of how to interact with the daemon via `stdio`, see the [end-to-end tests](https://github.com/VeryGoodOpenSource/dart_frog/tree/main/packages/dart_frog_cli/e2e/test/daemon).
15+
:::
16+
1317
There are three types of messages:
1418

1519
- **Request**: A request is a message sent by a client to the daemon. The daemon will process the
@@ -21,6 +25,10 @@ There are three types of messages:
2125
Every request should be met with a response as soon as possible so the caller can work with
2226
timeouts. The daemon will send events to the client as they happen.
2327

28+
:::warning
29+
The daemon is still in its early stages of development. Therefore, the API is not stable and may change.
30+
:::
31+
2432
---
2533

2634
#### Usage example
@@ -69,6 +77,19 @@ Request the daemon version.
6977
| ------- | ------ | ------------------ |
7078
| version | string | The daemon version |
7179

80+
```sh
81+
$ dart_frog daemon
82+
83+
// ready event sent via stdout
84+
[{"event":"daemon.ready","params":{"version":"0.0.1","processId":75941}}]
85+
86+
// request inserted via stdin
87+
[{"method": "daemon.requestVersion", "id": "12"}]
88+
89+
// response sent via stdout
90+
[{"id":"12","result":{"version":"0.0.1"}}]
91+
```
92+
7293
### Method: `kill`
7394

7495
Shuts down the daemon
@@ -79,6 +100,19 @@ Shuts down the daemon
79100
| ------- | ------ | ----------------- |
80101
| message | string | A goodbye message |
81102

103+
```sh
104+
$ dart_frog daemon
105+
106+
// ready event sent via stdout
107+
[{"event":"daemon.ready","params":{"version":"0.0.1","processId":75941}}]
108+
109+
// request inserted via stdin
110+
[{"method": "daemon.kill", "id": "12"}]
111+
112+
// response sent via stdout
113+
[{"id":"12","result":{"message":"Hogarth. You stay, I go. No following."}}]
114+
```
115+
82116
### Event: `ready`
83117

84118
Signals that a daemon is ready right after startup
@@ -112,6 +146,21 @@ Start a dev server on a given project.
112146
| ------------- | ------ | ----------------------------------------------- |
113147
| applicationId | String | A unique identifier for the dev server instance |
114148

149+
```sh
150+
$ dart_frog daemon
151+
152+
// ready event sent via stdout
153+
[{"event":"daemon.ready","params":{"version":"0.0.1","processId":75941}}]
154+
155+
// request inserted via stdin
156+
[{"method":"dev_server.start","id":"12","params":{"workingDirectory":"./","port":8080,"dartVmServicePort":8091}}]
157+
158+
// response sent via stdout
159+
[{"event":"dev_server.applicationStarting","params":{"applicationId":"9e531349","requestId":"12"}}]
160+
161+
// Few logs omitted
162+
```
163+
115164
### Method: `reload`
116165

117166
Reload a running dev server.
@@ -128,6 +177,25 @@ Reload a running dev server.
128177
| ------------- | ------ | ----------------------------------------------- |
129178
| applicationId | String | A unique identifier for the dev server instance |
130179

180+
```sh
181+
$ dart_frog daemon
182+
183+
// ready event sent via stdout
184+
[{"event":"daemon.ready","params":{"version":"0.0.1","processId":75941}}]
185+
186+
// start server before reloading (use dev_server.start)
187+
188+
// request inserted via stdin
189+
[{"method":"dev_server.reload","id":"12","params":{"applicationId":"9e531349"}}]
190+
191+
// Few logs omitted
192+
193+
// response sent via stdout
194+
[{"id":"12","result":{"applicationId":"9e531349"}}]
195+
196+
// Few logs omitted
197+
```
198+
131199
### Method: `stop`
132200

133201
Stop a running dev server.
@@ -145,6 +213,23 @@ Stop a running dev server.
145213
| applicationId | String | A unique identifier for the dev server instance |
146214
| exitCode | int | The exit code of the dev server process |
147215

216+
```sh
217+
$ dart_frog daemon
218+
219+
// ready event sent via stdout
220+
[{"event":"daemon.ready","params":{"version":"0.0.1","processId":75941}}]
221+
222+
// start server before stopping (use dev_server.start)
223+
224+
// request inserted via stdin
225+
[{"method":"dev_server.stop","id":"12","params":{"applicationId":"9e531349"}}]
226+
227+
// Few logs omitted
228+
229+
// response sent via stdout
230+
[{"id":"12","result":{"applicationId":"9e531349","exitCode":0}}]
231+
```
232+
148233
### Event: `applicationStarting`
149234

150235
Signals that a dev server is starting.
@@ -207,6 +292,22 @@ when the route configuration of a project changes.
207292
| --------- | ------ | -------------------------------------------- |
208293
| watcherId | String | A unique identifier for the watcher instance |
209294

295+
```sh
296+
$ dart_frog daemon
297+
298+
// ready event sent via stdout
299+
[{"event":"daemon.ready","params":{"version":"0.0.1","processId":75941}}]
300+
301+
// request inserted via stdin
302+
[{"method":"route_configuration.watcherStart","id":"12","params":{"workingDirectory":"./"}}]
303+
304+
// response sent via stdout
305+
[{"id":"12","result":{"watcherId":"29f9ad21"}}]
306+
307+
// An event is sent via stdout for every change detected
308+
[{"event":"route_configuration.changed","params":{"watcherId":"29f9ad21","requestId":"12","routeConfiguration":{ ... }}}]
309+
```
310+
210311
### Method: `watcherStop`
211312

212313
Stops a route configuration watcher created by `watcherStart`.
@@ -224,6 +325,23 @@ Stops a route configuration watcher created by `watcherStart`.
224325
| watcherId | String | A unique identifier for the watcher instance |
225326
| exitCode | int | The exit code of the watcher process |
226327

328+
```sh
329+
$ dart_frog daemon
330+
331+
// ready event sent via stdout
332+
[{"event":"daemon.ready","params":{"version":"0.0.1","processId":75941}}]
333+
334+
// start watcher before stopping (use route_configuration.watcherStart)
335+
336+
// request inserted via stdin
337+
[{"method":"route_configuration.watcherStop","id":"12","params":{"watcherId":"29f9ad21"}}]
338+
339+
// Few logs omitted
340+
341+
// response sent via stdout
342+
[{"id":"12","result":{"watcherId":"29f9ad21","exitCode":0}}]
343+
```
344+
227345
### Method: `watcherGenerateRouteConfiguration`
228346

229347
Forces a route configuration watcher to generate a route configuration for a given project.
@@ -242,6 +360,23 @@ Also, returns the generated route configuration.
242360
| watcherId | String | A unique identifier for the watcher instance |
243361
| routeConfiguration | String | The generated route configuration |
244362

363+
```sh
364+
$ dart_frog daemon
365+
366+
// ready event sent via stdout
367+
[{"event":"daemon.ready","params":{"version":"0.0.1","processId":75941}}]
368+
369+
// start watcher before stopping (use route_configuration.watcherStart)
370+
371+
// request inserted via stdin
372+
[{"method":"route_configuration.watcherGenerateRouteConfiguration","id":"12","params":{"watcherId":"29f9ad21"}}]
373+
374+
// Few logs omitted
375+
376+
// response sent via stdout
377+
[{"id":"12","result":{"watcherId":"29f9ad21","routeConfiguration":{ ... }}}]
378+
```
379+
245380
### Event: `changed`
246381

247382
Signals that the route configuration of a project has changed.

0 commit comments

Comments
 (0)