Skip to content

Commit

Permalink
add file exists check to prevent override of existing .gitignore file…
Browse files Browse the repository at this point in the history
… within collection
  • Loading branch information
maxgaurav committed Apr 29, 2022
1 parent 94b0c03 commit d3d6ef7
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion actions/new.action.ts
Expand Up @@ -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 = () => {
Expand Down Expand Up @@ -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);

0 comments on commit d3d6ef7

Please sign in to comment.