serverless / serverless

⚡ Serverless Framework – Effortlessly build apps that auto-scale, incur zero costs when idle, and require minimal maintenance using AWS Lambda and other managed cloud services.
https://serverless.com
MIT License
46.41k stars 5.7k forks source link

Incorrect lifecycle events in documentation #11891

Open AntonOellerer opened 1 year ago

AntonOellerer commented 1 year ago

Are you certain it's a bug?

Is the issue caused by a plugin?

Are you using the latest v3 release?

Is there an existing issue for this?

Issue description

I am trying to write a plugin creating certain files before packaging, referring to the official documentation here

Under the Lifecycle Events section, there are listed events such as:

* before:package:package
* package:package
* after:package:package
* before:deploy:deploy
* deploy:deploy
* after:deploy:deploy

I did some fiddling around now and discovered that for me at least the before:package:package, package:package and after:package:package events do not exist

Service configuration (serverless.yml) content

interface Props {
  log: any;
}
class SchemaCompiler {
  hooks: { [key: string]: () => void };
  serverless: any;
  log: any;
  cliOptions: any;

  constructor(serverless: any, cliOptions: any, props: Props) {
    this.serverless = serverless;
    this.cliOptions = cliOptions;
    this.log = props.log;
    this.log.warn("Hello from constructor");
    this.hooks = {
      initialize: () => this.compileSchema("initialize"),
      "package:initialize": () => this.compileSchema("package:initialize"),
      "before:package:package": () => this.compileSchema("before:package:package"),
      "package:package": () => this.compileSchema("package:package"),
      "after:package:package": () => this.compileSchema("after:package:package"),
      "before:deploy:deploy": () => this.compileSchema("before:deploy:deploy"),
      "deploy:deploy": () => this.compileSchema("deploy:deploy"),
      "after:deploy:deploy": () => this.compileSchema("after:deploy:deploy"),
    };
  }

  compileSchema(name: String) {
    this.log.warn("Hello from %s!", name);
  }
}

module.exports = SchemaCompiler;

Command name and used flags

sls deploy

Command output

Warning: Hello from constructor

Deploying xxx to stage dev (eu-central-1, "default" provider)
Warning: Hello from initialize!
Warning: Hello from package:initialize!
Warning: No external modules needed
Warning: Hello from before:deploy:deploy!
Warning: Hello from deploy:deploy!
Warning: Hello from after:deploy:deploy!

### Environment information

```shell
Framework Core: 3.29.0 (local)
Plugin: 6.2.3
SDK: 4.3.2
medikoo commented 1 year ago

@AntonOellerer these event names are just examples. they're not references of specific lifecycle events that occur at specific command.

Nonetheless, we'd welcome the PR, that improves the example with some real world event names that actually occur

katlim-br commented 7 months ago

I found this

https://gist.github.com/HyperBrain/50d38027a8f57778d5b0f135d80ea406