@@ -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' )
@@ -107,7 +107,7 @@ function setUpWebStormTask(context) {
107107 }
108108
109109 // ensure options correspond to the types that they were defined as belonging to
110- if ( key !== 'defaults' ) {
110+ if ( ( key !== 'defaults' ) && ( key !== 'launch' ) ) {
111111 tyRun . checkFlagType ( opt , key , value ) ;
112112 }
113113
@@ -123,6 +123,24 @@ function setUpWebStormTask(context) {
123123 throw new Error ( 'Unrecognised value for defaults flag, expected true|false|reset.' ) ;
124124 }
125125 }
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+ }
126144 } ) ;
127145 if ( ! argv . defaults ) {
128146 // when defaults are not present, check whether angularity project is present
@@ -135,33 +153,6 @@ function setUpWebStormTask(context) {
135153 return true ;
136154 }
137155
138- /**
139- * yargs check for a valid --launch parameter
140- * Additionally parses true|false strings to boolean literals
141- * @param argv
142- */
143- function validateLaunchPath ( argv ) {
144- switch ( argv . launch ) {
145- case false :
146- case 'false' :
147- argv . launch = false ;
148- break ;
149- case true :
150- case 'true' :
151- if ( ideTemplate . webStorm . validateExecutable ( ) ) {
152- argv . launch = true ;
153- } else {
154- return 'Cannot find Webstorm executable, you will have to specify it explicitly.' ;
155- }
156- break ;
157- default :
158- if ( ! fs . existsSync ( path . normalize ( argv . launch ) ) ) {
159- return 'Launch path is not valid or does not exist.' ;
160- }
161- }
162- return argv ;
163- }
164-
165156 var taskDefinition = {
166157 name : 'webstorm' ,
167158 description : [
@@ -186,7 +177,7 @@ function setUpWebStormTask(context) {
186177 'angularity webstorm --defaults reset Reset defaults'
187178 ] . join ( '\n' ) ,
188179 prerequisiteTasks : [ 'help' ] ,
189- checks : [ validateLaunchPath , checkWebstormFlags ] ,
180+ checks : [ checkWebstormFlags ] ,
190181 options : webstormOptionDefinitions ,
191182 onInit : function onInitWebstormTask ( yargsInstance ) {
192183 var gulp = context . gulp ,
@@ -202,7 +193,7 @@ function setUpWebStormTask(context) {
202193 yargsInstance
203194 . strict ( )
204195 . wrap ( 80 ) ;
205- cliArgs = validateLaunchPath ( yargsInstance . argv ) ; // cast launch flag to boolean (mutate and return)
196+ cliArgs = yargsInstance . argv ;
206197
207198 gulp . task ( 'webstorm' , function ( done ) {
208199 console . log ( hr ( '-' , 80 , 'webstorm' ) ) ;
@@ -218,13 +209,14 @@ function setUpWebStormTask(context) {
218209 }
219210 // else run the selected items
220211 else {
212+ var launch = ( cliArgs . launch !== 'false' ) ;
221213 var taskList = [
222214 cliArgs . subdir && 'webstorm:subdir' ,
223215 cliArgs . project && 'webstorm:project' ,
224216 cliArgs . external && 'webstorm:externaltools' ,
225217 cliArgs . codestyle && 'webstorm:codestyle' ,
226218 cliArgs . templates && 'webstorm:templates' ,
227- cliArgs . launch && 'webstorm:launch'
219+ launch && 'webstorm:launch'
228220 ] . filter ( Boolean ) ;
229221 if ( taskList . length > 0 ) {
230222 runSequence . apply ( runSequence , taskList . concat ( done ) ) ;
0 commit comments