@@ -13,6 +13,7 @@ var ConfigXml = IonicAppLib.configXml;
1313var childProcess = require ( 'child_process' ) ;
1414var childExec = childProcess . exec ;
1515var promiseExec = Q . denodeify ( childExec ) ;
16+ var npmScripts = require ( '../utils/npmScripts' ) ;
1617
1718/**
1819 * Returns true or false after checking if the platform exists
@@ -266,12 +267,59 @@ function setupLiveReload(argv, baseDir) {
266267 } ) ;
267268}
268269
270+ /**
271+ * Start the app scripts server for emulator or device
272+ *
273+ * @param {Number } port
274+ * @param {String } address
275+ * @return {Promise } Promise upon completion
276+ */
277+ function startAppScriptsServer ( argv ) {
278+ var options = _ . extend ( argv , {
279+ runLivereload : true ,
280+ isPlatformServe : true
281+ } ) ;
282+
283+ return Serve . getAddress ( options )
284+ . then ( function ( ) {
285+
286+ // Check that the server port is available
287+ return Serve . checkPorts ( true , options . port , options . address , options ) ;
288+ } )
289+ . then ( function ( ) {
290+
291+ // Check that the liveReload port is available
292+ return Serve . checkPorts ( false , options . liveReloadPort , options . address , options ) ;
293+ } )
294+ . then ( function ( ) {
295+
296+ // Execute the serve command from app-scripts
297+ // Also remove platform from the raw args passed
298+ return npmScripts . runIonicScript ( 'serve' ,
299+ [
300+ '--port' , options . port ,
301+ '--address' , options . address ,
302+ '--liveReloadPort' , options . liveReloadPort ,
303+ '--nobrowser'
304+ ]
305+ . concat ( options . consolelogs ? '--consolelogs' : [ ] )
306+ . concat ( options . serverlogs ? '--serverlogs' : [ ] )
307+ ) ;
308+ } )
309+ . then ( function ( ) {
310+ return ConfigXml . setConfigXml ( process . cwd ( ) , {
311+ devServer : Serve . host ( options . address , options . port )
312+ } ) ;
313+ } ) ;
314+ }
315+
269316module . exports = {
270317 isPlatformInstalled : isPlatformInstalled ,
271318 arePluginsInstalled : arePluginsInstalled ,
272319 installPlatform : installPlatform ,
273320 installPlugins : installPlugins ,
274321 execCordovaCommand : execCordovaCommand ,
275322 filterArgumentsForCordova : filterArgumentsForCordova ,
276- setupLiveReload : setupLiveReload
323+ setupLiveReload : setupLiveReload ,
324+ startAppScriptsServer : startAppScriptsServer
277325} ;
0 commit comments