Store .gitignore as gitignore in template dir

This commit is contained in:
Vlad Golubev 2017-01-06 17:24:44 +02:00
parent 0d8910ec4b
commit da18517fcd
7 changed files with 9 additions and 5 deletions

View File

@ -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. ',