@@ -37,7 +37,11 @@ function execute(options) {
37
37
] ;
38
38
39
39
if ( options . bundle ) {
40
- commands . unshift ( ( ) => webpack ( options . platform ) ) ;
40
+ commands = [
41
+ ( ) => prepare ( options . platform ) ,
42
+ ( ) => webpack ( options . platform ) ,
43
+ ...commands
44
+ ] ;
41
45
}
42
46
43
47
return commands . reduce ( ( current , next ) => current . then ( next ) , Promise . resolve ( ) ) ;
@@ -47,17 +51,42 @@ function webpack(platform) {
47
51
return new Promise ( function ( resolve , reject ) {
48
52
console . log ( `Running webpack for ${ platform } ...` ) ;
49
53
50
- spawnChildProcess ( "tns" , "clean-app" , platform )
51
- . then ( ( ) => spawnChildProcess ( "webpack" , `--config=webpack.${ platform } .js` , "--progress" ) )
54
+ spawnChildProcess ( true , "webpack" , `--config=webpack.${ platform } .js` , "--progress" )
52
55
. then ( resolve )
53
56
. catch ( throwError ) ;
54
57
} ) ;
55
58
}
56
59
60
+ function prepare ( platform ) {
61
+ return removePlatform ( platform )
62
+ . then ( ( ) => addPlatform ( platform ) ) ;
63
+ }
64
+
65
+ function removePlatform ( platform ) {
66
+ return new Promise ( function ( resolve , reject ) {
67
+ console . log ( `Removing platform ${ platform } ...` ) ;
68
+
69
+ spawnChildProcess ( false , "tns" , "platform" , "remove" , platform )
70
+ . then ( resolve )
71
+ . catch ( resolve ) ;
72
+ } ) ;
73
+ }
74
+
75
+ function addPlatform ( platform ) {
76
+ return new Promise ( function ( resolve , reject ) {
77
+ console . log ( `Adding platform ${ platform } ...` ) ;
78
+
79
+ spawnChildProcess ( false , "tns" , "platform" , "add" , platform )
80
+ . then ( resolve )
81
+ . catch ( resolve ) ;
82
+ } ) ;
83
+ }
84
+
57
85
function runTns ( command , platform ) {
58
- console . log ( `Running tns ${ command } ...` ) ;
59
86
return new Promise ( ( resolve , reject ) => {
60
- spawnChildProcess ( "tns" , command , platform , "--bundle" , "--disable-npm-install" , ...tnsArgs )
87
+ console . log ( `Running tns ${ command } ...` ) ;
88
+
89
+ spawnChildProcess ( true , "tns" , command , platform , "--bundle" , "--disable-npm-install" , ...tnsArgs )
61
90
. then ( resolve )
62
91
. catch ( throwError ) ;
63
92
} ) ;
@@ -100,9 +129,11 @@ function getCommand(flags) {
100
129
}
101
130
}
102
131
103
- function spawnChildProcess ( command , ...args ) {
132
+ function spawnChildProcess ( shouldPrintOutput , command , ...args ) {
133
+ const stdio = shouldPrintOutput ? "inherit" : "ignore" ;
134
+
104
135
return new Promise ( ( resolve , reject ) => {
105
- const childProcess = spawn ( command , args , { stdio : "inherit" , pwd : PROJECT_DIR , shell : true } ) ;
136
+ const childProcess = spawn ( command , args , { stdio, pwd : PROJECT_DIR , shell : true } ) ;
106
137
107
138
childProcess . on ( "close" , ( code ) => {
108
139
if ( code === 0 ) {
0 commit comments