Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--config option #6216

Merged
merged 11 commits into from
Jun 11, 2019
1 change: 1 addition & 0 deletions docs/providers/aws/cli-reference/deploy.md
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ serverless deploy
``` ```


## Options ## Options
- `--config` or `-c` Path to your conifguration file, if other than `serverless.yml|.yaml|.js|.json`.
- `--stage` or `-s` The stage in your service that you want to deploy to. - `--stage` or `-s` The stage in your service that you want to deploy to.
- `--region` or `-r` The region in that stage that you want to deploy to. - `--region` or `-r` The region in that stage that you want to deploy to.
- `--package` or `-p` path to a pre-packaged directory and skip packaging step. - `--package` or `-p` path to a pre-packaged directory and skip packaging step.
Expand Down
2 changes: 1 addition & 1 deletion docs/providers/aws/guide/deploying.md
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ serverless deploy


Use this method when you have updated your Function, Event or Resource configuration in `serverless.yml` and you want to deploy that change (or multiple changes at the same time) to Amazon Web Services. Use this method when you have updated your Function, Event or Resource configuration in `serverless.yml` and you want to deploy that change (or multiple changes at the same time) to Amazon Web Services.


**Note:** You can always enforce a deployment using the `--force` option. **Note:** You can always enforce a deployment using the `--force` option, or specify a different configuration file name with the the `--config` option.


### How It Works ### How It Works


Expand Down
1 change: 1 addition & 0 deletions docs/providers/azure/cli-reference/deploy.md
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ serverless deploy
``` ```


## Options ## Options
- `--config` or `-c` Path to your conifguration file, if other than `serverless.yml|.yaml|.js|.json`.
- `--noDeploy` or `-n` Skips the deployment steps and leaves artifacts in the `.serverless` directory - `--noDeploy` or `-n` Skips the deployment steps and leaves artifacts in the `.serverless` directory
- `--verbose` or `-v` Shows all stack events during deployment, and display any Stack Output. - `--verbose` or `-v` Shows all stack events during deployment, and display any Stack Output.
- `--function` or `-f` Invoke `deploy function` (see above). Convenience shortcut. - `--function` or `-f` Invoke `deploy function` (see above). Convenience shortcut.
Expand Down
2 changes: 2 additions & 0 deletions docs/providers/azure/guide/deploying.md
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ Use this method when you have updated your Function, Event or Resource
configuration in `serverless.yml` and you want to deploy that change (or multiple configuration in `serverless.yml` and you want to deploy that change (or multiple
changes at the same time) to Azure Functions. changes at the same time) to Azure Functions.


**Note:** You can specify a different configuration file name with the the `--config` option.

### How It Works ### How It Works


The Serverless Framework translates all syntax in `serverless.yml` to an Azure The Serverless Framework translates all syntax in `serverless.yml` to an Azure
Expand Down
4 changes: 2 additions & 2 deletions docs/providers/azure/guide/intro.md
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ needed for that event and configure your functions to listen to it.
A **Service** is the Framework's unit of organization. You can think of it as a A **Service** is the Framework's unit of organization. You can think of it as a
project file, though you can have multiple services for a single application. project file, though you can have multiple services for a single application.
It's where you define your Functions, the Events that trigger them, and the It's where you define your Functions, the Events that trigger them, and the
Resources your Functions use, all in one file entitled `serverless.yml` (or Resources your Functions use, all in one file by default entitled `serverless.yml` (or
`serverless.json` or `serverless.js`). It looks like this: `serverless.json` or `serverless.js`). It looks like this:


```yml ```yml
Expand Down Expand Up @@ -91,7 +91,7 @@ functions: # Your "Functions"
``` ```


When you deploy with the Framework by running `serverless deploy`, everything in When you deploy with the Framework by running `serverless deploy`, everything in
`serverless.yml` is deployed at once. `serverless.yml` (or the file specified with the `--config` option) is deployed at once.


### Plugins ### Plugins


Expand Down
1 change: 1 addition & 0 deletions docs/providers/cloudflare/cli-reference/deploy.md
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ serverless deploy
This is the simplest deployment usage possible. With this command, Serverless will deploy your service to Cloudflare. This is the simplest deployment usage possible. With this command, Serverless will deploy your service to Cloudflare.


