@@ -90,7 +90,7 @@ exports.init = function (logger, config, cli, appc) {
90
90
paths [ bin ] = process . env [ envName ] ;
91
91
if ( paths [ bin ] ) {
92
92
done ( ) ;
93
- } else if ( process . platform === 'win32' ) {
93
+ } else if ( process . platform === 'win32' && bin === 'alloy' ) {
94
94
paths . alloy = 'alloy.cmd' ;
95
95
done ( ) ;
96
96
} else {
@@ -116,13 +116,12 @@ exports.init = function (logger, config, cli, appc) {
116
116
}
117
117
} ;
118
118
} ) , function ( ) {
119
+
120
+ // compose alloy command execution
119
121
var cmd = [ paths . node , paths . alloy , 'compile' , appDir , '--config' , config ] ;
120
122
if ( cli . argv [ 'no-colors' ] || cli . argv [ 'color' ] === false ) { cmd . push ( '--no-colors' ) ; }
121
- if ( process . platform === 'win32' ) { cmd . shift ( ) ; }
122
- logger . info ( __ ( 'Executing Alloy compile: %s' , cmd . join ( ' ' ) . cyan ) ) ;
123
-
124
- var child = ( process . platform === 'win32' ) ? spawn ( cmd . shift ( ) , cmd , { stdio : 'inherit' } ) : spawn ( cmd . shift ( ) , cmd ) ;
125
123
124
+ // process each line of output from alloy
126
125
function checkLine ( line ) {
127
126
var re = new RegExp (
128
127
'(?:\u001b\\[\\d+m)?\\[?(' +
@@ -139,17 +138,35 @@ exports.init = function (logger, config, cli, appc) {
139
138
}
140
139
}
141
140
142
- child . stdout !== null && child . stdout . on ( 'data' , function ( data ) {
143
- data . toString ( ) . split ( '\n' ) . forEach ( function ( line ) {
144
- checkLine ( line ) ;
141
+ // execute alloy in os-specific manner
142
+ var child ;
143
+ if ( process . platform === 'win32' ) {
144
+ cmd . shift ( ) ;
145
+ logger . info ( __ ( 'Executing Alloy compile: %s' ,
146
+ [ 'cmd' , '/s' , '/c' ] . concat ( cmd ) . join ( ' ' ) . cyan ) ) ;
147
+
148
+ // arg processing from https://github.com/MarcDiethelm/superspawn
149
+ child = spawn ( 'cmd' , [ [ '/s' , '/c' , '"' +
150
+ cmd . map ( function ( a ) {
151
+ if ( / ^ [ ^ " ] .* .* [ ^ " ] / . test ( a ) ) return '"' + a + '"' ; return a ;
152
+ } ) . join ( " " ) + '"' ] . join ( " " ) ] , {
153
+ stdio : 'inherit' ,
154
+ windowsVerbatimArguments : true
155
+ }
156
+ ) ;
157
+ } else {
158
+ logger . info ( __ ( 'Executing Alloy compile: %s' , cmd . join ( ' ' ) . cyan ) ) ;
159
+ child = spawn ( cmd . shift ( ) , cmd ) ;
160
+ child . stdout . on ( 'data' , function ( data ) {
161
+ data . toString ( ) . split ( '\n' ) . forEach ( checkLine ) ;
145
162
} ) ;
146
- } ) ;
147
- child . stderr !== null && child . stderr . on ( 'data' , function ( data ) {
148
- data . toString ( ) . split ( '\n' ) . forEach ( function ( line ) {
149
- checkLine ( line ) ;
163
+ child . stderr . on ( 'data' , function ( data ) {
164
+ data . toString ( ) . split ( '\n' ) . forEach ( checkLine ) ;
150
165
} ) ;
151
- } ) ;
152
- child !== null && child . on ( 'exit' , function ( code ) {
166
+ }
167
+
168
+ // handle the completion of alloy, success or otherwise
169
+ child . on ( 'exit' , function ( code ) {
153
170
if ( code ) {
154
171
logger . error ( __ ( 'Alloy compiler failed' ) ) ;
155
172
process . exit ( 1 ) ;
@@ -161,6 +178,7 @@ exports.init = function (logger, config, cli, appc) {
161
178
}
162
179
finished ( ) ;
163
180
} ) ;
181
+
164
182
} ) ;
165
183
}
166
184
}
0 commit comments