[
https://issues.apache.org/jira/browse/CB-8239?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14288198#comment-14288198
]
ASF GitHub Bot commented on CB-8239:
------------------------------------
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
> Add support for git urls to 'cordova platform add'
> --------------------------------------------------
>
> Key: CB-8239
> URL: https://issues.apache.org/jira/browse/CB-8239
> Project: Apache Cordova
> Issue Type: New Feature
> Components: CLI, CordovaLib
> Reporter: Omar Mefire
>
> Allow the following scenarios:
> - users can issue 'cordova platform add
> https://github.com/apache/cordova-android.git' and the git repo will be
> cloned and used.
> - users can issue 'cordova platform add
> android@https://github.com/apache/cordova-android.git' and the git repo will
> be cloned and used.
> - users can issue 'cordova platform add android' and if their config.xml file
> contains: '<engine id='android'
> version='https://github.com/apache/cordova-android.git' />, then the git repo
> pointed to by config.xml will be cloned and used.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]