11const clear = require ( "clear" ) ;
2- const figlet = require ( "figlet" ) ;
32const cowsay = require ( "cowsay" ) ;
43const files = require ( "../lib/files.js" ) ;
54const program = require ( "commander" ) ;
65const { getQuestions, getConfigQuestions, displaySuggestions } = require ( "../lib/inquirer.js" ) ;
7- const simpleGit = require ( "simple-git " ) ;
8- const git = simpleGit ( ) ;
6+ const logLogo = require ( "../lib/funcs/logLogo " ) ;
7+ const git = require ( "simple-git" ) ( ) ;
98const { jsonReader } = require ( "../lib/funcs/jsonReader.js" ) ;
109const version = require ( "../../package.json" ) ;
1110const chalk = require ( "chalk" ) ;
1211const { exec } = require ( "child_process" ) ;
1312const fs = require ( "fs" ) ;
13+ import { GitGoConf } from "../types" ;
1414
1515clear ( ) ;
1616
1717program
1818 . command ( "start" )
1919 . alias ( "s" )
20- . action ( function ( ) {
20+ . action ( ( ) => {
2121 // displays Gitg0 on start
2222 if ( files . directoryExists ( ".git" ) ) {
23- console . log (
24- figlet . textSync ( "Gitg0" , {
25- horizontalLayout : "default" ,
26- verticalLayout : "default" ,
27- } ) ,
28- "\n"
29- ) ;
23+ logLogo ( ) ;
3024 getQuestions ( ) ;
3125 } else {
3226 // checks if the directory is a git based repo or not
@@ -43,21 +37,15 @@ program
4337program
4438 . command ( "config" )
4539 . alias ( "c" )
46- . action ( function ( ) {
40+ . action ( async ( ) => {
4741 // displays Gitg0 on start
4842 if ( files . directoryExists ( ".git" ) ) {
49- console . log (
50- figlet . textSync ( "Gitg0" , {
51- horizontalLayout : "default" ,
52- verticalLayout : "default" ,
53- } ) ,
54- "\n"
55- ) ;
56- fs . stat ( "./.gitgo" , function ( err , stat ) {
57- if ( err == null ) {
58- // asks task based questions
59- getConfigQuestions ( ) ;
60- } else if ( err . code === "ENOENT" ) {
43+ try {
44+ logLogo ( ) ;
45+ await fs . stat ( "./.gitgo" ) ;
46+ getConfigQuestions ( ) ;
47+ } catch ( err ) {
48+ if ( err . code === "ENOENT" ) {
6149 // file does not exist
6250 var conf = {
6351 current_issue : {
@@ -91,16 +79,17 @@ program
9179 use_emojis : false ,
9280 commit_config : false ,
9381 } ;
94- fs . writeFile ( "./.gitgo" , JSON . stringify ( conf , null , 2 ) , ( err ) => {
95- if ( err ) console . log ( "Error writing file:" , err ) ;
96- } ) ;
97- getConfigQuestions ( ) ;
82+ try {
83+ await fs . writeFile ( "./.gitgo" , JSON . stringify ( conf , null , 2 ) ) ;
84+ getConfigQuestions ( ) ;
85+ } catch ( e ) {
86+ console . log ( "Error writing file: " , e ) ;
87+ }
9888 } else {
9989 console . log ( "Some other error: " , err . code ) ;
10090 }
101- } ) ;
91+ }
10292 } else {
103- // checks if the directory is a git based repo or not
10493 console . log (
10594 cowsay . say ( {
10695 text : "Not a git repository!" ,
@@ -114,16 +103,10 @@ program
114103program
115104 . command ( "display" )
116105 . alias ( "d" )
117- . action ( function ( ) {
106+ . action ( ( ) => {
118107 // displays Gitg0 on start
119108 if ( files . directoryExists ( ".git" ) ) {
120- console . log (
121- figlet . textSync ( "Gitg0" , {
122- horizontalLayout : "default" ,
123- verticalLayout : "default" ,
124- } ) ,
125- "\n"
126- ) ;
109+ logLogo ( ) ;
127110 // asks task based questions
128111 displaySuggestions ( ) ;
129112 } else {
@@ -144,14 +127,8 @@ program
144127 . action ( function ( ) {
145128 // displays Gitg0 on start
146129 if ( files . directoryExists ( ".git" ) ) {
147- console . log (
148- figlet . textSync ( "Gitg0" , {
149- horizontalLayout : "default" ,
150- verticalLayout : "default" ,
151- } ) ,
152- "\n"
153- ) ;
154- jsonReader ( "./.gitgo" , ( err , conf ) => {
130+ logLogo ( ) ;
131+ jsonReader ( "./.gitgo" , ( err : Error , conf : GitGoConf ) => {
155132 if ( err ) {
156133 console . log ( "Error reading file:" , err ) ;
157134 return ;
@@ -178,14 +155,8 @@ program
178155 . action ( function ( ) {
179156 // displays Gitg0 on start
180157 if ( files . directoryExists ( ".git" ) ) {
181- console . log (
182- figlet . textSync ( "Gitg0" , {
183- horizontalLayout : "default" ,
184- verticalLayout : "default" ,
185- } ) ,
186- "\n"
187- ) ;
188- jsonReader ( "./.gitgo" , ( err , conf ) => {
158+ logLogo ( ) ;
159+ jsonReader ( "./.gitgo" , ( err : Error , conf : GitGoConf ) => {
189160 if ( err ) {
190161 console . log ( "Error reading file:" , err ) ;
191162 return ;
@@ -194,17 +165,19 @@ program
194165 if ( conf . commit_config ) {
195166 conf . commit_config = false ;
196167 conf . current_commit_message = "" ;
197- conf . current_branch = [ "" ] ;
168+ conf . current_branch = "" ;
198169 conf . existing_branches = [ "" ] ;
199170 conf . selected_commit_type = "" ;
200- conf . current_issue . number = "" ;
201- conf . current_issue . labels = [ "" ] ;
202- conf . current_issue . title = "" ;
203- fs . writeFile ( "./.gitgo" , JSON . stringify ( conf , null , 2 ) , ( err ) => {
171+ conf . current_issue = {
172+ number : undefined ,
173+ labels : [ "" ] ,
174+ title : "" ,
175+ } ;
176+ fs . writeFile ( "./.gitgo" , JSON . stringify ( conf , null , 2 ) , ( err : Error ) => {
204177 if ( err ) console . log ( "Error writing file:" , err ) ;
205178 } ) ;
206179 setTimeout ( function ( ) {
207- exec ( "git add ./.gitgo" , ( error , stdout , stderr ) => {
180+ exec ( "git add ./.gitgo" , ( error : Error , stdout : any , stderr : Error ) => {
208181 if ( error ) {
209182 console . log ( `error: ${ error . message } ` ) ;
210183 return ;
@@ -218,7 +191,7 @@ program
218191 console . log ( "Files have be commited!\nRecent commit message: " + cMsg ) ;
219192 } , 1000 ) ;
220193 } else {
221- exec ( "git reset -- ./.gitgo" , ( error , stdout , stderr ) => {
194+ exec ( "git reset -- ./.gitgo" , ( error : Error , stdout : any , stderr : Error ) => {
222195 if ( error ) {
223196 console . log ( `error: ${ error . message } ` ) ;
224197 return ;
@@ -249,13 +222,7 @@ program
249222 . alias ( "v" )
250223 . action ( function ( ) {
251224 // displays Gitg0 on start
252- console . log (
253- figlet . textSync ( "Gitg0" , {
254- horizontalLayout : "default" ,
255- verticalLayout : "default" ,
256- } ) ,
257- "\n"
258- ) ;
225+ logLogo ( ) ;
259226 console . log ( "v" + version . version + "-stable" ) ;
260227 } ) ;
261228
@@ -264,13 +231,7 @@ program
264231 . alias ( "w" )
265232 . action ( function ( ) {
266233 // displays Gitg0 on start
267- console . log (
268- figlet . textSync ( "Gitg0" , {
269- horizontalLayout : "default" ,
270- verticalLayout : "default" ,
271- } ) ,
272- "\n"
273- ) ;
234+ logLogo ( ) ;
274235 console . log (
275236 `You just need to know 7 simple commands you and then you're ${ chalk . bold . cyan (
276237 "gtg"
0 commit comments