Skip to content

Use fork instead of spawn for tns command #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 18, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 20 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict';

var spawn = require('child_process').spawn;
var fork = require('child_process').fork;
var which = require('shelljs').which;

var fs = require('fs');
var os = require('os');
var path = require('path');
Expand All @@ -9,9 +11,10 @@ var util = require('util');

var TEST_RUNNER_DIR = path.join(__dirname, 'runner');

var tnsCliExecutable = {
'win32': 'tns.cmd'
}[require('os').platform()] || 'tns';
function getTnsCliExecutablePath() {
var pathToTnsExecutable = which('tns');
return path.join(path.dirname(pathToTnsExecutable), "nativescript.js");
}

function NativeScriptLauncher(baseBrowserDecorator, logger, config, args, emitter, executor) {
var self = this;
Expand Down Expand Up @@ -58,24 +61,26 @@ function NativeScriptLauncher(baseBrowserDecorator, logger, config, args, emitte
if (launcherConfig.log) {
tnsArgs = tnsArgs.concat(['--log', launcherConfig.log]);
}

if (typeof launcherConfig.path !== 'undefined') {
tnsArgs = tnsArgs.concat(['--path', launcherConfig.path]);
}

var tnsCli = tnsCliExecutable;
if (launcherConfig.tns) {
tnsCli = launcherConfig.node || 'node';
tnsArgs.unshift(launcherConfig.tns);
}

var tnsCli = launcherConfig.tns || getTnsCliExecutablePath();
self.log.debug('Starting "' + tnsCli + '" ' + tnsArgs.join(' '));

var runner = spawn(tnsCli, tnsArgs);
var optionsStr = JSON.stringify(launcherConfig.options);
runner.stdin.end(optionsStr);
var runner = fork(tnsCli, tnsArgs);

runner.on('message', function(data) {
if (data === "ready") {
// Child process is ready to read the data
var optionsStr = JSON.stringify(launcherConfig.options);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

process.send already does that for you.

runner.send(optionsStr);
}
});

runner.stdout.on('data', logDebugOutput);
runner.stderr.on('data', logDebugOutput);
runner.on('error', logDebugOutput);
runner.on('data', logDebugOutput);
runner.on('exit', function(code) {
self.log.info('NativeScript deployment completed with code ' + code);
if (code) {
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "karma-nativescript-launcher",
"version": "0.2.0",
"version": "0.3.0",
"description": "",
"main": "index.js",
"scripts": {
Expand All @@ -13,6 +13,7 @@
},
"devDependencies": {
"grunt": "^0.4.5",
"grunt-shell": "^1.1.2"
"grunt-shell": "^1.1.2",
"shelljs": "0.5.3"
}
}
}