Skip to content

Commit 9d5d5bb

Browse files
author
Anmol Shukla
committed
Enhancement (Code Refactor): Separated out the redundant directory check code into a separate function.
1 parent d10bc1c commit 9d5d5bb

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

src/commands/init.js

+19-11
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,10 @@ const showInstructions = kickStart => {
4646
};
4747

4848
/**
49-
* Initialize all the tasks
50-
*
51-
* @returns {Promise<void>}
49+
* Checks if there already is a directory called 'teachcode-solutions' in the present working directory
50+
* and errors out if that is the case.
5251
*/
53-
54-
const initTasks = async () => {
55-
await showBanner(
56-
'teachcode',
57-
` Learn to code effectively ${`\t`.repeat(4)} Powered by MadHacks`,
58-
);
59-
console.log();
60-
52+
const checkIfDirExists = () => {
6153
if (
6254
fs.existsSync(`${process.cwd()}/teachcode-solutions`) ||
6355
fs.existsSync(`${process.cwd()}/config.json`)
@@ -75,6 +67,22 @@ const initTasks = async () => {
7567
console.log();
7668
process.exit(1);
7769
}
70+
};
71+
72+
/**
73+
* Initialize all the tasks
74+
*
75+
* @returns {Promise<void>}
76+
*/
77+
78+
const initTasks = async () => {
79+
await showBanner(
80+
'teachcode',
81+
` Learn to code effectively ${`\t`.repeat(4)} Powered by MadHacks`,
82+
);
83+
console.log();
84+
85+
checkIfDirExists();
7886

7987
console.log();
8088
console.log(

0 commit comments

Comments
 (0)