-
Notifications
You must be signed in to change notification settings - Fork 380
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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{ | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
fs.accessSync(path); | ||||||
return true; | ||||||
} catch (err: any) { | ||||||
if (err.code === 'ENOENT') { | ||||||
return false; | ||||||
} | ||||||
|
||||||
throw err; | ||||||
} | ||||||
} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On a separate note, this whole gitignore problem is there as the npm does not copy .gitignore files to the distributions. Since we are using angular schematics which allows template prefix/suffix to be added which can be automatically removed through the schematics build process. I have achieved the same for my collection Would it be okay that do the same for the nestjs schematics as well by opening a PR which can allow managing of .gitignore file through schematics. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure! I'll close the PR #1649 then Which means that we can close this PR as well, right? then after your fix on that schematics issue, we could open another one to drop the workaround implemented on this repo There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, makes sense. But form then the responsibility of having .gitingore file will be to the schematics, if not provided then gitingore will not be there in the project structure. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Once I complete the functionality I will map the pull request here for refernce. |
||||||
|
||||||
export const exit = () => process.exit(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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