@@ -10,11 +10,38 @@ var Serve = IonicAppLib.serve;
1010var Project = IonicAppLib . project ;
1111var log = IonicAppLib . logging . logger ;
1212var ConfigXml = IonicAppLib . configXml ;
13- var childProcess = require ( 'child_process' ) ;
14- var childExec = childProcess . exec ;
15- var promiseExec = Q . denodeify ( childExec ) ;
13+ var crossSpawn = require ( 'cross-spawn' ) ;
1614var npmScripts = require ( '../utils/npmScripts' ) ;
1715
16+
17+ function promiseSpawn ( cmd , args ) {
18+ var deferred = Q . defer ( ) ;
19+ var info = '' ;
20+
21+ try {
22+ var proc = crossSpawn . spawn ( cmd , args ) ;
23+
24+ proc . stdout . on ( 'data' , function ( data ) {
25+ info += data . toString ( 'utf8' ) ;
26+ } ) ;
27+
28+ proc . on ( 'error' , function ( error ) {
29+ deferred . reject ( error ) ;
30+ } ) ;
31+
32+ proc . on ( 'close' , function ( code ) {
33+ if ( code !== 0 ) {
34+ return deferred . reject ( code ) ;
35+ }
36+ deferred . resolve ( info . replace ( '\n' , ' ' ) ) ;
37+ } ) ;
38+ } catch ( e ) {
39+ return deferred . reject ( e ) ;
40+ }
41+
42+ return deferred . promise ;
43+ }
44+
1845/**
1946 * Returns true or false after checking if the platform exists
2047 * Synchronous
@@ -24,14 +51,21 @@ var npmScripts = require('../utils/npmScripts');
2451 * @return {Boolean } True if platform is installed
2552 */
2653function isPlatformInstalled ( platform , baseDir ) {
54+ var deferred = Q . defer ( ) ;
2755 var platformPath = path . join ( baseDir , 'platforms' , platform ) ;
2856
2957 try {
30- fs . statSync ( platformPath ) ;
31- return true ;
58+ fs . stat ( platformPath , function ( err ) {
59+ if ( err ) {
60+ return deferred . resolve ( false ) ;
61+ }
62+ return deferred . resolve ( true ) ;
63+ } ) ;
3264 } catch ( ex ) {
33- return false ;
65+ deferred . resolve ( false ) ;
3466 }
67+
68+ return deferred . promise ;
3569}
3670
3771/**
@@ -42,14 +76,42 @@ function isPlatformInstalled(platform, baseDir) {
4276 * @return {Boolean } True if any plugin is installed
4377 */
4478function arePluginsInstalled ( baseDir ) {
79+ var deferred = Q . defer ( ) ;
4580 var pluginPath = path . join ( baseDir , 'plugins' ) ;
4681
4782 try {
48- fs . statSync ( pluginPath ) ;
49- return true ;
83+ fs . stat ( pluginPath , function ( err ) {
84+ if ( err ) {
85+ return deferred . resolve ( false ) ;
86+ }
87+ return deferred . resolve ( true ) ;
88+ } ) ;
5089 } catch ( ex ) {
51- return false ;
90+ deferred . resolve ( false ) ;
5291 }
92+
93+ return deferred . promise ;
94+ }
95+
96+ /**
97+ * Install ionic required plugins
98+ *
99+ * @return {Promise } Promise upon completion
100+ */
101+ function installPlugins ( ) {
102+ var plugins = [
103+ 'cordova-plugin-device' ,
104+ 'cordova-plugin-console' ,
105+ 'cordova-plugin-whitelist' ,
106+ 'cordova-plugin-splashscreen' ,
107+ 'cordova-plugin-statusbar' ,
108+ 'ionic-plugin-keyboard'
109+ ] ;
110+
111+ return Q . all ( plugins . map ( function ( plugin ) {
112+ log . info ( [ 'Installing ' , plugin ] . join ( '' ) ) ;
113+ return promiseSpawn ( 'cordova' , [ 'plugin' , 'add' , '--save' , plugin ] ) ;
114+ } ) ) ;
53115}
54116
55117/**
@@ -62,7 +124,7 @@ function installPlatform(platform) {
62124 log . info ( chalk . yellow ( '• You\'re trying to build for ' + platform + ' but don\'t have the platform installed yet.' ) ) ;
63125 log . info ( '∆ Installing ' + platform + ' for you.' ) ;
64126
65- return promiseExec ( 'cordova platform add ' + platform ) . then ( function ( ) {
127+ return promiseSpawn ( 'cordova' , [ ' platform' , ' add' , platform ] ) . then ( function ( ) {
66128 log . info ( '√ Installed platform ' + platform ) ;
67129 } ) ;
68130}
@@ -72,9 +134,7 @@ function execCordovaCommand(optionList, isLiveReload, serveOptions) {
72134 isLiveReload = ! ! isLiveReload ;
73135
74136 log . debug ( 'Executing cordova cli: ' + optionList . join ( ' ' ) ) ;
75- var cordovaProcess = childProcess . exec ( 'cordova ' + optionList . join ( ' ' ) , {
76- maxBuffer : 1024 * 1024 * 1024
77- } ) ;
137+ var cordovaProcess = crossSpawn . spawn ( 'cordova' , optionList ) ;
78138
79139 cordovaProcess . stdout . on ( 'data' , function ( data ) {
80140 log . info ( data . toString ( ) ) ;
@@ -137,26 +197,6 @@ function execCordovaCommand(optionList, isLiveReload, serveOptions) {
137197 return deferred . promise ;
138198}
139199
140- /**
141- * Install ionic required plugins
142- *
143- * @return {Promise } Promise upon completion
144- */
145- function installPlugins ( ) {
146- var plugins = [
147- 'cordova-plugin-device' ,
148- 'cordova-plugin-console' ,
149- 'cordova-plugin-whitelist' ,
150- 'cordova-plugin-splashscreen' ,
151- 'cordova-plugin-statusbar' ,
152- 'ionic-plugin-keyboard'
153- ] ;
154-
155- return Q . all ( plugins . map ( function ( plugin ) {
156- log . info ( [ 'Installing ' , plugin ] . join ( '' ) ) ;
157- return promiseExec ( 'cordova plugin add --save ' + plugin ) ;
158- } ) ) ;
159- }
160200
161201/**
162202 * Filter and gather arguments from command line to be passed to Cordova
0 commit comments