1
1
const clear = require ( "clear" ) ;
2
- const figlet = require ( "figlet" ) ;
3
2
const cowsay = require ( "cowsay" ) ;
4
3
const files = require ( "../lib/files.js" ) ;
5
4
const program = require ( "commander" ) ;
6
5
const { 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" ) ( ) ;
9
8
const { jsonReader } = require ( "../lib/funcs/jsonReader.js" ) ;
10
9
const version = require ( "../../package.json" ) ;
11
10
const chalk = require ( "chalk" ) ;
12
11
const { exec } = require ( "child_process" ) ;
13
12
const fs = require ( "fs" ) ;
13
+ import { GitGoConf } from "../types" ;
14
14
15
15
clear ( ) ;
16
16
17
17
program
18
18
. command ( "start" )
19
19
. alias ( "s" )
20
- . action ( function ( ) {
20
+ . action ( ( ) => {
21
21
// displays Gitg0 on start
22
22
if ( files . directoryExists ( ".git" ) ) {
23
- console . log (
24
- figlet . textSync ( "Gitg0" , {
25
- horizontalLayout : "default" ,
26
- verticalLayout : "default" ,
27
- } ) ,
28
- "\n"
29
- ) ;
23
+ logLogo ( ) ;
30
24
getQuestions ( ) ;
31
25
} else {
32
26
// checks if the directory is a git based repo or not
@@ -43,21 +37,15 @@ program
43
37
program
44
38
. command ( "config" )
45
39
. alias ( "c" )
46
- . action ( function ( ) {
40
+ . action ( async ( ) => {
47
41
// displays Gitg0 on start
48
42
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" ) {
61
49
// file does not exist
62
50
var conf = {
63
51
current_issue : {
@@ -91,16 +79,17 @@ program
91
79
use_emojis : false ,
92
80
commit_config : false ,
93
81
} ;
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
+ }
98
88
} else {
99
89
console . log ( "Some other error: " , err . code ) ;
100
90
}
101
- } ) ;
91
+ }
102
92
} else {
103
- // checks if the directory is a git based repo or not
104
93
console . log (
105
94
cowsay . say ( {
106
95
text : "Not a git repository!" ,
@@ -114,16 +103,10 @@ program
114
103
program
115
104
. command ( "display" )
116
105
. alias ( "d" )
117
- . action ( function ( ) {
106
+ . action ( ( ) => {
118
107
// displays Gitg0 on start
119
108
if ( files . directoryExists ( ".git" ) ) {
120
- console . log (
121
- figlet . textSync ( "Gitg0" , {
122
- horizontalLayout : "default" ,
123
- verticalLayout : "default" ,
124
- } ) ,
125
- "\n"
126
- ) ;
109
+ logLogo ( ) ;
127
110
// asks task based questions
128
111
displaySuggestions ( ) ;
129
112
} else {
@@ -144,14 +127,8 @@ program
144
127
. action ( function ( ) {
145
128
// displays Gitg0 on start
146
129
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 ) => {
155
132
if ( err ) {
156
133
console . log ( "Error reading file:" , err ) ;
157
134
return ;
@@ -178,14 +155,8 @@ program
178
155
. action ( function ( ) {
179
156
// displays Gitg0 on start
180
157
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 ) => {
189
160
if ( err ) {
190
161
console . log ( "Error reading file:" , err ) ;
191
162
return ;
@@ -194,17 +165,19 @@ program
194
165
if ( conf . commit_config ) {
195
166
conf . commit_config = false ;
196
167
conf . current_commit_message = "" ;
197
- conf . current_branch = [ "" ] ;
168
+ conf . current_branch = "" ;
198
169
conf . existing_branches = [ "" ] ;
199
170
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 ) => {
204
177
if ( err ) console . log ( "Error writing file:" , err ) ;
205
178
} ) ;
206
179
setTimeout ( function ( ) {
207
- exec ( "git add ./.gitgo" , ( error , stdout , stderr ) => {
180
+ exec ( "git add ./.gitgo" , ( error : Error , stdout : any , stderr : Error ) => {
208
181
if ( error ) {
209
182
console . log ( `error: ${ error . message } ` ) ;
210
183
return ;
@@ -218,7 +191,7 @@ program
218
191
console . log ( "Files have be commited!\nRecent commit message: " + cMsg ) ;
219
192
} , 1000 ) ;
220
193
} else {
221
- exec ( "git reset -- ./.gitgo" , ( error , stdout , stderr ) => {
194
+ exec ( "git reset -- ./.gitgo" , ( error : Error , stdout : any , stderr : Error ) => {
222
195
if ( error ) {
223
196
console . log ( `error: ${ error . message } ` ) ;
224
197
return ;
@@ -249,13 +222,7 @@ program
249
222
. alias ( "v" )
250
223
. action ( function ( ) {
251
224
// displays Gitg0 on start
252
- console . log (
253
- figlet . textSync ( "Gitg0" , {
254
- horizontalLayout : "default" ,
255
- verticalLayout : "default" ,
256
- } ) ,
257
- "\n"
258
- ) ;
225
+ logLogo ( ) ;
259
226
console . log ( "v" + version . version + "-stable" ) ;
260
227
} ) ;
261
228
@@ -264,13 +231,7 @@ program
264
231
. alias ( "w" )
265
232
. action ( function ( ) {
266
233
// displays Gitg0 on start
267
- console . log (
268
- figlet . textSync ( "Gitg0" , {
269
- horizontalLayout : "default" ,
270
- verticalLayout : "default" ,
271
- } ) ,
272
- "\n"
273
- ) ;
234
+ logLogo ( ) ;
274
235
console . log (
275
236
`You just need to know 7 simple commands you and then you're ${ chalk . bold . cyan (
276
237
"gtg"
0 commit comments