Skip to content

Commit

Permalink
Merge pull request #1630 from maxgaurav/master
Browse files Browse the repository at this point in the history
add file exists check to prevent override of existing .gitignore file…
  • Loading branch information
kamilmysliwiec committed Jul 8, 2022
2 parents 54b0768 + 847192b commit 64f8334
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions actions/new.action.ts
Expand Up @@ -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);
};

Expand Down Expand Up @@ -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);

0 comments on commit 64f8334

Please sign in to comment.