@@ -52,9 +52,7 @@ findPkg()
5252 if ( ! val ) {
5353 console . log ( 'Deleting script.' ) ;
5454 delete scripts [ script ] ;
55- } else {
56- scripts [ script ] = val ;
57- }
55+ } else scripts [ script ] = val ;
5856 return fs . writeJson ( pkgPath , pkg ) ;
5957 } ) ;
6058} )
@@ -64,23 +62,8 @@ findPkg()
6462} ) ;
6563
6664function 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 {
8467 // Get choices:
8568 var choices = Object . keys ( scripts ) . map ( function ( key ) {
8669 return {
@@ -110,36 +93,50 @@ function getScriptName() {
11093 ] )
11194 . then ( function ( answers ) {
11295 switch ( answers . script ) {
113- case NEW_SCRIPT_SYMBOL :
96+ case NEW_SCRIPT_SYMBOL :
11497 // 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+ } ] )
124107 . then ( function ( answers ) {
125108 // Set it:
126109 script = answers . name ;
127110 } ) ;
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 ;
132115 }
133116 } ) ;
134117 }
135118}
136119
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+
137136function pad ( str1 , str2 ) {
138137 var padLen = 60 - ( str1 . length + str2 . length ) ;
139138 // Ensure at least one space:
140139 var pad = ' ' ;
141- for ( var i = 1 ; i < padLen ; i ++ ) {
142- pad += ' ' ;
143- }
140+ for ( var i = 1 ; i < padLen ; i ++ ) pad += ' ' ;
144141 return str1 + pad + str2 ;
145142}
0 commit comments