Repository: serverless/serverless (JavaScript)
Date: 2017-01-06 14:36:56+00:00
Task type: Bug Fix

Issue:
Serverless ignores path argument which starts with a digit
# This is a Bug Report

## Description

For bug reports:
* What went wrong?

When I create a new project from template it ignores my `--path` param if it starts with a digit.

```bash
$ serverless create --template aws-nodejs --path 123
```

```bash
$ ls -a
$ .  ..  handler.js  .npmignore  serverless.yml
```


* What did you expect should have happened?


I expected that template will be created in a dir I provided, even if it starts with a digit. 

```bash
$ ls -a
$ .  ..  123
```

* What was the config you used?

All default.

* What stacktrace or error message from your provider did you see?

No error stacktrace.

Similar or dependent issues:
* haven't found

## Additional Data

* ***Serverless Framework Version you're using***: 1.4.0
* ***Operating System***: Ubuntu 16.10
* ***Stack Trace***: no
* ***Provider Error messages***: no

After looking into sources, I guess the reason is here:

```js
const boilerplatePath = this.options
      .path && this.options.path.length ? this.options.path : null;
```
Serverless ignores path argument which starts with a digit
# This is a Bug Report

## Description

For bug reports:
* What went wrong?

When I create a new project from template it ignores my `--path` param if it starts with a digit.

```bash
$ serverless create --template aws-nodejs --path 123
```

```bash
$ ls -a
$ .  ..  handler.js  .npmignore  serverless.yml
```


* What did you expect should have happened?


I expected that template will be created in a dir I provided, even if it starts with a digit. 

```bash
$ ls -a
$ .  ..  123
```

* What was the config you used?

All default.

* What stacktrace or error message from your provider did you see?

No error stacktrace.

Similar or dependent issues:
* haven't found

## Additional Data

* ***Serverless Framework Version you're using***: 1.4.0
* ***Operating System***: Ubuntu 16.10
* ***Stack Trace***: no
* ***Provider Error messages***: no

After looking into sources, I guess the reason is here:

```js
const boilerplatePath = this.options
      .path && this.options.path.length ? this.options.path : null;
```


Issue discussion:

Solution patch:
diff --git a/lib/plugins/create/create.js b/lib/plugins/create/create.js
index 8da0f8a306c..1bc0991e625 100644
--- a/lib/plugins/create/create.js
+++ b/lib/plugins/create/create.js
@@ -3,6 +3,7 @@
 const BbPromise = require('bluebird');
 const path = require('path');
 const fse = require('fs-extra');
+const _ = require('lodash');
 
 // class wide constants
 const validTemplates = [
@@ -66,9 +67,8 @@ class Create {
     }
 
     // store the custom options for the service if given
-    const boilerplatePath = this.options
-      .path && this.options.path.length ? this.options.path : null;
-    const serviceName = this.options.name && this.options.name.length ? this.options.name : null;
+    const boilerplatePath = _.toString(this.options.path);
+    const serviceName = _.toString(this.options.name);
 
     // create (if not yet present) and chdir into the directory for the service
     if (boilerplatePath) {


Test patch:
diff --git a/lib/plugins/create/create.test.js b/lib/plugins/create/create.test.js
index d35e8f4c526..5597ec35765 100644
--- a/lib/plugins/create/create.test.js
+++ b/lib/plugins/create/create.test.js
@@ -311,6 +311,30 @@ describe('Create', () => {
       });
     });
 
+    it('should create a service in the directory if using the "path" option with digits', () => {
+      const cwd = process.cwd();
+      fse.mkdirsSync(tmpDir);
+      process.chdir(tmpDir);
+
+      create.options.path = 123;
+      create.options.name = null;
+
+      // using the nodejs template (this test is completely be independent from the template)
+      create.options.template = 'aws-nodejs';
+
+      return create.create().then(() => {
+        const serviceDir = path.join(tmpDir, String(create.options.path));
+
+        // check if files are created in the correct directory
+        expect(create.serverless.utils.fileExistsSync(
+          path.join(serviceDir, 'serverless.yml'))).to.be.equal(true);
+        expect(create.serverless.utils.fileExistsSync(
+          path.join(serviceDir, 'handler.js'))).to.be.equal(true);
+
+        process.chdir(cwd);
+      });
+    });
+
     it('should create a custom renamed service in the directory if using ' +
        'the "path" and "name" option', () => {
       const cwd = process.cwd();