diff --git a/local-cli/generator/copyProjectTemplateAndReplace.js b/local-cli/generator/copyProjectTemplateAndReplace.js index d202434d4..b169736c0 100644 --- a/local-cli/generator/copyProjectTemplateAndReplace.js +++ b/local-cli/generator/copyProjectTemplateAndReplace.js @@ -39,11 +39,10 @@ function copyProjectTemplateAndReplace(srcPath, destPath, newProjectName, option } const relativeFilePath = path.relative(srcPath, absoluteSrcFilePath); - const relativeRenamedPath = relativeFilePath + const relativeRenamedPath = dotFilePath(relativeFilePath) .replace(/HelloWorld/g, newProjectName) .replace(/helloworld/g, newProjectName.toLowerCase()); - let contentChangedCallback = null; if (options && options.upgrade && (!options.force)) { contentChangedCallback = (_, contentChanged) => { @@ -66,6 +65,24 @@ function copyProjectTemplateAndReplace(srcPath, destPath, newProjectName, option }); } +/** + * There are various dotfiles in the templates folder in the RN repo. We want + * these to be ignored by tools when working with React Native itself. + * Example: _babelrc file is ignored by Babel, renamed to .babelrc inside + * a real app folder. + * This is especially important for .gitignore because npm has some special + * behavior of automatically renaming .gitignore to .npmignore. + */ +function dotFilePath(path) { + if (!path) return path; + return path + .replace('_gitignore', '.gitignore') + .replace('_babelrc', '.babelrc') + .replace('_flowconfig', '.flowconfig') + .replace('_buckconfig', '.buckconfig') + .replace('_watchmanconfig', '.watchmanconfig'); +} + function upgradeFileContentChangedCallback( absoluteSrcFilePath, relativeDestPath, diff --git a/local-cli/templates/HelloWorld/.babelrc b/local-cli/templates/HelloWorld/_babelrc similarity index 100% rename from local-cli/templates/HelloWorld/.babelrc rename to local-cli/templates/HelloWorld/_babelrc diff --git a/local-cli/templates/HelloWorld/.buckconfig b/local-cli/templates/HelloWorld/_buckconfig similarity index 100% rename from local-cli/templates/HelloWorld/.buckconfig rename to local-cli/templates/HelloWorld/_buckconfig diff --git a/local-cli/templates/HelloWorld/.flowconfig b/local-cli/templates/HelloWorld/_flowconfig similarity index 100% rename from local-cli/templates/HelloWorld/.flowconfig rename to local-cli/templates/HelloWorld/_flowconfig diff --git a/local-cli/templates/HelloWorld/.gitignore b/local-cli/templates/HelloWorld/_gitignore similarity index 100% rename from local-cli/templates/HelloWorld/.gitignore rename to local-cli/templates/HelloWorld/_gitignore diff --git a/local-cli/templates/HelloWorld/.watchmanconfig b/local-cli/templates/HelloWorld/_watchmanconfig similarity index 100% rename from local-cli/templates/HelloWorld/.watchmanconfig rename to local-cli/templates/HelloWorld/_watchmanconfig