You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by cs...@apache.org on 2013/10/24 20:28:50 UTC
git commit: CB:5187 on node windows broken compile, emulate, run
Updated Branches:
refs/heads/master d75c0585c -> a778f0063
CB:5187 on node windows broken compile, emulate, run
Project: http://git-wip-us.apache.org/repos/asf/cordova-cli/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-cli/commit/a778f006
Tree: http://git-wip-us.apache.org/repos/asf/cordova-cli/tree/a778f006
Diff: http://git-wip-us.apache.org/repos/asf/cordova-cli/diff/a778f006
Branch: refs/heads/master
Commit: a778f0063ffa4e892ed7cf9f9a31f59fe63f0461
Parents: d75c058
Author: Carlos Santana <cs...@gmail.com>
Authored: Thu Oct 24 13:37:25 2013 -0400
Committer: Carlos Santana <cs...@gmail.com>
Committed: Thu Oct 24 14:26:51 2013 -0400
----------------------------------------------------------------------
spec/compile.spec.js | 39 ++++++++++++++++++++++++++++++++-------
spec/emulate.spec.js | 35 ++++++++++++++++++++++++++++++-----
spec/run.spec.js | 32 +++++++++++++++++++++++++++-----
src/compile.js | 12 +++++++++---
src/emulate.js | 12 +++++++++---
src/run.js | 28 +++++++++-------------------
6 files changed, 116 insertions(+), 42 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/a778f006/spec/compile.spec.js
----------------------------------------------------------------------
diff --git a/spec/compile.spec.js b/spec/compile.spec.js
index 4b9ee43..b5a9304 100644
--- a/spec/compile.spec.js
+++ b/spec/compile.spec.js
@@ -23,12 +23,15 @@ var cordova = require('../cordova'),
fs = require('fs'),
hooker = require('../src/hooker'),
Q = require('q'),
- util = require('../src/util');
+ util = require('../src/util'),
+ os = require('os');
+
var supported_platforms = Object.keys(platforms).filter(function(p) { return p != 'www'; });
+var os_platform = os.platform();
describe('compile command', function() {
- var is_cordova, list_platforms, fire, result, child;
+ var is_cordova, list_platforms, fire, result, child, spawn_wrap;
var project_dir = '/some/path';
child = {
on: function(child_event,cb){
@@ -45,6 +48,21 @@ describe('compile command', function() {
on: function(){}
}
};
+ spawn_wrap = function(cmd,args,options){
+ var _cmd = cmd,
+ _args = args;
+
+ if (os.platform() === 'win32') {
+ _args = ['/c',_cmd].concat(_args);
+ _cmd = 'cmd';
+ }
+
+ return {
+ "cmd": _cmd,
+ "args": _args,
+ "options": options
+ };
+ };
function wrapper(f, post) {
runs(function() {
@@ -75,17 +93,24 @@ describe('compile command', function() {
});
describe('success', function() {
+ var spawn_call;
it('should run inside a Cordova-based project with at least one added platform and shell out to build', function(done) {
cordova.raw.compile(['android','ios']).then(function() {
- expect(child_process.spawn).toHaveBeenCalledWith(path.join(project_dir, 'platforms', 'android', 'cordova', 'build'),[]);
- expect(child_process.spawn).toHaveBeenCalledWith(path.join(project_dir, 'platforms', 'ios', 'cordova', 'build'),[]);
+ spawn_call = spawn_wrap(path.join(project_dir, 'platforms', 'android', 'cordova', 'build'),[]);
+ expect(child_process.spawn).toHaveBeenCalledWith(spawn_call.cmd, spawn_call.args);
+
+ spawn_call = spawn_wrap(path.join(project_dir, 'platforms', 'ios', 'cordova', 'build'),[]);
+ expect(child_process.spawn).toHaveBeenCalledWith(spawn_call.cmd, spawn_call.args);
+
done();
});
-
});
+
it('should pass down optional parameters', function (done) {
cordova.raw.compile({platforms:["blackberry10"], options:["--release"]}).then(function () {
- expect(child_process.spawn).toHaveBeenCalledWith(path.join(project_dir, 'platforms', 'blackberry10', 'cordova', 'build'),['--release']);
+ spawn_call = spawn_wrap(path.join(project_dir, 'platforms', 'blackberry10', 'cordova', 'build'),['--release']);
+ expect(child_process.spawn).toHaveBeenCalledWith(spawn_call.cmd, spawn_call.args);
+
done();
});
});
@@ -94,7 +119,7 @@ describe('compile command', function() {
describe('hooks', function() {
describe('when platforms are added', function() {
it('should fire before hooks through the hooker module', function(done) {
- cordova.raw.compile(['android', 'ios']).then(function() {;
+ cordova.raw.compile(['android', 'ios']).then(function() {
expect(fire).toHaveBeenCalledWith('before_compile', {verbose: false, platforms:['android', 'ios'], options: []});
done();
});
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/a778f006/spec/emulate.spec.js
----------------------------------------------------------------------
diff --git a/spec/emulate.spec.js b/spec/emulate.spec.js
index 8f3303e..ddc5a21 100644
--- a/spec/emulate.spec.js
+++ b/spec/emulate.spec.js
@@ -23,12 +23,13 @@ var cordova = require('../cordova'),
fs = require('fs'),
hooker = require('../src/hooker'),
Q = require('q'),
- util = require('../src/util');
+ util = require('../src/util'),
+ os = require('os');
var supported_platforms = Object.keys(platforms).filter(function(p) { return p != 'www'; });
describe('emulate command', function() {
- var is_cordova, list_platforms, fire, result, child;
+ var is_cordova, list_platforms, fire, result, child, spawn_wrap;
var project_dir = '/some/path';
var prepare_spy;
child = {
@@ -46,6 +47,21 @@ describe('emulate command', function() {
on: function(){}
}
};
+ spawn_wrap = function(cmd,args,options){
+ var _cmd = cmd,
+ _args = args;
+
+ if (os.platform() === 'win32') {
+ _args = ['/c',_cmd].concat(_args);
+ _cmd = 'cmd';
+ }
+
+ return {
+ "cmd": _cmd,
+ "args": _args,
+ "options": options
+ };
+ };
function wrapper(f, post) {
runs(function() {
@@ -78,18 +94,27 @@ describe('emulate command', function() {
});
describe('success', function() {
+ var spawn_call;
it('should run inside a Cordova-based project with at least one added platform and call prepare and shell out to the emulate script', function(done) {
cordova.raw.emulate(['android','ios']).then(function(err) {
expect(prepare_spy).toHaveBeenCalledWith(['android', 'ios']);
- expect(child_process.spawn).toHaveBeenCalledWith(path.join(project_dir, 'platforms', 'android', 'cordova', 'run'), ['--emulator']);
- expect(child_process.spawn).toHaveBeenCalledWith(path.join(project_dir, 'platforms', 'ios', 'cordova', 'run'), ['--emulator']);
+
+ spawn_call = spawn_wrap(path.join(project_dir, 'platforms', 'android', 'cordova', 'run'), ['--emulator']);
+ expect(child_process.spawn).toHaveBeenCalledWith(spawn_call.cmd, spawn_call.args);
+
+ spawn_call = spawn_wrap(path.join(project_dir, 'platforms', 'ios', 'cordova', 'run'), ['--emulator']);
+ expect(child_process.spawn).toHaveBeenCalledWith(spawn_call.cmd, spawn_call.args);
+
done();
});
});
it('should pass down options', function(done) {
cordova.raw.emulate({platforms: ['ios'], options:["--optionTastic"]}).then(function(err) {
expect(prepare_spy).toHaveBeenCalledWith(['ios']);
- expect(child_process.spawn).toHaveBeenCalledWith(path.join(project_dir, 'platforms', 'ios', 'cordova', 'run'), ['--emulator', '--optionTastic']);
+
+ spawn_call = spawn_wrap(path.join(project_dir, 'platforms', 'ios', 'cordova', 'run'), ['--emulator', '--optionTastic']);
+ expect(child_process.spawn).toHaveBeenCalledWith(spawn_call.cmd, spawn_call.args);
+
done();
});
});
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/a778f006/spec/run.spec.js
----------------------------------------------------------------------
diff --git a/spec/run.spec.js b/spec/run.spec.js
index 65e6bbe..8fc833f 100644
--- a/spec/run.spec.js
+++ b/spec/run.spec.js
@@ -23,12 +23,13 @@ var cordova = require('../cordova'),
fs = require('fs'),
hooker = require('../src/hooker'),
Q = require('q'),
- util = require('../src/util');
+ util = require('../src/util'),
+ os = require('os');
var supported_platforms = Object.keys(platforms).filter(function(p) { return p != 'www'; });
describe('run command', function() {
- var is_cordova, list_platforms, fire, child;
+ var is_cordova, list_platforms, fire, child, spawn_wrap;
var project_dir = '/some/path';
var prepare_spy;
child = {
@@ -46,6 +47,21 @@ describe('run command', function() {
on: function(){}
}
};
+ spawn_wrap = function(cmd,args,options){
+ var _cmd = cmd,
+ _args = args;
+
+ if (os.platform() === 'win32') {
+ _args = ['/c',_cmd].concat(_args);
+ _cmd = 'cmd';
+ }
+
+ return {
+ "cmd": _cmd,
+ "args": _args,
+ "options": options
+ };
+ };
beforeEach(function() {
is_cordova = spyOn(util, 'isCordova').andReturn(project_dir);
@@ -77,8 +93,12 @@ describe('run command', function() {
it('should run inside a Cordova-based project with at least one added platform and call prepare and shell out to the run script', function(done) {
cordova.raw.run(['android','ios']).then(function() {
expect(prepare_spy).toHaveBeenCalledWith(['android', 'ios']);
- expect(child_process.spawn).toHaveBeenCalledWith(path.join(project_dir, 'platforms', 'android', 'cordova', 'run'), ['--device']);
- expect(child_process.spawn).toHaveBeenCalledWith(path.join(project_dir, 'platforms', 'ios', 'cordova', 'run'), ['--device']);
+
+ spawn_call = spawn_wrap(path.join(project_dir, 'platforms', 'android', 'cordova', 'run'), ['--device']);
+ expect(child_process.spawn).toHaveBeenCalledWith(spawn_call.cmd, spawn_call.args);
+
+ spawn_call = spawn_wrap(path.join(project_dir, 'platforms', 'ios', 'cordova', 'run'), ['--device']);
+ expect(child_process.spawn).toHaveBeenCalledWith(spawn_call.cmd, spawn_call.args);
}, function(err) {
console.log(err);
@@ -88,7 +108,9 @@ describe('run command', function() {
it('should pass down parameters', function(done) {
cordova.raw.run({platforms: ['blackberry10'], options:['--password', '1q1q']}).then(function() {
expect(prepare_spy).toHaveBeenCalledWith(['blackberry10']);
- expect(child_process.spawn).toHaveBeenCalledWith(path.join(project_dir, 'platforms', 'blackberry10', 'cordova', 'run'), ['--device', '--password', '1q1q']);
+
+ spawn_call = spawn_wrap(path.join(project_dir, 'platforms', 'blackberry10', 'cordova', 'run'), ['--device', '--password', '1q1q']);
+ expect(child_process.spawn).toHaveBeenCalledWith(spawn_call.cmd, spawn_call.args);
}, function(err) {
expect(err).toBeUndefined();
}).fin(done);
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/a778f006/src/compile.js
----------------------------------------------------------------------
diff --git a/src/compile.js b/src/compile.js
index 97f7f21..a9a31e8 100644
--- a/src/compile.js
+++ b/src/compile.js
@@ -25,7 +25,8 @@ var cordova_util = require('./util'),
child_process = require('child_process'),
hooker = require('./hooker'),
events = require('./events'),
- Q = require('q');
+ Q = require('q'),
+ os = require('os');
// Returns a promise.
function shell_out_to_build(projectRoot, platform, options) {
@@ -35,9 +36,14 @@ function shell_out_to_build(projectRoot, platform, options) {
errors = "",
child;
+ if (os.platform() === 'win32') {
+ args = ['/c',cmd].concat(args);
+ cmd = 'cmd';
+ }
+
events.emit('log', 'Compiling app on platform "' + platform + '" via command "' + cmd + '" ' + args.join(" "));
- //CB-5125 using spawn instead of exec to avoid errors with stdout on maxBuffer
+ //using spawn instead of exec to avoid errors with stdout on maxBuffer
child = child_process.spawn(cmd, args);
child.stdout.setEncoding('utf8');
child.stdout.on('data', function (data) {
@@ -51,7 +57,7 @@ function shell_out_to_build(projectRoot, platform, options) {
});
child.on('close', function (code) {
- events.emit('verbose', "child_process.spawn(" + cmd + "," + args.join(" ") + ") = " + code);
+ events.emit('verbose', "child_process.spawn(" + cmd + "," + "[" + args.join(", ") + "]) = " + code);
if (code === 0) {
events.emit('log', 'Platform "' + platform + '" compiled successfully.');
d.resolve();
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/a778f006/src/emulate.js
----------------------------------------------------------------------
diff --git a/src/emulate.js b/src/emulate.js
index f1853a7..cf5e7b9 100644
--- a/src/emulate.js
+++ b/src/emulate.js
@@ -26,7 +26,8 @@ var cordova_util = require('./util'),
events = require('./events'),
hooker = require('./hooker'),
Q = require('q'),
- DEFAULT_OPTIONS = ["--emulator"];
+ DEFAULT_OPTIONS = ["--emulator"],
+ os = require('os');
// Returns a promise.
function shell_out_to_emulate(projectRoot, platform, options) {
@@ -36,9 +37,14 @@ function shell_out_to_emulate(projectRoot, platform, options) {
errors = "",
child;
+ if (os.platform() === 'win32') {
+ args = ['/c',cmd].concat(args);
+ cmd = 'cmd';
+ }
+
events.emit('log', 'Running on emulator for platform "' + platform + '" via command "' + cmd + '" ' + args.join(" "));
- //CB-5125 using spawn instead of exec to avoid errors with stdout on maxBuffer
+ //using spawn instead of exec to avoid errors with stdout on maxBuffer
child = child_process.spawn(cmd, args);
child.stdout.setEncoding('utf8');
@@ -53,7 +59,7 @@ function shell_out_to_emulate(projectRoot, platform, options) {
});
child.on('close', function (code) {
- events.emit('verbose', "child_process.spawn(" + cmd + "," + args.join(" ") + ") = " + code);
+ events.emit('verbose', "child_process.spawn(" + cmd + "," + "[" + args.join(", ") + "]) = " + code);
if (code === 0) {
events.emit('log', 'Platform "' + platform + '" deployed to emulator.');
d.resolve();
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/a778f006/src/run.js
----------------------------------------------------------------------
diff --git a/src/run.js b/src/run.js
index d5487b3..fc3fbeb 100644
--- a/src/run.js
+++ b/src/run.js
@@ -26,7 +26,8 @@ var cordova_util = require('./util'),
events = require('./events'),
Q = require('q'),
child_process = require('child_process'),
- DEFAULT_OPTIONS = ["--device"];
+ DEFAULT_OPTIONS = ["--device"],
+ os = require('os');
// Returns a promise.
function shell_out_to_run(projectRoot, platform, options) {
@@ -36,25 +37,14 @@ function shell_out_to_run(projectRoot, platform, options) {
errors = "",
child;
- events.emit('log', 'Running app on platform "' + platform + '" via command "' + cmd + '" ' + args.join(" "));
-
- // TODO: inconsistent API for BB10 run command
-/* if (platform == 'blackberry') {
- var bb_project = path.join(projectRoot, 'platforms', 'blackberry')
- var project = new platforms.blackberry.parser(bb_project);
- if (project.has_device_target()) {
- var bb_config = project.get_cordova_config();
- var device = project.get_device_targets()[0].name;
- cmd = '"' + path.join(bb_project, 'cordova', 'run') + '" --target=' + device + ' -k ' + bb_config.signing_password;
- } else {
- var err = new Error('No BlackBerry device targets defined. If you want to run `run` with BB10, please add a device target. For more information run "' + path.join(bb_project, 'cordova', 'target') + '" -h');
- if (error_callback) error_callback(err);
- else throw err;
- }
+ if (os.platform() === 'win32') {
+ args = ['/c',cmd].concat(args);
+ cmd = 'cmd';
}
-*/
- //CB-5125 using spawn instead of exec to avoid errors with stdout on maxBuffer
+ events.emit('log', 'Running app on platform "' + platform + '" via command "' + cmd + '" ' + args.join(" "));
+
+ //using spawn instead of exec to avoid errors with stdout on maxBuffer
child = child_process.spawn(cmd, args);
child.stdout.setEncoding('utf8');
@@ -69,7 +59,7 @@ function shell_out_to_run(projectRoot, platform, options) {
});
child.on('close', function (code) {
- events.emit('verbose', "child_process.spawn(" + cmd + "," + args.join(" ") + ") = " + code);
+ events.emit('verbose', "child_process.spawn(" + cmd + "," + "[" + args.join(", ") + "]) = " + code);
if (code === 0) {
events.emit('log', 'Platform "' + platform + '" ran successfully.');
d.resolve();