11'use strict' ;
22
33const chalk = require ( 'chalk' ) ;
4- const { execSync } = require ( 'child_process ' ) ;
4+ const { shellSync } = require ( 'execa ' ) ;
55const fs = require ( 'fs' ) ;
66const inquirer = require ( 'inquirer' ) ;
77const showBanner = require ( 'node-banner' ) ;
88const open = require ( 'open' ) ;
9+ const ora = require ( 'ora' ) ;
910
1011// GitHub workflow helper methods.
1112const {
@@ -44,6 +45,12 @@ const showInstructions = () => {
4445 console . log ( chalk . cyan . bold ( ` 2. teachcode fetchtask` ) ) ;
4546} ;
4647
48+ /**
49+ * Opens up the default browser with information concerning
50+ * access token creation as required
51+ * @returns {Promise<void> }
52+ */
53+
4754const promptAccessTokenCreation = async ( ) => {
4855 const instructionsUrl =
4956 'https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line' ;
@@ -87,13 +94,10 @@ const initTasks = async () => {
8794 console . log (
8895 chalk . redBright (
8996 ` It seems that there is already a ${ chalk . yellow (
90- 'Teach-Code -solutions' ,
97+ 'teachcode -solutions' ,
9198 ) } directory or ${ chalk . yellow ( 'config.json' ) } file existing in path`,
9299 ) ,
93100 ) ;
94- console . log ( ) ;
95- console . log ( chalk . redBright ( ' Exiting!!' ) ) ;
96- console . log ( ) ;
97101 process . exit ( 1 ) ;
98102 }
99103
@@ -133,9 +137,10 @@ const initTasks = async () => {
133137 ...userConfig ,
134138 learningTrack : learningTrackOfChoice ,
135139 userName,
136- keys : userConfig . keys . push ( key ) ,
137140 } ;
138141
142+ userConfig . keys . push ( key ) ;
143+
139144 // Prompt for GitHub username.
140145 await initializeGHWorkFlow ( ) ;
141146
@@ -146,17 +151,22 @@ const initTasks = async () => {
146151 await promptAccessTokenCreation ( ) ;
147152 await createRepository ( ) ;
148153
149- execSync ( `mkdir -p teachcode-solutions` ) ;
154+ shellSync ( `mkdir teachcode-solutions` ) ;
150155 fs . writeFileSync (
151- ` teachcode-solutions/config.json` ,
156+ ' teachcode-solutions/config.json' ,
152157 JSON . stringify ( userConfig , null , 2 ) ,
153158 ) ;
154-
155- process . chdir ( 'teachcode-solutions' ) ;
156159 await configureLocalRepo ( ) ;
157160 } else {
158- // Clone the remote repository
159- await cloneRepository ( ) ;
161+ const spinner = ora ( 'Fetching user progress' ) . start ( ) ;
162+ try {
163+ // Clone the remote repository
164+ await cloneRepository ( ) ;
165+ } catch ( err ) {
166+ spinner . fail ( 'Something went wrong' ) ;
167+ throw err ;
168+ }
169+ spinner . stop ( ) ;
160170 }
161171 showInstructions ( ) ;
162172} ;
0 commit comments