Skip to content

Commit

Permalink
feat: update docs to reference cli to generate components, add docs f…
Browse files Browse the repository at this point in the history
…or cli
  • Loading branch information
mrgnhnt96 committed Jan 29, 2025
1 parent 8803549 commit e6e0606
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 0 deletions.
10 changes: 10 additions & 0 deletions doc-site/docs/constructs/revali_server/core/controllers.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ To create a controller, we need to create a class within the `routes` directory
class UsersController {}
```

:::tip
Try using the [`create` cli][create-cli] to generate the controller for you!

```bash
dart run revali_server create controller
```

:::

In order for Revali to know of this new controller, we need to add the `@Controller` annotation. The `Controller` annotation accepts 1 argument, which is the server path.

```dart title="routes/users/users_controller.dart"
Expand Down Expand Up @@ -104,3 +113,4 @@ Learn how to [configure dependencies][configure-dependencies].
[configure-dependencies]: ../../../revali/app-configuration/configure-dependencies.md#registering-dependencies
[binding]: ./binding.md
[instance-variables]: https://dart.dev/language/constructors#instance-variable-initialization
[create-cli]: ../getting-started/cli.md#create
10 changes: 10 additions & 0 deletions doc-site/docs/constructs/revali_server/core/pipes.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ class UserPipe implements Pipe<String, User> {
}
```

:::tip
Try using the [`create` cli][create-cli] to generate the pipe for you!

```bash
dart run revali_server create pipe
```

:::

The first type argument of the `Pipe` class is the type received from the binding. The second type argument is the type to be returned.

:::tip
Expand Down Expand Up @@ -77,3 +86,4 @@ Learn more about the Pipe Context [here][pipe-context].
[json-binding]: ./binding.md#auto-fromjson
[pipe-context]: ../context/pipe.md
[binding-pipe-transform]: ./binding.md#pipe-transform
[create-cli]: ../getting-started/cli.md#create
79 changes: 79 additions & 0 deletions doc-site/docs/constructs/revali_server/getting-started/cli.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
---
title: CLI
description: Learn how to use the Revali CLI to create components for your Revali application.
sidebar_position: 1
---

# Revali Server CLI

The Revali Server CLI is a tool that can be used to enhance the development of your Revali application. The CLI is installed when you add `revali_server` as a dev dependency during the [installation][installation] process.

## Commands

### Create

The `create` command is used to generate components for your Revali application. The following components can be generated using the `create` command:

- [App]

```bash
dart run revali_server create app
```

- [Controller]

```bash
dart run revali_server create controller
```

- [Lifecycle Component]

```bash
dart run revali_server create lifecycle-component
```

- [Observer]

```bash
dart run revali_server create observer
```

- [Pipe]

```bash
dart run revali_server create pipe
```

:::tip
You can choose from a list of available options by running the `create` command without any arguments.

```bash
dart run revali_server create
```

:::

## Configuration

Each of the components using the `create` command are generated into specific folders within your Revali application. If you would like to change the default configuration, you can do so by creating a `revali.yaml` file in the root of your project.

The following is an example of a `revali.yaml` file containing the default configuration:

```yaml title="revali.yaml"
revali_server:
create_path:
app: [ "routes", "app" ]
controller: [ "routes", "controllers" ]
lifecycle_component: [ "components", "lifecycle_components" ]
observer: [ "components", "observers" ]
pipe: [ "components", "pipes" ]
```

The `create_path` configuration allows you to specify the folder structure for each component type. The value of each component type can be either a string or a list of strings.

[installation]: ./installation.md
[controller]: ../core/controllers.md
[app]: ../../../revali/app-configuration/create-an-app.md
[lifecycle component]: ../lifecycle-components/components.md
[observer]: ../lifecycle-components/observer.md
[pipe]: ../core/pipes.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ class MyComponent implements LifecycleComponent {
}
```

:::tip
Try using the [`create` cli][create-cli] to generate the components for you!

```bash
dart run revali_server create lifecycle-component
```

:::

You may add fields to this class as you need, such as classes from your [dependencies][di] or values that are specific to the component. You can use [binding annotations][binding] to inject these dependencies into the component.

```dart title="lib/components/my_component.dart"
Expand Down Expand Up @@ -189,3 +198,4 @@ Future<void> myEndpoint() {
[interceptor-post-context]: ../context/interceptor.md#post
[exception-catcher-context]: ../context/exception-catcher.md
[implied-binding]: ../core/implied_binding.md
[create-cli]: ../getting-started/cli.md#create
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ class MyObserver implements Observer {
}
```

:::tip
Try using the [`create` cli][create-cli] to generate the observer for you!

```bash
dart run revali_server create observer
```

:::

:::note
There's no limit to the number of observers that can be applied to an app. Observers are executed in the order they are registered.
:::
Expand Down Expand Up @@ -65,3 +74,4 @@ class MyApp ...
```

[interceptors]: ./advanced/interceptors.md
[create-cli]: ../getting-started/cli.md#create

0 comments on commit e6e0606

Please sign in to comment.