diff --git a/actions/new.action.ts b/actions/new.action.ts index e962deed2..23648b0f1 100644 --- a/actions/new.action.ts +++ b/actions/new.action.ts @@ -203,7 +203,12 @@ const initializeGitRepository = async (dir: string) => { const createGitIgnoreFile = (dir: string, content?: string) => { const fileContent = content || defaultGitIgnore; const filePath = join(process.cwd(), dir, '.gitignore'); - return promisify(fs.writeFile)(filePath, fileContent); + return fileExists(filePath).then(exists => { + if (!exists) { + return promisify(fs.writeFile)(filePath, fileContent); + } + return; + }); }; const printCollective = () => { @@ -250,4 +255,14 @@ export const retrieveCols = () => { } }; +const fileExists = (path: string) => { + return promisify(fs.access)(path).then(() => true).catch((err: any) => { + if (err.code === 'ENOENT') { + return false; + } + + return Promise.reject(err); + }); +} + export const exit = () => process.exit(1);