Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add file exists check to prevent override of existing .gitignore file… #1630

Merged
merged 3 commits into from Jul 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const createGitIgnoreFile = (dir: string, content?: string) => {
const createGitIgnoreFile = async (dir: string, content?: string) => {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi sorry for the dealy in response. Got stuck in my main project. I have no problem doing it this way, I was just trying to get the flow what was already there. If needed I can change.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe async/await will be better to follow

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);