Skip to content

Commit

Permalink
change fileExists to be synchronous
Browse files Browse the repository at this point in the history
  • Loading branch information
maxgaurav committed May 19, 2022
1 parent d3d6ef7 commit 097d53f
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions actions/new.action.ts
Expand Up @@ -203,12 +203,11 @@ const initializeGitRepository = async (dir: string) => {
const createGitIgnoreFile = (dir: string, content?: string) => {
const fileContent = content || defaultGitIgnore;
const filePath = join(process.cwd(), dir, '.gitignore');
return fileExists(filePath).then(exists => {
if (!exists) {
return promisify(fs.writeFile)(filePath, fileContent);
}

if (fileExists(filePath)) {
return;
});
}
return promisify(fs.writeFile)(filePath, fileContent);
};

const printCollective = () => {
Expand Down Expand Up @@ -256,13 +255,16 @@ export const retrieveCols = () => {
};

const fileExists = (path: string) => {
return promisify(fs.access)(path).then(() => true).catch((err: any) => {
try{
fs.accessSync(path);
return true;
} catch (err: any) {
if (err.code === 'ENOENT') {
return false;
}

return Promise.reject(err);
});
throw err;
}
}

export const exit = () => process.exit(1);

0 comments on commit 097d53f

Please sign in to comment.