diff --git a/tools/commands.js b/tools/commands.js index cc49afd0ff..f8562a755b 100644 --- a/tools/commands.js +++ b/tools/commands.js @@ -1627,7 +1627,6 @@ var ensureCordovaProject = function (options, projectPath, bundlePath) { if (_.has(installedPlugins, name) && installedPlugins[name] === version) return; - console.log("> Installing Cordova plugin", name); // XXX do something different for plugins fetched from a url. execFileSync('cordova', ['plugin', 'add', name + '@' + version], { cwd: projectPath }); @@ -1648,7 +1647,8 @@ main.registerCommand({ requiresApp: true, options: { port: { type: String, short: 'p', default: '3000' }, - host: { type: String, short: 'h', default: 'localhost' } + host: { type: String, short: 'h', default: 'localhost' }, + verbose: { type: Boolean, short: 'v', default: false } }, }, function (options) { var localDir = path.join(options.appDir, '.meteor', 'local'); @@ -1662,14 +1662,17 @@ main.registerCommand({ if (cordovaCommand === 'plugin' || cordovaCommand === 'plugins') { var pluginsCommand = cordovaArgs[0]; var pluginsArgs = cordovaArgs.slice(1); + var plugins = _.map(pluginsArgs, function (str) { return str.split('@')[0]; }); if (pluginsCommand === 'add') { project.addCordovaPlugins(_.object(_.map(pluginsArgs, function (str) { return str.split('@'); }))); + console.log("=> Added", plugins.join(' ')); return 0; } else if (pluginsCommand === 'remove' || pluginsCommand === 'rm') { project.removeCordovaPlugins(pluginsArgs); + console.log("=> Removed", plugins.join(' ')); return 0; } } @@ -1682,7 +1685,6 @@ main.registerCommand({ if (cordovaCommand === 'emulate' && cordovaArgs[0] === 'android' && options.host === 'localhost') projectOptions.host = '10.0.2.2'; - try { ensureCordovaProject(projectOptions, cordovaPath, bundleDir); } catch (e) { @@ -1691,8 +1693,15 @@ main.registerCommand({ return 1; } - // XXX if it is cordova serve, print the output // XXX error if not a Cordova project - execFileSync('cordova', options.args, { cwd: cordovaPath }); + var cordovaProcess = execFileSync('cordova', options.args, { cwd: cordovaPath }); + if (cordovaProcess.success) { + if (options.verbose) + console.log(cordovaProcess.stdout); + return 0; + } else { + process.stderr.write(cordovaProcess.stderr); + return 1; + } }); diff --git a/tools/selftest.js b/tools/selftest.js index c0b2f9df6b..f46c989033 100644 --- a/tools/selftest.js +++ b/tools/selftest.js @@ -75,10 +75,10 @@ var getToolsPackage = function () { }; // Execute a command synchronously, discarding stderr. -var execFileSync = function (binary, args) { +var execFileSync = function (binary, args, opts) { return Future.wrap(function(cb) { var cb2 = function(err, stdout, stderr) { cb(err, stdout); }; - child_process.execFile(binary, args, cb2); + child_process.execFile(binary, args, opts, cb2); })().wait(); }; @@ -1529,5 +1529,6 @@ _.extend(exports, { fail: fail, expectEqual: expectEqual, expectThrows: expectThrows, - getToolsPackage: getToolsPackage + getToolsPackage: getToolsPackage, + execFileSync: execFileSync }); diff --git a/tools/tests/cordova-plugins.js b/tools/tests/cordova-plugins.js index 8b318b0093..3b4a9c1aff 100644 --- a/tools/tests/cordova-plugins.js +++ b/tools/tests/cordova-plugins.js @@ -1,7 +1,8 @@ var selftest = require('../selftest.js'); var Sandbox = selftest.Sandbox; var files = require('../files.js'); -var _= require('underscore'); +var _ = require('underscore'); +var utils = require('../utils.js'); // Copy the contents of one file to another. In these series of tests, we often // want to switch contents of package.js files. It is more legible to copy in @@ -26,25 +27,18 @@ var copyFile = function(from, to, sand) { // sand: a sandbox, that has the main app directory as its cwd. // plugins: an array of plugins in order. var checkCordovaPlugins = function(sand, plugins) { - var lines = sand.read(".meteor/local/cordova.client/cordova-all-plugins") - .split("\n"); + var lines = selftest.execFileSync(sand.execPath, ['cordova', 'plugins'], { cwd: sand.cwd }).split("\n"); var i = 0; _.each(lines, function(line) { - if (!line) return; - // If the specified package contains an @ sign, then it has a version - // number, so we should match everything. - if (plugins[i].split('@').length > 1) { - selftest.expectEqual(line, plugins[i]); - } else { - var pack = line.split('@')[0]; - selftest.expectEqual(pack, plugins[i]); - } + if (!line || line === '') return; + // XXX should check for the version as well? + selftest.expectEqual(line.split(' ')[0], plugins[i]); i++; }); selftest.expectEqual(plugins.length, i); }; -// Given a sandbox, that has the app as its currend cwd, read the cordova plugins +// Given a sandbox, that has the app as its cwd, read the cordova plugins // file and check that it contains exactly the plugins specified, in order. // // sand: a sandbox, that has the main app directory as its cwd. @@ -114,9 +108,9 @@ selftest.define("change plugins", function () { }); -// Add packages through the command line, and make sure that the correct set of +// Add plugins through the command line, and make sure that the correct set of // changes is reflected in .meteor/packages, .meteor/versions and list -selftest.define("add packages", function () { +selftest.define("add plugins", function () { var s = new Sandbox(); var run; @@ -127,25 +121,25 @@ selftest.define("add packages", function () { s.set("METEOR_OFFLINE_CATALOG", "t"); run = s.run("cordova", "plugin", "add", "org.apache.cordova.camera"); + run.match("Added org.apache.cordova.camera"); checkUserPlugins(s, ["org.apache.cordova.camera"]); run = s.run("add", "contains-cordova-plugin"); run.match("Successfully added"); // XXX message about a plugin? - checkUserPlugins(s, ["org.apache.cordova.camera"]); + checkUserPlugins(s, ["org.apache.cordova.camera"]); // XXX should really have the facebookconnect plugin as well - run = s.run("cordova", "create", "ios"); // XXX remove ios + run = s.run("cordova", "build"); + run.waitSecs(10); + run.expectExit(0); - checkCordovaPlugins(s, - ["org.apache.cordova.camera@0.3.0", - "https://github.com/shazron/phonegap-facebook-plugin.git"]);// XXX fix this - - run = s.run("remove", "contains-cordova-plugin"); - // XXX message here? - - run = s.run("cordova", "build"); // XXX remove ios checkCordovaPlugins(s, ["org.apache.cordova.camera", - "https://github.com/shazron/phonegap-facebook-plugin.git"]); + "com.phonegap.plugins.facebookconnect"]); + + run = s.run("remove", "contains-cordova-plugin"); + + run.match("removed"); + checkCordovaPlugins(s, ["org.apache.cordova.camera"]); });