Return-Path: X-Original-To: apmail-cordova-dev-archive@www.apache.org Delivered-To: apmail-cordova-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id EB58E10A31 for ; Thu, 22 Jan 2015 20:54:00 +0000 (UTC) Received: (qmail 79289 invoked by uid 500); 22 Jan 2015 20:54:00 -0000 Delivered-To: apmail-cordova-dev-archive@cordova.apache.org Received: (qmail 79246 invoked by uid 500); 22 Jan 2015 20:54:00 -0000 Mailing-List: contact dev-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 dev@cordova.apache.org Received: (qmail 79163 invoked by uid 99); 22 Jan 2015 20:54:00 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 22 Jan 2015 20:54:00 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 35A7AE03A3; Thu, 22 Jan 2015 20:54:00 +0000 (UTC) From: agrieve To: dev@cordova.apache.org Reply-To: dev@cordova.apache.org References: In-Reply-To: Subject: [GitHub] cordova-lib pull request: CB-8239 Add support for git urls to 'cor... Content-Type: text/plain Message-Id: <20150122205400.35A7AE03A3@git1-us-west.apache.org> Date: Thu, 22 Jan 2015 20:54:00 +0000 (UTC) Github user agrieve commented on a diff in the pull request: https://github.com/apache/cordova-lib/pull/148#discussion_r23408840 --- Diff: cordova-lib/src/cordova/platform.js --- @@ -71,102 +72,98 @@ function add(hooksRunner, projectRoot, targets, opts) { // The "platforms" dir is safe to delete, it's almost equivalent to // cordova platform rm - if ( !fs.existsSync(platformsDir)) { + if (!fs.existsSync(platformsDir)) { shell.mkdir('-p', platformsDir); } return hooksRunner.fire('before_platform_add', opts) - .then(function() { - return promiseutil.Q_chainmap(targets, function(target) { + .then(function () { + return promiseutil.Q_chainmap(targets, function (target) { // For each platform, download it and call its "create" script. var parts = target.split('@'); var platform = parts[0]; var version = parts[1]; - return Q.when().then(function() { + return Q.when().then(function () { if (!(platform in platforms)) { - return getPlatformDetailsFromDir(target); - } else { + // First, try handling 'platform' as a directory, if it fails, try handling it as a git repository + return Q.fcall(function () { + return util.getPlatformDetailsFromDir(target); + }).fail(function (err) { + // Maybe it's a git repo + events.emit('verbose', err); + events.emit('verbose', 'Could not find local folder ' + target + '. Try to handle it as git repository.'); + return cloneGitRepo(target); + }); + } + else { if (!version) { events.emit('verbose', 'No version supplied. Retrieving version from config.xml...'); } version = version || getVersionFromConfigFile(platform, cfg); var tgt = version ? (platform + '@' + version) : platform; - return isDirectory(version) ? getPlatformDetailsFromDir(version) : downloadPlatform(projectRoot, tgt, opts); + + if (isDirectory(version)) { + return util.getPlatformDetailsFromDir(version); + } + + return Q.fcall(function () { + return downloadPlatform(projectRoot, tgt, opts); + }).fail(function (err) { + // Maybe it's a git repo + events.emit('verbose', err); + events.emit('verbose', 'Could not download platform ' + tgt + '. Try to handle ' + version + ' as git repository.'); + return cloneGitRepo(version); + }); } - }).then(function(platDetails) { + }).then(function (platDetails) { var template = config_json && config_json.lib && config_json.lib[platform] && config_json.lib[platform].template || null; return call_into_create(platDetails.platform, projectRoot, cfg, platDetails.libDir, template, opts); + }).fail(function (error) { + throw new CordovaError('Unable to add platform ' + target + '. Make sure to provide a valid version, an existing folder or an accessible git repository: ' + + error); }); + }).then(function () { + return hooksRunner.fire('after_platform_add', opts); }); - }) - .then(function() { - return hooksRunner.fire('after_platform_add', opts); }); } -function isDirectory(dir) { - try { +function isDirectory(dir){ + try{ return fs.lstatSync(dir).isDirectory(); - } catch(e) { - return false; } + catch(e){ + return false; + } } -// Returns a Promise -function downloadPlatform(projectRoot, target, opts) { - // Using lazy_load for a platform specified by name - return lazy_load.based_on_config(projectRoot, target, opts) - .then(function (libDir) { - return { - platform: target.split('@')[0], - libDir: libDir - }; - }).fail(function (err) { - throw new CordovaError('Unable to fetch platform ' + target + ': ' + err); - }); -} - -function getPackageJsonContent(pPath) { - return require(path.join(pPath, 'package')); -} - -function resolvePath(pPath){ - return path.resolve(pPath); +function cloneGitRepo(gitRepo) +{ + // Check all exit points and make sure their return types match to expected one. + return lazy_load.git_clone(gitRepo) + .then(function(clone) { + // After cloning, retrieve the platform details from dir + return util.getPlatformDetailsFromDir(clone.libDir); + }) + .then(function(platDetails){ --- End diff -- this block is a no-op --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastructure@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org For additional commands, e-mail: dev-help@cordova.apache.org