@@ -5,7 +5,7 @@ const chalk = require('chalk');
5
5
const execa = require ( 'execa' ) ;
6
6
const inquirer = require ( 'inquirer' ) ;
7
7
8
- const validate = require ( '../utils /validate' ) ;
8
+ const validate = require ( './validate' ) ;
9
9
10
10
// Global reference to the GitHub username.
11
11
let GHUserName ;
@@ -27,8 +27,26 @@ const initializeGHWorkFlow = async () => {
27
27
// Holding global reference to the GitHub username.
28
28
GHUserName = userName ;
29
29
30
- // Check if the remote repository already exists and act accordingly.
31
- await checkIfRepositoryExists ( ) ;
30
+ // Check if it is a valid username
31
+ if ( ! ( await checkIfValidUser ( ) ) ) {
32
+ await initializeGHWorkFlow ( ) ;
33
+ }
34
+ } ;
35
+
36
+ /**
37
+ * Checks if the remote repository exists
38
+ *
39
+ * @returns {Promise<boolean> }
40
+ */
41
+
42
+ const checkIfValidUser = async ( ) => {
43
+ const API_URL = `https://api.github.com/users/${ GHUserName } ` ;
44
+ try {
45
+ await axios . get ( API_URL ) ;
46
+ return true ;
47
+ } catch ( err ) {
48
+ return false ;
49
+ }
32
50
} ;
33
51
34
52
/**
@@ -102,7 +120,7 @@ const configureLocalRepo = async () => {
102
120
const repoUrl = `https://github.com/${ GHUserName } /teachcode-solutions` ;
103
121
104
122
// Initialize an empty git repo.
105
- await execa ( 'git' , [ ' init'] ) ;
123
+ await execa . shell ( 'git init' ) ;
106
124
107
125
// Set the remote url.
108
126
await execa . shell ( `git remote add origin ${ repoUrl } ` ) ;
0 commit comments