Return-Path: X-Original-To: apmail-cordova-commits-archive@www.apache.org Delivered-To: apmail-cordova-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id F3E5911892 for ; Fri, 13 Jun 2014 21:01:20 +0000 (UTC) Received: (qmail 23983 invoked by uid 500); 13 Jun 2014 21:01:20 -0000 Delivered-To: apmail-cordova-commits-archive@cordova.apache.org Received: (qmail 23955 invoked by uid 500); 13 Jun 2014 21:01:20 -0000 Mailing-List: contact commits-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cordova.apache.org Delivered-To: mailing list commits@cordova.apache.org Received: (qmail 23948 invoked by uid 99); 13 Jun 2014 21:01:20 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 13 Jun 2014 21:01:20 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 987229341AA; Fri, 13 Jun 2014 21:01:20 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: kamrik@apache.org To: commits@cordova.apache.org Message-Id: <635ac577b22c498cad7c7df6be4874d3@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: git commit: CB-6512: Allow "cordova platform add /path/to/platform/files" Date: Fri, 13 Jun 2014 21:01:20 +0000 (UTC) Repository: cordova-lib Updated Branches: refs/heads/master c5180b29d -> f9025e84f CB-6512: Allow "cordova platform add /path/to/platform/files" The directory with platform files is expected to contain a package.json with name: cordova-platformName. Example: cordova platform add \ /Users/kamrik/.cordova/lib/npm_cache/cordova-ios/3.5.0/package/ Project: http://git-wip-us.apache.org/repos/asf/cordova-lib/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-lib/commit/f9025e84 Tree: http://git-wip-us.apache.org/repos/asf/cordova-lib/tree/f9025e84 Diff: http://git-wip-us.apache.org/repos/asf/cordova-lib/diff/f9025e84 Branch: refs/heads/master Commit: f9025e84fa88c3d97792eb45bd7c2d9c4abc5a97 Parents: c5180b2 Author: Mark Koudritsky Authored: Fri Jun 13 16:55:52 2014 -0400 Committer: Mark Koudritsky Committed: Fri Jun 13 16:59:59 2014 -0400 ---------------------------------------------------------------------- cordova-lib/src/cordova/platform.js | 55 +++++++++++++++++++++++++------- 1 file changed, 44 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/f9025e84/cordova-lib/src/cordova/platform.js ---------------------------------------------------------------------- diff --git a/cordova-lib/src/cordova/platform.js b/cordova-lib/src/cordova/platform.js index 374b223..8d5d418 100644 --- a/cordova-lib/src/cordova/platform.js +++ b/cordova-lib/src/cordova/platform.js @@ -74,17 +74,46 @@ function add(hooks, projectRoot, targets, opts) { return hooks.fire('before_platform_add', opts) .then(cordova_util.Q_chainmap(targets, function(t) { // For each platform, download it and call its "create" script. - return lazy_load.based_on_config(projectRoot, t, opts) - .fail(function(err) { - throw new CordovaError('Unable to fetch platform ' + t + ': ' + err); - }) - .then(function(libDir) { - var platform = t; - if (platform.indexOf('@') != -1) { - // If platform contains @version part, strip it. - var parts = platform.split('@'); - platform = parts[0]; + + var p; // The promise to be returned by this function. + var platform = t.split('@')[0]; + // If t is not a platform or platform@version, it must be a dir. + // In this case get platform name from package.json in that dir and + // skip lazy-load. + if( !(platform in platforms) ) { + var pPath = path.resolve(t); + var pkg; + // Prep the message in advance, we might need it in several places. + msg = 'The provided path does not seem to contain a ' + + 'Cordova platform: ' + t; + try { + pkg = require(path.join(pPath, 'package')); + } catch(e) { + throw new CordovaError(msg + '\n' + e.message); + } + if ( !pkg || !pkg.name ) { + throw new CordovaError(msg); + } + // Package names for Cordova platforms look like "cordova-ios". + var nameParts = pkg.name.split('-'); + var name = nameParts[1]; + if( !platforms[name] ) { + throw new CordovaError(msg); } + platform = name; + + // Use a fulfilled promise with the path as value to skip dloading. + p = Q(pPath); + } else { + // Using lazy_load for a platform specified by name + p = lazy_load.based_on_config(projectRoot, t, opts) + .fail(function(err) { + throw new CordovaError('Unable to fetch platform ' + t + ': ' + err); + }); + } + + return p + .then(function(libDir) { var template = config_json.lib && config_json.lib[platform] && config_json.lib[platform].template || null; var copts = null; if ('spawnoutput' in opts) { @@ -281,14 +310,18 @@ function platform(command, targets, opts) { // Verify that targets look like platforms. Examples: // - android // - android@3.5.0 + // - ../path/to/dir/with/platform/files if (targets) { if (!(targets instanceof Array)) targets = [targets]; - var err; targets.forEach(function(t) { // Trim the @version part if it's there. var p = t.split('@')[0]; // OK if it's one of known platform names. if ( p in platforms ) return; + // Not a known platform name, check if its a real path. + var pPath = path.resolve(t); + if (fs.existsSync(pPath)) return; + // Neither path, nor platform name - throw. var msg = 'Platform "' + t + '" not recognized as a core cordova platform. See `' + cordova_util.binname + ' platform list`.'