@@ -8,11 +8,11 @@ function setUpWebStormTask(context) {
88 throw new Error ( 'Context must specify run-sequence instance' ) ;
99 }
1010
11- var fs = require ( 'fs' ) ,
12- path = require ( 'path' ) ,
13- ideTemplate = require ( 'ide-template' ) ,
14- defaults = require ( '../lib/config/defaults' ) ,
15- platform = require ( '../lib/config/platform' ) ;
11+ var fs = require ( 'fs' ) ,
12+ path = require ( 'path' ) ,
13+ ideTemplate = require ( 'ide-template' ) ,
14+ defaults = require ( '../lib/config/defaults' ) ,
15+ platform = require ( '../lib/config/platform' ) ;
1616
1717 var config = defaults
1818 . getInstance ( 'webstorm' )
@@ -30,20 +30,20 @@ function setUpWebStormTask(context) {
3030 {
3131 key : 'defaults' ,
3232 value : {
33- describe : 'Set defaults' ,
34- alias : 'z' ,
35- boolean : true ,
36- isOptional : true
33+ describe : 'Set defaults' ,
34+ alias : 'z' ,
35+ isOptional : true ,
36+ default : false
3737 }
3838 } ,
3939 {
4040 key : 'subdir' ,
4141 value : {
42- describe : 'Navigate to the sub-directory specified' ,
43- alias : 's' ,
44- string : true ,
42+ describe : 'Navigate to the sub-directory specified' ,
43+ alias : 's' ,
44+ string : true ,
4545 isOptional : true ,
46- default : config . get ( 'subdir' )
46+ default : config . get ( 'subdir' )
4747 }
4848 } ,
4949 {
@@ -87,10 +87,9 @@ function setUpWebStormTask(context) {
8787 value : {
8888 describe : 'Launch the IDE following setup' ,
8989 alias : 'l' ,
90- boolean : true ,
9190 default : config . get ( 'launch' )
9291 }
93- } ,
92+ }
9493 ] ;
9594
9695 function checkWebstormFlags ( argv ) {
@@ -108,7 +107,9 @@ function setUpWebStormTask(context) {
108107 }
109108
110109 // ensure options correspond to the types that they were defined as belonging to
111- tyRun . checkFlagType ( opt , key , value ) ;
110+ if ( ( key !== 'defaults' ) && ( key !== 'launch' ) ) {
111+ tyRun . checkFlagType ( opt , key , value ) ;
112+ }
112113
113114 if ( key === 'subdir' ) {
114115 var subdir = path . resolve ( value ) ;
@@ -117,6 +118,29 @@ function setUpWebStormTask(context) {
117118 throw new Error ( 'The specified subdirectory does not exist.' ) ;
118119 }
119120 }
121+ else if ( key === 'defaults' ) {
122+ if ( ! ( / ^ ( t r u e | f a l s e | r e s e t ) $ / . test ( String ( argv . defaults ) ) ) ) {
123+ throw new Error ( 'Unrecognised value for defaults flag, expected true|false|reset.' ) ;
124+ }
125+ }
126+ else if ( key === 'launch' ) {
127+ switch ( argv . launch ) {
128+ case 'false' :
129+ break ;
130+ case 'true' :
131+ if ( ! ideTemplate . webStorm . validateExecutable ( ) ) {
132+ throw new Error ( 'Cannot find Webstorm executable, you will have to specify it explicitly.' ) ;
133+ }
134+ break ;
135+ default :
136+ var customPath = path . normalize ( argv . launch ) ;
137+ if ( fs . existsSync ( customPath ) ) {
138+ ideTemplate . webStorm . customExecutable = customPath ;
139+ } else {
140+ throw new Error ( 'Launch path is not valid or does not exist.' ) ;
141+ }
142+ }
143+ }
120144 } ) ;
121145 if ( ! argv . defaults ) {
122146 // when defaults are not present, check whether angularity project is present
@@ -129,33 +153,6 @@ function setUpWebStormTask(context) {
129153 return true ;
130154 }
131155
132- /**
133- * yargs check for a valid --launch parameter
134- * Additionally parses true|false strings to boolean literals
135- * @param argv
136- */
137- function validateLaunchPath ( argv ) {
138- switch ( argv . launch ) {
139- case false :
140- case 'false' :
141- argv . launch = false ;
142- break ;
143- case true :
144- case 'true' :
145- if ( ideTemplate . webStorm . validateExecutable ( ) ) {
146- argv . launch = true ;
147- } else {
148- return 'Cannot find Webstorm executable, you will have to specify it explicitly.' ;
149- }
150- break ;
151- default :
152- if ( ! fs . existsSync ( path . normalize ( argv . launch ) ) ) {
153- return 'Launch path is not valid or does not exist.' ;
154- }
155- }
156- return argv ;
157- }
158-
159156 var taskDefinition = {
160157 name : 'webstorm' ,
161158 description : [
@@ -180,7 +177,7 @@ function setUpWebStormTask(context) {
180177 'angularity webstorm --defaults reset Reset defaults'
181178 ] . join ( '\n' ) ,
182179 prerequisiteTasks : [ 'help' ] ,
183- checks : [ validateLaunchPath , checkWebstormFlags ] ,
180+ checks : [ checkWebstormFlags ] ,
184181 options : webstormOptionDefinitions ,
185182 onInit : function onInitWebstormTask ( yargsInstance ) {
186183 var gulp = context . gulp ,
@@ -212,13 +209,14 @@ function setUpWebStormTask(context) {
212209 }
213210 // else run the selected items
214211 else {
212+ var launch = ( cliArgs . launch !== 'false' ) ;
215213 var taskList = [
216214 cliArgs . subdir && 'webstorm:subdir' ,
217215 cliArgs . project && 'webstorm:project' ,
218216 cliArgs . external && 'webstorm:externaltools' ,
219217 cliArgs . codestyle && 'webstorm:codestyle' ,
220218 cliArgs . templates && 'webstorm:templates' ,
221- cliArgs . launch && 'webstorm:launch'
219+ launch && 'webstorm:launch'
222220 ] . filter ( Boolean ) ;
223221 if ( taskList . length > 0 ) {
224222 runSequence . apply ( runSequence , taskList . concat ( done ) ) ;
0 commit comments