From bed1b67b500bf2fcca3ce028da184132f2c24dc9 Mon Sep 17 00:00:00 2001 From: mcorrello <51805843+mcorrello@users.noreply.github.com> Date: Wed, 8 Feb 2023 11:59:34 -0500 Subject: [PATCH 1/2] feat: check if gitignore exists before renaming --- cli.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/cli.js b/cli.js index f5644acb..2daab505 100644 --- a/cli.js +++ b/cli.js @@ -40,13 +40,15 @@ const editFiles = async projectName => { file.set('name', projectName); file.save(); - fs.rename( - `${__dirname}/starter-kit/gitignore`, - `${__dirname}/starter-kit/.gitignore`, - function (err) { - if (err) throw err; - } - ); + if (fs.existsSync(`${__dirname}/starter-kit/gitignore`)) { + fs.rename( + `${__dirname}/starter-kit/gitignore`, + `${__dirname}/starter-kit/.gitignore`, + function (err) { + if (err) throw err; + } + ); + } }; const checkDirectory = async () => { From 104c3e7c742ec344380d1bc37751dee28fc54c2c Mon Sep 17 00:00:00 2001 From: mcorrello <51805843+mcorrello@users.noreply.github.com> Date: Wed, 8 Feb 2023 12:00:12 -0500 Subject: [PATCH 2/2] feat: check if project name exists in directory --- cli.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/cli.js b/cli.js index 2daab505..be480e35 100644 --- a/cli.js +++ b/cli.js @@ -67,7 +67,13 @@ const checkDirectory = async () => { } }; -const successText = projectName => { +const checkProjectName = async (projectPath) => { + if (fs.existsSync(projectPath)) { + throw `ERROR: Project already exists in directory:: ${projectPath}`; + } +}; + +const successText = (projectName) => { const successText = `Success! Created ${chalk.cyan( projectName )} at ${chalk.cyan(CURR_DIR)} @@ -95,6 +101,8 @@ const run = async () => { const starterKitPath = `${__dirname}/starter-kit/`; + await checkProjectName(`${CURR_DIR}/${projectName}`); + await editFiles(projectName); await asyncMkdir(`${CURR_DIR}/${projectName}`);