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 <list of all platforms> - 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 infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@cordova.apache.org For additional commands, e-mail: dev-h...@cordova.apache.org