## Options ## Options
- `--config` or `-c` Path to your conifguration file, if other than `serverless.yml|.yaml|.js|.json`.
- `--verbose` or `-v`: Shows all stack events during deployment, and display any Stack Output. - `--verbose` or `-v`: Shows all stack events during deployment, and display any Stack Output.
- `--function` or `-f`: Invokes `deploy function` (see above). Convenience shortcut - `--function` or `-f`: Invokes `deploy function` (see above). Convenience shortcut


Expand Down
4 changes: 3 additions & 1 deletion docs/providers/cloudflare/guide/deploying.md
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ serverless deploy
``` ```


Use this method when you have updated your Function, Event or Resource configuration in `serverless.yml` and you want to deploy that change (or multiple changes at the same time) to your Cloudflare Worker. If you've made changes to any of your routes since last deploying, the Serverless Framework will update them on the server for you. Use this method when you have updated your Function, Event or Resource configuration in `serverless.yml` and you want to deploy that change (or multiple changes at the same time) to your Cloudflare Worker. If you've made changes to any of your routes since last deploying, the Serverless Framework will update them on the server for you.


**Note:** You can specify a different configuration file name with the the `--config` option.

### How It Works ### How It Works
The Serverless Framework reads in `serverless.yml` and uses it to provision your Functions. The Serverless Framework reads in `serverless.yml` and uses it to provision your Functions.


Expand Down
1 change: 1 addition & 0 deletions docs/providers/fn/cli-reference/deploy.md
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ serverless deploy
This is the simplest deployment usage possible. With this command Serverless will deploy your service to the configured Fn server. This is the simplest deployment usage possible. With this command Serverless will deploy your service to the configured Fn server.


## Options ## Options
- `--config` or `-c` Path to your conifguration file, if other than `serverless.yml|.yaml|.js|.json`.
- `--verbose` or `-v` Shows all stack events during deployment, and display any Stack Output. - `--verbose` or `-v` Shows all stack events during deployment, and display any Stack Output.
- `--function` or `-f` Invoke `deploy function` (see above). Convenience shortcut - `--function` or `-f` Invoke `deploy function` (see above). Convenience shortcut


Expand Down
2 changes: 2 additions & 0 deletions docs/providers/fn/guide/deploying.md
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ serverless deploy


Use this method when you have updated your Function, Event or Resource configuration in `serverless.yml` and you want to deploy that change (or multiple changes at the same time) to your Fn cluster. Use this method when you have updated your Function, Event or Resource configuration in `serverless.yml` and you want to deploy that change (or multiple changes at the same time) to your Fn cluster.


**Note:** You can specify a different configuration file name with the the `--config` option.

### How It Works ### How It Works


