diff --git a/tools/commands-cordova.js b/tools/commands-cordova.js index fccae29701..ecf1a31c10 100644 --- a/tools/commands-cordova.js +++ b/tools/commands-cordova.js @@ -25,11 +25,52 @@ var Console = require('./console.js').Console; // XXX hard-coded the use of default tropohouse var tropo = tropohouse.default; +var supportedPlatforms = ['ios', 'android', 'firefoxos']; +var webArchName = "web.cordova"; var cordova = exports; -var supportedPlatforms = ['ios', 'android', 'firefoxos']; -var webArchName = "web.cordova"; + +// --- the public interface --- + +// Builds a Cordova project that targets the list of 'platforms' +// options: +// - appName: the target path of the build +// - host +// - port +cordova.buildPlatforms = function (localPath, platforms, options) { + verboseLog('Running build for platforms:', platforms); + checkRequestedPlatforms(platforms); + buildCordova(localPath, 'build', options); +}; + +cordova.buildPlatformRunners = function (localPath, platforms, options) { + var runners = []; + _.each(platforms, function (platformName) { + runners.push(new CordovaRunner(localPath, platformName, options)); + }); + return runners; +}; + +// packages - list of strings +cordova.filterPackages = function (packages) { +// We hard-code the 'cordova' and 'platform' namespaces + var ret = { + rest: [], + plugins: [] + }; + + _.each(packages, function (p) { + var namespace = p.split(':')[0]; + var name = p.split(':').slice(1).join(':'); + if (namespace === 'cordova') { + ret.plugins.push(name); + } else { + ret.rest.push(p); // leave it the same + } + }); + return ret; +}; // --- helpers --- @@ -241,7 +282,7 @@ var getBundle = function (bundlePath, webArchs, options) { }; // Creates a Cordova project if necessary. -cordova.ensureCordovaProject = function (localPath, appName) { +var ensureCordovaProject = function (localPath, appName) { verboseLog('Ensuring the cordova build project'); var cordovaPath = path.join(localPath, 'cordova-build'); var localPluginsPath = localPluginsPathFromCordovaPath(cordovaPath); @@ -269,7 +310,7 @@ cordova.ensureCordovaProject = function (localPath, appName) { // Ensures that the Cordova platforms are synchronized with the app-level // platforms. -cordova.ensureCordovaPlatforms = function (localPath) { +var ensureCordovaPlatforms = function (localPath) { verboseLog('Ensuring that platforms in cordova build project are in sync'); var cordovaPath = path.join(localPath, 'cordova-build'); var platforms = project.getCordovaPlatforms(); @@ -341,27 +382,7 @@ var checkRequestedPlatforms = function (platforms) { }); }; -// Builds a Cordova project that targets the list of 'platforms' -// options: -// - appName: the target path of the build -// - host -// - port -cordova.buildPlatforms = function (localPath, platforms, options) { - verboseLog('Running build for platforms:', platforms); - checkRequestedPlatforms(platforms); - buildCordova(localPath, 'build', options); -}; - - -cordova.buildPlatformRunners = function (localPath, platforms, options) { - var runners = []; - _.each(platforms, function (platformName) { - runners.push(new CordovaRunner(localPath, platformName, options)); - }); - return runners; -}; - -cordova.checkIsValidPlatform = function (name) { +var isValidPlatform = function (name) { if (name.match(/ios/i) && process.platform !== 'darwin') throw new Error(name + ': not available on your system'); if (! _.contains(supportedPlatforms, name)) @@ -598,7 +619,7 @@ var ensureCordovaPlugins = function (localPath, options) { // Cordova to fix the bug in their system, because it doesn't seem // like there's a way around this. files.rm_recursive(path.join(cordovaPath, 'platforms')); - cordova.ensureCordovaPlatforms(localPath); + ensureCordovaPlatforms(localPath); }; Console.stdout.write("Initializing Cordova plugins...\n"); uninstallAllPlugins(); @@ -664,16 +685,6 @@ var localPluginsPathFromCordovaPath = function (cordovaPath) { return path.join(cordovaPath, 'local-plugins'); }; -cordova.checkIsValidPlugin = function (name) { - var pluginHash = {}; - pluginHash[name.split('@')[0]] = name.split('@')[1]; - - // check that every plugin is specifying either an exact constraint or a - // tarball url with sha - utils.ensureOnlyExactVersions(pluginHash); -}; - - // --- Cordova from project --- @@ -700,8 +711,8 @@ var buildCordova = function (localPath, buildCommand, options) { verboseLog('Bundling the web.cordova program of the app'); var bundle = getBundle(bundlePath, [webArchName], options); - cordova.ensureCordovaProject(localPath, options.appName); - cordova.ensureCordovaPlatforms(localPath); + ensureCordovaProject(localPath, options.appName); + ensureCordovaPlatforms(localPath); ensureCordovaPlugins(localPath, _.extend({}, options, { packagePlugins: getCordovaDependenciesFromStar(bundle.starManifest) })); @@ -972,28 +983,6 @@ var execCordovaOnPlatform = function (localPath, platformName, options) { return 0; }; - - -// packages - list of strings -cordova.filterPackages = function (packages) { -// We hard-code the 'cordova' and 'platform' namespaces - var ret = { - rest: [], - plugins: [] - }; - - _.each(packages, function (p) { - var namespace = p.split(':')[0]; - var name = p.split(':').slice(1).join(':'); - if (namespace === 'cordova') { - ret.plugins.push(name); - } else { - ret.rest.push(p); // leave it the same - } - }); - return ret; -}; - var getTermsForPlatform = function (platform) { var url = 'https://warehouse.meteor.com/cordova/license_cordova_' + platform + '.txt'; var result = httpHelpers.request({ @@ -1069,7 +1058,7 @@ main.registerCommand({ try { _.each(platforms, function (platform) { - cordova.checkIsValidPlatform(platform); + isValidPlatform(platform); }); } catch (err) { Console.stderr.write(err.message + "\n"); @@ -1095,8 +1084,8 @@ main.registerCommand({ files.mkdir_p(localPath); var appName = path.basename(options.appDir); - cordova.ensureCordovaProject(localPath, appName); - cordova.ensureCordovaPlatforms(localPath); + ensureCordovaProject(localPath, appName); + ensureCordovaPlatforms(localPath); } _.each(platforms, function (platform) { @@ -1128,8 +1117,8 @@ main.registerCommand({ files.mkdir_p(localPath); var appName = path.basename(options.appDir); - cordova.ensureCordovaProject(localPath, appName); - cordova.ensureCordovaPlatforms(localPath); + ensureCordovaProject(localPath, appName); + ensureCordovaPlatforms(localPath); } });