From 097d53f2678b6385dd43b14e036b3c2ff01fa712 Mon Sep 17 00:00:00 2001 From: Max Gaurav Date: Thu, 19 May 2022 09:59:32 +0530 Subject: [PATCH] change fileExists to be synchronous --- actions/new.action.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/actions/new.action.ts b/actions/new.action.ts index 23648b0f1..6817b51d2 100644 --- a/actions/new.action.ts +++ b/actions/new.action.ts @@ -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 = () => { @@ -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);