aws-amplify / aws-amplify/amplify-cli

hooks should include lifecycle event (pre/post) in hook data

Open
#12,140 0 comments 0 reactions 0 assignees View on GitHub
feature-request p3 platform-hooks size-sm
Dominant language
TypeScript
Stars
2.9k
Forks
825
Avg merge
11d 23h
Merged PRs (30d)
2

Description

### Is this feature request related to a new or existing Amplify category?

_No response_

### Is this related to another service?

_No response_

### Describe the feature you'd like to request

When using Amplify CLI command hooks we are able to define pre/post hooks, however it would be helpful to include the stage in the hook's payload. Below is a sample of the current payload:

```json
{
"amplify": {
"environment": {
"projectPath": "/Users/josef/Documents/projects/aws-amplify/reproductions/a12114",
"defaultEditor": "Visual Studio Code",
"envName": "next"
},
"command": "push",
"argv": [
"/Users/josef/.amplify/bin/amplify",
"/snapshot/repo/build/node_modules/@aws-amplify/cli-internal/bin/amplify",
"push",
"-y"
],
"version": "11.0.0-beta.8"
}
}
```

### Describe the solution you'd like

Add a `stage` key to the hook's payload

```json
{
"amplify": {
"environment": {
"projectPath": "/Users/josef/Documents/projects/aws-amplify/reproductions/a12114",
"defaultEditor": "Visual Studio Code",
"envName": "next"
},
"command": "push",
"stage": "post"
"argv": [
"/Users/josef/.amplify/bin/amplify",
"/snapshot/repo/build/node_modules/@aws-amplify/cli-internal/bin/amplify",
"push",
"-y"
],
"version": "11.0.0-beta.8"
}
}
```

### Describe alternatives you've considered

hardcoding the stage in the script or reading from the filename:

```js
function getLifecycleStage() {
const url = new URL(import.meta.url)
const filename = path.basename(url.pathname, '.js')
const [stage] = filename.split('-')
return stage
}
```

### Additional context

_No response_

### Is this something that you'd be interested in working on?

- [X] 👋 I may be able to implement this feature request

### Would this feature include a breaking change?

- [ ] ⚠️ This feature might incur a breaking change

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.