The Serverless Framework translates all syntax in `serverless.yml` to [Fn](https://github.com/fnproject/fn) calls to provision your Functions. The Serverless Framework translates all syntax in `serverless.yml` to [Fn](https://github.com/fnproject/fn) calls to provision your Functions.
Expand Down
4 changes: 2 additions & 2 deletions docs/providers/fn/guide/intro.md
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Anything that triggers an Fn Event to execute is regarded by the Framework as an


### Services ### Services


A **Service** is the Serverless Framework's unit of organization. You can think of it as a project file, though you can have multiple services for a single application. It's where you define your Functions and the Events that trigger them, all in one file entitled `serverless.yml` (or `serverless.json` or `serverless.js`). It looks like this: A **Service** is the Serverless Framework's unit of organization. You can think of it as a project file, though you can have multiple services for a single application. It's where you define your Functions and the Events that trigger them, all in one file by default entitled `serverless.yml` (or `serverless.json` or `serverless.js`). It looks like this:


```yml ```yml
# serverless.yml # serverless.yml
Expand All @@ -59,4 +59,4 @@ functions: # Your "Functions"
path: /hello path: /hello
``` ```


When you deploy with the Framework by running `serverless deploy`, everything in `serverless.yml` is deployed at once. When you deploy with the Framework by running `serverless deploy`, everything in `serverless.yml` (or the file specified with the `--config` option) is deployed at once.
3 changes: 3 additions & 0 deletions docs/providers/google/cli-reference/deploy.md
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ The `serverless deploy` command deploys your entire service via the Google Cloud
serverless deploy serverless deploy
``` ```


## Options
- `--config` or `-c` Path to your conifguration file, if other than `serverless.yml|.yaml|.js|.json`.

## Artifacts ## Artifacts


After the `serverless deploy` command runs all created deployment artifacts are placed in the `.serverless` folder of the service. After the `serverless deploy` command runs all created deployment artifacts are placed in the `.serverless` folder of the service.
2 changes: 2 additions & 0 deletions docs/providers/google/guide/deploying.md
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ serverless deploy


Use this method when you have updated your Function, Events or Resource configuration in `serverless.yml` and you want to deploy that change (or multiple changes at the same time) to the Google Cloud. Use this method when you have updated your Function, Events or Resource configuration in `serverless.yml` and you want to deploy that change (or multiple changes at the same time) to the Google Cloud.


**Note:** You can specify a different configuration file name with the the `--config` option.

### How It Works ### How It Works


The Serverless Framework translates all syntax in `serverless.yml` to a Google Deployment Manager configuration template. The Serverless Framework translates all syntax in `serverless.yml` to a Google Deployment Manager configuration template.
Expand Down
4 changes: 2 additions & 2 deletions docs/providers/google/guide/intro.md
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ When you define an event for your Google Cloud Function in the Serverless Framew


### Services ### Services


A **Service** is the Framework's unit of organization. You can think of it as a project file, though you can have multiple services for a single application. It's where you define your Functions, the Events that trigger them, and the Resources your Functions use, all in one file entitled `serverless.yml` (or `serverless.json` or `serverless.js`). It looks like this: A **Service** is the Framework's unit of organization. You can think of it as a project file, though you can have multiple services for a single application. It's where you define your Functions, the Events that trigger them, and the Resources your Functions use, all in one file by default entitled `serverless.yml` (or `serverless.json` or `serverless.js`). It looks like this:


```yml ```yml
# serverless.yml # serverless.yml
Expand All @@ -59,7 +59,7 @@ functions: # Your "Functions"
- http: create - http: create
``` ```


When you deploy with the Framework by running `serverless deploy`, everything in `serverless.yml` is deployed at once. When you deploy with the Framework by running `serverless deploy`, everything in `serverless.yml` (or the file specified with the `--config` option) is deployed at once.


### Plugins ### Plugins


Expand Down
1 change: 1 addition & 0 deletions docs/providers/kubeless/cli-reference/deploy.md
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ serverless deploy
This is the simplest deployment usage possible. With this command Serverless will deploy your service to the default Kubernetes cluster in your kubeconfig file. This is the simplest deployment usage possible. With this command Serverless will deploy your service to the default Kubernetes cluster in your kubeconfig file.


## Options ## Options
- `--config` or `-c` Path to your conifguration file, if other than `serverless.yml|.yaml|.js|.json`.
- `--noDeploy` or `-n` Skips the deployment steps and leaves artifacts in the `.serverless` directory. - `--noDeploy` or `-n` Skips the deployment steps and leaves artifacts in the `.serverless` directory.
- `--verbose` or `-v` Shows all stack events during deployment, and display any Stack Output. - `--verbose` or `-v` Shows all stack events during deployment, and display any Stack Output.
- `--package` or `-p` The path of a previously packaged deployment to get deployed (skips packaging step). - `--package` or `-p` The path of a previously packaged deployment to get deployed (skips packaging step).
Expand Down
2 changes: 2 additions & 0 deletions docs/providers/kubeless/guide/deploying.md
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ serverless deploy -v


Use this method when you have updated your Function, Event or Resource configuration in `serverless.yml` and you want to deploy that change (or multiple changes at the same time) to your Kubernetes cluster. Use this method when you have updated your Function, Event or Resource configuration in `serverless.yml` and you want to deploy that change (or multiple changes at the same time) to your Kubernetes cluster.


**Note:** You can specify a different configuration file name with the the `--config` option.

### How It Works ### How It Works


The Serverless Framework translates all syntax in `serverless.yml` to [the Function object API](https://github.com/kubeless/kubeless/blob/master/pkg/spec/spec.go) calls to provision your Functions and Events. The Serverless Framework translates all syntax in `serverless.yml` to [the Function object API](https://github.com/kubeless/kubeless/blob/master/pkg/spec/spec.go) calls to provision your Functions and Events.
Expand Down
4 changes: 2 additions & 2 deletions docs/providers/kubeless/guide/intro.md
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Anything that triggers an Kubeless Event to execute is regarded by the Framework


### Services ### Services


A **Service** is the Serverless Framework's unit of organization (not to be confused with [Kubernetes Services](https://kubernetes.io/docs/concepts/services-networking/service/). You can think of it as a project file, though you can have multiple services for a single application. It's where you define your Functions and the Events that trigger them, all in one file entitled `serverless.yml` (or `serverless.json` or `serverless.js`). It looks like this: A **Service** is the Serverless Framework's unit of organization (not to be confused with [Kubernetes Services](https://kubernetes.io/docs/concepts/services-networking/service/). You can think of it as a project file, though you can have multiple services for a single application. It's where you define your Functions and the Events that trigger them, all in one file by default entitled `serverless.yml` (or `serverless.json` or `serverless.js`). It looks like this:


```yml ```yml
# serverless.yml # serverless.yml
Expand All @@ -57,4 +57,4 @@ functions: # Your "Functions"
path: /hello path: /hello
``` ```


When you deploy with the Framework by running `serverless deploy`, everything in `serverless.yml` is deployed at once. When you deploy with the Framework by running `serverless deploy`, everything in `serverless.yml` (or the file specified with the `--config` option) is deployed at once.
1 change: 1 addition & 0 deletions docs/providers/openwhisk/cli-reference/deploy.md
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ serverless deploy
``` ```


## Options ## Options
- `--config` or `-c` Path to your conifguration file, if other than `serverless.yml|.yaml|.js|.json`.
- `--noDeploy` or `-n` Skips the deployment steps and leaves artifacts in the `.serverless` directory - `--noDeploy` or `-n` Skips the deployment steps and leaves artifacts in the `.serverless` directory
- `--verbose` or `-v` Shows all stack events during deployment, and display any Stack Output. - `--verbose` or `-v` Shows all stack events during deployment, and display any Stack Output.
- `--function` or `-f` Invoke `deploy function` (see above). Convenience shortcut - cannot be used with `--package`. - `--function` or `-f` Invoke `deploy function` (see above). Convenience shortcut - cannot be used with `--package`.
Expand Down
2 changes: 2 additions & 0 deletions docs/providers/openwhisk/guide/deploying.md
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ serverless deploy


Use this method when you have updated your Function, Event or Resource configuration in `serverless.yml` and you want to deploy that change (or multiple changes at the same time) to Apache OpenWhisk. Use this method when you have updated your Function, Event or Resource configuration in `serverless.yml` and you want to deploy that change (or multiple changes at the same time) to Apache OpenWhisk.


**Note:** You can specify a different configuration file name with the the `--config` option.

### How It Works ### How It Works


The Serverless Framework translates all syntax in `serverless.yml` to [platform API](http://petstore.swagger.io/?url=https://raw.githubusercontent.com/openwhisk/openwhisk/master/core/controller/src/main/resources/whiskswagger.json) calls to provision your Actions, Triggers, Rules and APIs. The Serverless Framework translates all syntax in `serverless.yml` to [platform API](http://petstore.swagger.io/?url=https://raw.githubusercontent.com/openwhisk/openwhisk/master/core/controller/src/main/resources/whiskswagger.json) calls to provision your Actions, Triggers, Rules and APIs.
Expand Down
4 changes: 2 additions & 2 deletions docs/providers/openwhisk/guide/intro.md
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ When you define an event for your Apache OpenWhisk Action in the Serverless Fram


### Services ### Services


A **Service** is the Framework's unit of organization. You can think of it as a project file, though you can have multiple services for a single application. It's where you define your Functions, the Events that trigger them, and the Resources your Functions use, all in one file entitled `serverless.yml` (or `serverless.json` or `serverless.js`). It looks like this: A **Service** is the Framework's unit of organization. You can think of it as a project file, though you can have multiple services for a single application. It's where you define your Functions, the Events that trigger them, and the Resources your Functions use, all in one file by default entitled `serverless.yml` (or `serverless.json` or `serverless.js`). It looks like this:


```yml ```yml
# serverless.yml # serverless.yml
Expand All @@ -62,7 +62,7 @@ functions: # Your "Functions"
events: events:
- http: delete /users/delete - http: delete /users/delete
``` ```
When you deploy with the Framework by running `serverless deploy`, everything in `serverless.yml` is deployed at once. When you deploy with the Framework by running `serverless deploy`, everything in `serverless.yml` (or the file specified with the `--config` option) is deployed at once.


### Plugins ### Plugins


Expand Down
1 change: 1 addition & 0 deletions docs/providers/spotinst/cli-reference/deploy.md
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ serverless deploy -v
``` ```


## Options ## Options
- `--config` or `-c` Path to your conifguration file, if other than `serverless.yml|.yaml|.js|.json`.
- `--package` or `-p` path to a pre-packaged directory and skip packaging step. - `--package` or `-p` path to a pre-packaged directory and skip packaging step.
- `--verbose` or `-v` Shows all stack events during deployment, and display any Stack Output. - `--verbose` or `-v` Shows all stack events during deployment, and display any Stack Output.
4 changes: 2 additions & 2 deletions docs/providers/spotinst/guide/intro.md
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ module.exports.main = function main (event, context, callback) {


### Services ### Services


A **Service** is the Framework's unit of organization. You can think of it as a project file, though you can have multiple services for a single application. It's where you define your Functions, the Events that trigger them, and the Resources your Functions use, all in one file entitled `serverless.yml` (or `serverless.json` or `serverless.js`). It looks like this: A **Service** is the Framework's unit of organization. You can think of it as a project file, though you can have multiple services for a single application. It's where you define your Functions, the Events that trigger them, and the Resources your Functions use, all in one file by default entitled `serverless.yml` (or `serverless.json` or `serverless.js`). It looks like this:


```yml ```yml


Expand All @@ -98,7 +98,7 @@ functions:
# key: value # key: value


``` ```
When you deploy with the Framework by running `serverless deploy`, everything in `serverless.yml` is deployed at once. When you deploy with the Framework by running `serverless deploy`, everything in `serverless.yml` (or the file specified with the `--config` option) is deployed at once.


### Plugins ### Plugins


Expand Down
4 changes: 3 additions & 1 deletion lib/Serverless.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const path = require('path');
const BbPromise = require('bluebird'); const BbPromise = require('bluebird');
const os = require('os'); const os = require('os');
const updateNotifier = require('update-notifier'); const updateNotifier = require('update-notifier');
const minimist = require('minimist');
const pkg = require('../package.json'); const pkg = require('../package.json');
const CLI = require('./classes/CLI'); const CLI = require('./classes/CLI');
const Config = require('./classes/Config'); const Config = require('./classes/Config');
Expand Down Expand Up @@ -31,7 +32,8 @@ class Serverless {
this.pluginManager = new PluginManager(this); this.pluginManager = new PluginManager(this);


// use the servicePath from the options or try to find it in the CWD // use the servicePath from the options or try to find it in the CWD
configObject.servicePath = configObject.servicePath || this.utils.findServicePath(); configObject.servicePath = configObject.servicePath ||
this.utils.findServicePath(minimist(process.argv.slice(2)).config);


this.config = new Config(this, configObject); this.config = new Config(this, configObject);


Expand Down
11 changes: 10 additions & 1 deletion lib/classes/CLI.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -152,7 +152,16 @@ class CLI {


displayCommandOptions(commandObject) { displayCommandOptions(commandObject) {
const dotsLength = 40; const dotsLength = 40;
_.forEach(commandObject.options, (optionsObject, option) => {
const commandOptions = commandObject.configDependent ?
Object.assign({}, commandObject.options, {
config: {
usage: 'Path to serverless config file',
shortcut: 'c',
},
}) : commandObject.options;

_.forEach(commandOptions, (optionsObject, option) => {
let optionsDots = _.repeat('.', dotsLength - option.length); let optionsDots = _.repeat('.', dotsLength - option.length);
const optionsUsage = optionsObject.usage; const optionsUsage = optionsObject.usage;


Expand Down
2 changes: 1 addition & 1 deletion lib/classes/PluginManager.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class PluginManager {


loadConfigFile() { loadConfigFile() {
return serverlessConfigFileUtils return serverlessConfigFileUtils
.getServerlessConfigFile(this.serverless.config.servicePath) .getServerlessConfigFile(this.serverless)
.then((serverlessConfigFile) => { .then((serverlessConfigFile) => {
this.serverlessConfigFile = serverlessConfigFile; this.serverlessConfigFile = serverlessConfigFile;
return; return;
Expand Down
58 changes: 11 additions & 47 deletions lib/classes/Service.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const path = require('path');
const _ = require('lodash'); const _ = require('lodash');
const BbPromise = require('bluebird'); const BbPromise = require('bluebird');
const semver = require('semver'); const semver = require('semver');
const serverlessConfigFileUtils = require('../utils/getServerlessConfigFile');


const validAPIGatewayStageNamePattern = /^[-_a-zA-Z0-9]+$/; const validAPIGatewayStageNamePattern = /^[-_a-zA-Z0-9]+$/;


Expand Down Expand Up @@ -46,73 +47,36 @@ class Service {
return BbPromise.resolve(); return BbPromise.resolve();
} }


// List of supported service filename variants. return BbPromise.all([
// The order defines the precedence. serverlessConfigFileUtils.getServerlessConfigFilePath(this.serverless),
const serviceFilenames = [ serverlessConfigFileUtils.getServerlessConfigFile(this.serverless),
'serverless.yaml', ]).then((args) => that.loadServiceFileParam(...args));
'serverless.yml',
'serverless.json',
'serverless.js',
];

const serviceFilePaths = _.map(serviceFilenames, filename => path.join(servicePath, filename));
const serviceFileIndex = _.findIndex(serviceFilePaths,
filename => this.serverless.utils.fileExistsSync(filename)
);

// Set the filename if found, otherwise set the preferred variant.
const serviceFilePath = serviceFileIndex !== -1 ?
serviceFilePaths[serviceFileIndex] :
_.first(serviceFilePaths);
const serviceFilename = serviceFileIndex !== -1 ?
serviceFilenames[serviceFileIndex] :
_.first(serviceFilenames);

if (serviceFilename === 'serverless.js') {
return BbPromise.try(() => {
// use require to load serverless.js file
// eslint-disable-next-line global-require
const configExport = require(serviceFilePath);
// In case of a promise result, first resolve it.
return configExport;
}).then(config => {
if (!_.isPlainObject(config)) {
throw new Error('serverless.js must export plain object');
}

return that.loadServiceFileParam(serviceFilename, config);
});
}

return that.serverless.yamlParser
.parse(serviceFilePath)
.then((serverlessFileParam) =>
that.loadServiceFileParam(serviceFilename, serverlessFileParam)
);
} }


loadServiceFileParam(serviceFilename, serverlessFileParam) { loadServiceFileParam(serviceFilename, serverlessFileParam) {
const that = this; const that = this;


that.serviceFilename = path.basename(serviceFilename);

const serverlessFile = serverlessFileParam; const serverlessFile = serverlessFileParam;
// basic service level validation // basic service level validation
const version = this.serverless.utils.getVersion(); const version = this.serverless.utils.getVersion();
const ymlVersion = serverlessFile.frameworkVersion; const ymlVersion = serverlessFile.frameworkVersion;
if (ymlVersion && !semver.satisfies(version, ymlVersion)) { if (ymlVersion && !semver.satisfies(version, ymlVersion)) {
const errorMessage = [ const errorMessage = [
`The Serverless version (${version}) does not satisfy the`, `The Serverless version (${version}) does not satisfy the`,
` "frameworkVersion" (${ymlVersion}) in ${serviceFilename}`, ` "frameworkVersion" (${ymlVersion}) in ${this.serviceFilename}`,
].join(''); ].join('');
throw new ServerlessError(errorMessage); throw new ServerlessError(errorMessage);
} }
if (!serverlessFile.service) { if (!serverlessFile.service) {
throw new ServerlessError(`"service" property is missing in ${serviceFilename}`); throw new ServerlessError(`"service" property is missing in ${this.serviceFilename}`);
} }
if (_.isObject(serverlessFile.service) && !serverlessFile.service.name) { if (_.isObject(serverlessFile.service) && !serverlessFile.service.name) {
throw new ServerlessError(`"service" is missing the "name" property in ${serviceFilename}`); // eslint-disable-line max-len throw new ServerlessError(`"service" is missing the "name" property in ${this.serviceFilename}`); // eslint-disable-line max-len
} }
if (!serverlessFile.provider) { if (!serverlessFile.provider) {
throw new ServerlessError(`"provider" property is missing in ${serviceFilename}`); throw new ServerlessError(`"provider" property is missing in ${this.serviceFilename}`);
} }


// ####################################################################### // #######################################################################
Expand Down