Skip to content

Commit

Permalink
Merge pull request #32 from tecfu/master
Browse files Browse the repository at this point in the history
Can now pass CLI style JSON props i.e. '--remote-debugger-port':8888
  • Loading branch information
jhnns committed Apr 27, 2015
2 parents 44ad338 + 13af15c commit b7b9bba
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions lib/spawn.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var initialMessage = "message to node: hi";
*/
function spawn(phantomJsConfig) {
var configPath;
var cliStyleOpts = [];
var stdout;
var stderr;
var child;
Expand All @@ -46,6 +47,15 @@ function spawn(phantomJsConfig) {
.then(function writeConfig(info) {
configPath = info.path;

//Pass config items in CLI style (--some-config) separately
//to avoid Phantom's JSON config bugs
for (var i in phantomJsConfig) {
if (i[0] === '-') {
cliStyleOpts.push(i + '=' + phantomJsConfig[i]);
delete phantomJsConfig[i];
}
}

return writeFile(info.path, JSON.stringify(phantomJsConfig))
.then(function () {
return close(info.fd);
Expand Down Expand Up @@ -79,11 +89,21 @@ function spawn(phantomJsConfig) {
reject(new Error(message));
}

child = childProcess.spawn(phantomjs.path, [
"--config=" + configPath,
startScript,
configPath
]);
var spawnOptions = [
"--config=" + configPath,
startScript,
configPath
];

//Add in CLI style options
/**/
if (cliStyleOpts.length > 0) {
while (cliStyleOpts.length > 0) {
spawnOptions.splice(1, 0, cliStyleOpts.pop());
}
}

child = childProcess.spawn(phantomjs.path, spawnOptions);

prepareChildProcess(child);

Expand Down

0 comments on commit b7b9bba

Please sign in to comment.