@@ -52,9 +52,7 @@ findPkg()
52
52
if ( ! val ) {
53
53
console . log ( 'Deleting script.' ) ;
54
54
delete scripts [ script ] ;
55
- } else {
56
- scripts [ script ] = val ;
57
- }
55
+ } else scripts [ script ] = val ;
58
56
return fs . writeJson ( pkgPath , pkg ) ;
59
57
} ) ;
60
58
} )
@@ -64,23 +62,8 @@ findPkg()
64
62
} ) ;
65
63
66
64
function getScriptName ( ) {
67
- if ( script ) {
68
- // Verify creation if the script does not exist:
69
- return inquirer . prompt ( [
70
- {
71
- type : 'confirm' ,
72
- name : 'create' ,
73
- message : `The script "${ script } " does not exist. Create it?` ,
74
- when : ! scripts [ script ] ,
75
- } ,
76
- ] )
77
- . then ( function ( answers ) {
78
- if ( ! answers . create ) {
79
- console . log ( 'Aborting' ) ;
80
- process . exit ( ) ;
81
- }
82
- } ) ;
83
- } else {
65
+ if ( script && ! scripts [ script ] ) return confirmCreation ( ) ;
66
+ else {
84
67
// Get choices:
85
68
var choices = Object . keys ( scripts ) . map ( function ( key ) {
86
69
return {
@@ -110,36 +93,50 @@ function getScriptName() {
110
93
] )
111
94
. then ( function ( answers ) {
112
95
switch ( answers . script ) {
113
- case NEW_SCRIPT_SYMBOL :
96
+ case NEW_SCRIPT_SYMBOL :
114
97
// Get script name:
115
- return inquirer . prompt ( [ {
116
- type : 'input' ,
117
- name : 'name' ,
118
- message : 'Enter the script name:' ,
119
- validate : function ( val ) {
120
- if ( ! val ) return 'Script name must not be empty' ;
121
- else return true ;
122
- } ,
123
- } ] )
98
+ return inquirer . prompt ( [ {
99
+ type : 'input' ,
100
+ name : 'name' ,
101
+ message : 'Enter the script name:' ,
102
+ validate : function ( val ) {
103
+ if ( ! val ) return 'Script name must not be empty' ;
104
+ else return true ;
105
+ } ,
106
+ } ] )
124
107
. then ( function ( answers ) {
125
108
// Set it:
126
109
script = answers . name ;
127
110
} ) ;
128
- case EXIT_SYMBOL :
129
- process . exit ( ) ;
130
- default :
131
- script = answers . script ;
111
+ case EXIT_SYMBOL :
112
+ return process . exit ( ) ;
113
+ default :
114
+ script = answers . script ;
132
115
}
133
116
} ) ;
134
117
}
135
118
}
136
119
120
+ function confirmCreation ( ) {
121
+ return inquirer . prompt ( [
122
+ {
123
+ type : 'confirm' ,
124
+ name : 'create' ,
125
+ message : `The script "${ script } " does not exist. Create it?` ,
126
+ } ,
127
+ ] )
128
+ . then ( function ( answers ) {
129
+ if ( ! answers . create ) {
130
+ console . log ( 'Aborting' ) ;
131
+ process . exit ( ) ;
132
+ }
133
+ } ) ;
134
+ }
135
+
137
136
function pad ( str1 , str2 ) {
138
137
var padLen = 60 - ( str1 . length + str2 . length ) ;
139
138
// Ensure at least one space:
140
139
var pad = ' ' ;
141
- for ( var i = 1 ; i < padLen ; i ++ ) {
142
- pad += ' ' ;
143
- }
140
+ for ( var i = 1 ; i < padLen ; i ++ ) pad += ' ' ;
144
141
return str1 + pad + str2 ;
145
142
}
0 commit comments