diff --git a/lib/plugins/create/create.js b/lib/plugins/create/create.js index 8da0f8a30..409386721 100644 --- a/lib/plugins/create/create.js +++ b/lib/plugins/create/create.js @@ -69,6 +69,8 @@ class Create { 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 templateSrcDir = path.join(this.serverless.config.serverlessPath, + 'plugins', 'create', 'templates', this.options.template); // create (if not yet present) and chdir into the directory for the service if (boilerplatePath) { @@ -89,9 +91,7 @@ class Create { process.chdir(newPath); } else { // ensure no template file already exists in cwd that we may overwrite - const templateFullFilePaths = this.serverless.utils.walkDirSync(path.join( - this.serverless.config.serverlessPath, 'plugins', 'create', 'templates', - this.options.template)); + const templateFullFilePaths = this.serverless.utils.walkDirSync(templateSrcDir); templateFullFilePaths.forEach(ffp => { const filename = path.basename(ffp); @@ -111,8 +111,12 @@ class Create { // copy template files recursively to cwd // while keeping template file tree try { - this.serverless.utils.copyDirContentsSync(path.join(this.serverless.config.serverlessPath, - 'plugins', 'create', 'templates', this.options.template), process.cwd()); + this.serverless.utils.copyDirContentsSync(templateSrcDir, process.cwd()); + + // NPM renames .gitignore to .npmignore on publish so we have to rename it. + if (this.serverless.utils.fileExistsSync(`${process.cwd()}/gitignore`)) { + fse.rename(`${process.cwd()}/gitignore`, `${process.cwd()}/.gitignore`); + } } catch (err) { const errorMessage = [ 'Error unable to create a service in this directory. ', diff --git a/lib/plugins/create/templates/aws-csharp/.gitignore b/lib/plugins/create/templates/aws-csharp/gitignore similarity index 100% rename from lib/plugins/create/templates/aws-csharp/.gitignore rename to lib/plugins/create/templates/aws-csharp/gitignore diff --git a/lib/plugins/create/templates/aws-java-gradle/.gitignore b/lib/plugins/create/templates/aws-java-gradle/gitignore similarity index 100% rename from lib/plugins/create/templates/aws-java-gradle/.gitignore rename to lib/plugins/create/templates/aws-java-gradle/gitignore diff --git a/lib/plugins/create/templates/aws-java-maven/.gitignore b/lib/plugins/create/templates/aws-java-maven/gitignore similarity index 100% rename from lib/plugins/create/templates/aws-java-maven/.gitignore rename to lib/plugins/create/templates/aws-java-maven/gitignore diff --git a/lib/plugins/create/templates/aws-nodejs/.gitignore b/lib/plugins/create/templates/aws-nodejs/gitignore similarity index 100% rename from lib/plugins/create/templates/aws-nodejs/.gitignore rename to lib/plugins/create/templates/aws-nodejs/gitignore diff --git a/lib/plugins/create/templates/aws-python/.gitignore b/lib/plugins/create/templates/aws-python/gitignore similarity index 100% rename from lib/plugins/create/templates/aws-python/.gitignore rename to lib/plugins/create/templates/aws-python/gitignore diff --git a/lib/plugins/create/templates/aws-scala-sbt/.gitignore b/lib/plugins/create/templates/aws-scala-sbt/gitignore similarity index 100% rename from lib/plugins/create/templates/aws-scala-sbt/.gitignore rename to lib/plugins/create/templates/aws-scala-sbt/gitignore