diff --git a/lib/plugins/create/create.js b/lib/plugins/create/create.js index 8da0f8a30..1bc0991e6 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) { diff --git a/lib/plugins/create/create.test.js b/lib/plugins/create/create.test.js index d35e8f4c5..5597ec357 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();