Skip to content

Commit a39ba2c

Browse files
committed
Merge pull request tidev#672 from appcelerator/CLI-461
[CLI-461] properly handle windows node/alloy paths
2 parents 1bc437a + 34b447b commit a39ba2c

File tree

1 file changed

+32
-14
lines changed

1 file changed

+32
-14
lines changed

hooks/alloy.js

+32-14
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ exports.init = function (logger, config, cli, appc) {
9090
paths[bin] = process.env[envName];
9191
if (paths[bin]) {
9292
done();
93-
} else if (process.platform === 'win32') {
93+
} else if (process.platform === 'win32' && bin === 'alloy') {
9494
paths.alloy = 'alloy.cmd';
9595
done();
9696
} else {
@@ -116,13 +116,12 @@ exports.init = function (logger, config, cli, appc) {
116116
}
117117
};
118118
}), function () {
119+
120+
// compose alloy command execution
119121
var cmd = [paths.node, paths.alloy, 'compile', appDir, '--config', config];
120122
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);
125123

124+
// process each line of output from alloy
126125
function checkLine(line) {
127126
var re = new RegExp(
128127
'(?:\u001b\\[\\d+m)?\\[?(' +
@@ -139,17 +138,35 @@ exports.init = function (logger, config, cli, appc) {
139138
}
140139
}
141140

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);
145162
});
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);
150165
});
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) {
153170
if (code) {
154171
logger.error(__('Alloy compiler failed'));
155172
process.exit(1);
@@ -161,6 +178,7 @@ exports.init = function (logger, config, cli, appc) {
161178
}
162179
finished();
163180
});
181+
164182
});
165183
}
166184
}

0 commit comments

Comments
 (0)