diff --git a/actions/new.action.ts b/actions/new.action.ts index e962deed2..044786eb0 100644 --- a/actions/new.action.ts +++ b/actions/new.action.ts @@ -203,6 +203,10 @@ const initializeGitRepository = async (dir: string) => { const createGitIgnoreFile = (dir: string, content?: string) => { const fileContent = content || defaultGitIgnore; const filePath = join(process.cwd(), dir, '.gitignore'); + + if (fileExists(filePath)) { + return; + } return promisify(fs.writeFile)(filePath, fileContent); }; @@ -250,4 +254,17 @@ export const retrieveCols = () => { } }; +const fileExists = (path: string) => { + try { + fs.accessSync(path); + return true; + } catch (err: any) { + if (err.code === 'ENOENT') { + return false; + } + + throw err; + } +}; + export const exit = () => process.exit(1);