feat: complete external module lifecycle SDK
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
# Aurora module template
|
||||
|
||||
Create a module with:
|
||||
|
||||
```sh
|
||||
npm run module:new -- my-module "My Module"
|
||||
```
|
||||
|
||||
Edit `manifest.json` and `main/index.cjs`, then package every module in `packages/`:
|
||||
|
||||
```sh
|
||||
npm run build:modules
|
||||
```
|
||||
|
||||
The resulting `.pac` file is written to `dist/module-catalog/`.
|
||||
|
||||
Lifecycle exports are optional. `projectCreate` runs during initial provisioning, `projectStart` after the containers start, `projectRemove` before project-scoped removal, and `packageUninstall` before the installed package is deleted. A manifest entry in `project.tools` calls `projectTool(context)` with its `id` in `context.toolId`.
|
||||
|
||||
The context provides `moduleId`, `hook`, `directory`, `projectName`, `settings`, `urls`, and `toolId`. It also provides `run(label, command, args)`, `ensureRouter()`, `setProjectMetadata(values)`, and `saveCredentials(values)`. Project-only values and helpers are unavailable to `packageUninstall`.
|
||||
@@ -0,0 +1,23 @@
|
||||
'use strict'
|
||||
|
||||
exports.projectCreate = async function projectCreate(context) {
|
||||
await context.run('Provision application', 'docker', ['compose', '-f', `${context.directory}/.aurora/compose.yaml`, 'up', '-d', '--build', '--remove-orphans'])
|
||||
}
|
||||
|
||||
exports.projectStart = async function projectStart() {
|
||||
// Optional: migrations, health checks, or other work after containers start.
|
||||
}
|
||||
|
||||
exports.projectRemove = async function projectRemove() {
|
||||
// Optional: remove project-scoped resources before the module/project is removed.
|
||||
}
|
||||
|
||||
exports.packageUninstall = async function packageUninstall() {
|
||||
// Optional: remove global resources before the installed .pac package is deleted.
|
||||
}
|
||||
|
||||
exports.projectTool = async function projectTool(context) {
|
||||
if (context.toolId === 'example-action') {
|
||||
await context.run('Example action', 'docker', ['compose', '-f', `${context.directory}/.aurora/compose.yaml`, 'ps'])
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"id": "example-module",
|
||||
"name": "Example Module",
|
||||
"version": "1.0.0",
|
||||
"category": "application",
|
||||
"description": "Describe what this Aurora module installs.",
|
||||
"main": "main/index.cjs",
|
||||
"aurora": { "core": "2.0.0-alpha.24", "moduleApi": "1.0.0" },
|
||||
"dependencies": [],
|
||||
"conflicts": [],
|
||||
"defaults": { "docroot": "" },
|
||||
"settings": [],
|
||||
"creation": {
|
||||
"databases": ["mariadb", "mysql", "postgres"],
|
||||
"setup": []
|
||||
},
|
||||
"project": {
|
||||
"tools": [{ "id": "example-action", "label": "Run example action" }]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user