Merge pull request #3065 from vladgolubev/preserve-gitignore-on-npm-publish

Store .gitignore as gitignore in template dir. Rename on template creation
This commit is contained in:
Eslam λ Hefnawy 2017-03-13 19:27:16 +08:00 committed by GitHub
commit 9e271999a7
7 changed files with 9 additions and 5 deletions

View File

@ -71,6 +71,8 @@ class Create {
// store the custom options for the service if given
const boilerplatePath = _.toString(this.options.path);
const serviceName = _.toString(this.options.name);
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) {
@ -91,9 +93,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);
@ -113,8 +113,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. ',