serverless / components

The Serverless Framework's new infrastructure provisioning technology — Build, compose, & deploy serverless apps in seconds...
https://www.serverless.com
Apache License 2.0
2.31k stars 182 forks source link

Installing components via the CLI #435

Open eahefnawy opened 5 years ago

eahefnawy commented 5 years ago

Currently whenever you run components in an empty directory, you get a prompt to choose one of the templates available in core. This has the following problems:

  1. For every component out there, we gotta make a new core release.
  2. The prompt does not scale (and doesn't work well with our own CLI)
  3. If the user does not find the component as a template, they'd need to copy paste the template. Which also makes on-boarding and documenting components a little harder.

So instead of the prompt, I suggest that each component repo/dir could (not should) have a templates directory, containing at least one template (with comments/sample files if required), but could possibly have more than one.

Users could then run the following command:

# only if an empty directory

# npm installs the component to the local cache if it doesn't exist
# and also copies the default template of that component in the cwd
$ components <component-package-name> 

# npm installs the component to the local cache if it doesn't exist
# and also copies the specified template of that component in the cwd
$ components <component-package-name>/<template-name>

some examples:

# install and copy the default template
$ components @serverless/aws-lambda

# install and copy the http-function template
$ components @serverless/aws-lambda/http-function

This way, we implement a scalable templating solution that component authors could extend and offer an experience similar to Yoman. In v1, we have to explicitly add lambda templates to the core, and users are still asking for more till this day.

remember that adding a template to the repo is optional but encouraged. If the specified component does not include a template, the the component would just be installed. Practically though, I think any quality component should have a template example with comments.

thoughts?

eahefnawy commented 5 years ago

Also, if you run just components in an empty directory, it would generate the component template right away. (ie. writing your own component)