From e6e0606ab5afbd0280be60464165e5bc803b15a0 Mon Sep 17 00:00:00 2001 From: Morgan Date: Wed, 29 Jan 2025 09:37:31 -0700 Subject: [PATCH] feat: update docs to reference cli to generate components, add docs for cli --- .../revali_server/core/controllers.md | 10 +++ .../constructs/revali_server/core/pipes.md | 10 +++ .../revali_server/getting-started/cli.md | 79 +++++++++++++++++++ .../lifecycle-components/components.md | 10 +++ .../lifecycle-components/observer.md | 10 +++ 5 files changed, 119 insertions(+) create mode 100644 doc-site/docs/constructs/revali_server/getting-started/cli.md diff --git a/doc-site/docs/constructs/revali_server/core/controllers.md b/doc-site/docs/constructs/revali_server/core/controllers.md index c2187c27..161df3f4 100644 --- a/doc-site/docs/constructs/revali_server/core/controllers.md +++ b/doc-site/docs/constructs/revali_server/core/controllers.md @@ -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" @@ -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 diff --git a/doc-site/docs/constructs/revali_server/core/pipes.md b/doc-site/docs/constructs/revali_server/core/pipes.md index 057a90ea..de5e699b 100644 --- a/doc-site/docs/constructs/revali_server/core/pipes.md +++ b/doc-site/docs/constructs/revali_server/core/pipes.md @@ -24,6 +24,15 @@ class UserPipe implements Pipe { } ``` +:::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 @@ -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 diff --git a/doc-site/docs/constructs/revali_server/getting-started/cli.md b/doc-site/docs/constructs/revali_server/getting-started/cli.md new file mode 100644 index 00000000..2b660a4d --- /dev/null +++ b/doc-site/docs/constructs/revali_server/getting-started/cli.md @@ -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 diff --git a/doc-site/docs/constructs/revali_server/lifecycle-components/components.md b/doc-site/docs/constructs/revali_server/lifecycle-components/components.md index 730a7a25..5a47dbdc 100644 --- a/doc-site/docs/constructs/revali_server/lifecycle-components/components.md +++ b/doc-site/docs/constructs/revali_server/lifecycle-components/components.md @@ -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" @@ -189,3 +198,4 @@ Future 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 \ No newline at end of file diff --git a/doc-site/docs/constructs/revali_server/lifecycle-components/observer.md b/doc-site/docs/constructs/revali_server/lifecycle-components/observer.md index 0f4606b1..1a0fc6d2 100644 --- a/doc-site/docs/constructs/revali_server/lifecycle-components/observer.md +++ b/doc-site/docs/constructs/revali_server/lifecycle-components/observer.md @@ -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. ::: @@ -65,3 +74,4 @@ class MyApp ... ``` [interceptors]: ./advanced/interceptors.md +[create-cli]: ../getting-started/cli.md#create