serverless
binary serves as an entrance for three independent CLI programs. Initial logic decides which CLI is actually run in current working directory context. Possible options are listed below
Documented at serverless.com/framework/docs of which code is hosted in this repository.
See Anatomy of the Serverless Framework CLI
Deprecated old version of Serverless Components
Documented at serverless/components/blob/v1, with code hosted at serverless/cli
Documented at serverless.com/components, with code hosted at serverless/components
Core flow of a process is managed through internal lifecycle engine, for which, internal (core) and external (user made) plugins register supported CLI commands attributing to them ordered lifecycle events,, plus hooks (event listeners) which are invoked when given event is triggered.
Internals are configured with following modules.
Note: that each of these modules are considered private, there should be no dependency on them in external packages. Organization of files and internal API is subject to constant changes
Located in (lib/Serverless.js
and lib/classes)
It's were core machinery with lifecycle engine internals is implemented
Located in lib/plugins. Register and implement core CLI commands with its events and attaches hooks for registered events
Located in lib/utils. General utils to be used in either core classes or internal plugins
- Setup essentials related to general error handling and eventual debugging (bin/serverless.js#L40-L56)
- Setup autocompletion (only if explicitly turned on) (bin/serverless.js#L58-L61)
- Propagate eventual analytics requests which weren't successful in previous runs (bin/serverless.js#L64-L66)
- Resolve location of eventual service configuration in current working directory (lib/Serverless.js#L40-L42)
- Parse CLI arguments (lib/Serverless.js#L67)
- (If in service context) Read service configuration (just read, no normalization and variables resolution at this point) (lib/classes/PluginManager.js#L60-L63)
- Check whether there's a newer version of a Framework available, and notify user if there is (Serverless.js#L79-L89)
- (If in service context) Normalize service configuration by filling defaults and ensuring core structure (no variables resolution yet) (lib/classes/Service.js#L38-L53)
- Load all plugins (internal and those installed by user). They configure supported CLI commands, register events for lifecycle engine, and attach hooks to events eventually triggered by lifecycle engine (lib/classes/PluginManager.js#L107-L116
- If it's
sls --help
command, show help and abort (lib/Serverless.js#L108-L110 - (If in service context) Populate all variables in service configuration (lib/Serverless.js#L118-L125)
- (if in service context) Validate service configration (lib/Serverless.js#L128
- Run lifecycle engine (emit all events that were registered for invoked CLI command) (lib/classes/PluginManager.js#L509-L511)
- If execution ended with an error, log it in user friendly way (lib/classes/Error.js#L68-L129)