Path: blob/main/docs/versioned_docs/version-v28/apps/02-developing-apps.md
1007 views
---
---
Developing Ignite Apps
It's easy to create an app and use it immediately in your project. First choose a directory outside your project and run:
This will create a new directory my-app
that contains the app's code and will output some instructions about how to use your app with the ignite
command. An app path can be a local directory which has several benefits:
You don't need to use a Git repository during the development of your app.
The app is recompiled each time you run the
ignite
binary in your project if the source files are older than the app binary.
Thus, app development workflow is as simple as:
Scaffold an app with
ignite app scaffold my-app
Add it to your config via
ignite app install -g /path/to/my-app
Update app code
Run
ignite my-app
binary to compile and run the appGo back to 3
Once your app is ready you can publish it to a Git repository and the community can use it by calling ignite app install github.com/foo/my-app
.
Now let's detail how to update your app's code.
App interface
Under the hood Ignite Apps are implemented using a plugin system based on github.com/hashicorp/go-plugin
.
All apps must implement a predefined interface:
The scaffolded code already implements this interface, you just need to update the method's body.
Defining app's manifest
Here is the Manifest
proto message definition:
In your app's code the Manifest
method already returns a predefined Manifest
struct as an example. You must adapt it according to your need.
If your app adds one or more new commands to ignite
, add them to the Commands
field.
If your app adds features to existing commands, add them to the Hooks
field.
Of course an app can declare both, Commands
and Hooks
.
An app may also share a host process by setting SharedHost
to true
. SharedHost
is desirable if an app hooks into, or declares long running commands. Commands executed from the same app context interact with the same app server. Allowing all executing commands to share the same server instance, giving shared execution context.
Adding new commands
App commands are custom commands added to Ignite CLI by an installed app. Commands can use any path not defined already by the CLI.
For instance, let's say your app adds a new oracle
command to ignite scaffold
, then the Manifest
method will look like :
To update the app execution, you have to change the Execute
command. For example:
Then, run ignite scaffold oracle
to execute the app.
Adding hooks
App Hooks
allow existing CLI commands to be extended with new functionality. Hooks are useful when you want to streamline functionality without needing to run custom scripts after or before a command has been run. This can streamline processes that where once error prone or forgotten all together.
The following are hooks defined which will run on a registered ignite
command:
Name | Description |
---|---|
Pre | Runs before a commands main functionality is invoked in the PreRun scope |
Post | Runs after a commands main functionality is invoked in the PostRun scope |
Clean Up | Runs after a commands main functionality is invoked. If the command returns an error it will run before the error is returned to guarantee execution. |
Note: If a hook causes an error in the pre step the command will not run resulting in post
and clean up
not executing.
The following is an example of a hook
definition.
Above we can see a similar definition to Command
where a hook has a Name
and a PlaceHookOn
. You'll notice that the Execute*
methods map directly to each life cycle of the hook. All hooks defined within the app will invoke these methods.