weixu365 / serverless-scriptable-plugin

Adding script support to Serverless 1.x which enables you to customize Serverless behavior without writing a plugin.
MIT License
112 stars 11 forks source link

scripthooks Not working with separate yml file #44

Closed andreimcristof closed 5 years ago

andreimcristof commented 5 years ago

Hi there, the plugin works smooth when I declare the scripthooks in the main serverless.yml file. But to keep a clean yml, I have split my custom declarations in another file, referenced like this:

custom: ${file(./custom.yml)}

the rest of the variables declared there work fine, except for the scriptHooks one:

  env:
    app:
    ...
  scriptHooks:
    after:aws:deploy:finalize:cleanup: ./export-frontend-config.js

So, the above scriptHooks declaration works only when declared in the serverless.yml, but not in the custom.yml. Thanks for any suggestion. Best regards,

weixu365 commented 5 years ago

Hi @andreimcristof, there has no simple fix for this unless use a few internal serverless methods, but that would cause more issues if serverless framework changed their code.

Here's what happens inside serverless when you run a serverless command:

1. Load config files
2. Load plugins, each plugin setup their hooks and commands
3. Populate variables, replace `${file(./custom.yml)}` with the actual content
4. Run command based on command-line options

Plugins have already been set up and all the commands and hooks info have been loaded into serverless before Serverless populate variables.

I think the only way is to populate variables after the plugin has been loaded, but that would change the behavior of serverless and could cause more troubles.

So I think the best approach is changing serverless logic to populate variables immediately after it loaded the config file, and you have to put custom scripts inside serverless.yml file until that happens

andreimcristof commented 5 years ago

Thank you very much for taking the time to explain in such detail. Much appreciated.