diff --git a/src/download-utils.js b/src/download-utils.js index 5d3f034..2b2ab2e 100644 --- a/src/download-utils.js +++ b/src/download-utils.js @@ -34,7 +34,7 @@ async function download_and_untar( // Delete the tarball fs.unlinkSync(full_path) - console.log(`✅ {${pkgname}} downloaded and extracted ----\n`); + console.log(`✅ {${pkgname}} downloaded and extracted ----`); } catch (error) { console.error('Error:', error.message); } diff --git a/src/init.js b/src/init.js index bf1cafa..1ee5b6e 100644 --- a/src/init.js +++ b/src/init.js @@ -1,18 +1,24 @@ const fs = require("fs"); const path = require("path"); const log = console.log; +const error = console.error; const { execSync } = require("child_process"); const {installIt} = require("./install"); const init = async (destination_folder) => { + // check if destination_folder does not exists + if (fs.existsSync(destination_folder)){ + error(`❌ A folder named ${destination_folder} already exists. \nPlease choose another name or remove the existing folder.`); + return false; + } + log("👉 Initializing project ----"); log("(This may take some time, please be patient)") // Making destination_folder folder full path destination_folder = path.resolve(destination_folder); - basename = path.basename(destination_folder); // creating the folder if it doesn't exist if (!fs.existsSync(destination_folder)){ diff --git a/src/install-utils.js b/src/install-utils.js index d033b7f..3776cc2 100644 --- a/src/install-utils.js +++ b/src/install-utils.js @@ -10,7 +10,7 @@ const installOnePackage = async function ( ) { // check if the package is already installed if (fs.existsSync(path.join(destination_folder, pkgname))) { - console.log(`❗️ Package {${pkgname}} is already installed`) + console.log(`❗️ {${pkgname}} is already installed`) return } diff --git a/tests/init.test.js b/tests/init.test.js index 15b5425..580c53d 100644 --- a/tests/init.test.js +++ b/tests/init.test.js @@ -60,4 +60,9 @@ test('init works', async () => { ) ).toBe(true); + // testing that the function return undefined + // if the folder already exists + const folder_can_be_created = await init(temp_dir); + expect(folder_can_be_created).toBe(false); + }, 1000000); \ No newline at end of file