cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From an-s...@apache.org
Subject cordova-lib git commit: CB-8227 CB8237 CB-8238 Add --save flag and autosave to 'cordova platform add', 'cordova platform remove' and 'cordova platform update'
Date Mon, 09 Feb 2015 10:45:15 GMT
Repository: cordova-lib
Updated Branches:
  refs/heads/master 0ee180cd1 -> b7eabab1d


CB-8227 CB8237 CB-8238 Add --save flag and autosave to 'cordova platform add',
'cordova platform remove' and 'cordova platform update'


Project: http://git-wip-us.apache.org/repos/asf/cordova-lib/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-lib/commit/b7eabab1
Tree: http://git-wip-us.apache.org/repos/asf/cordova-lib/tree/b7eabab1
Diff: http://git-wip-us.apache.org/repos/asf/cordova-lib/diff/b7eabab1

Branch: refs/heads/master
Commit: b7eabab1d8cee081a8baf4394cf16368f2b9c934
Parents: 0ee180c
Author: Omar Mefire <ommenjik@microsoft.com>
Authored: Thu Jan 1 21:15:21 2015 -0800
Committer: Omar Mefire <ommenjik@microsoft.com>
Committed: Thu Feb 5 09:37:03 2015 -0800

----------------------------------------------------------------------
 cordova-lib/src/cordova/platform.js | 33 ++++++++++++++++++++++++++++++--
 1 file changed, 31 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/b7eabab1/cordova-lib/src/cordova/platform.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/cordova/platform.js b/cordova-lib/src/cordova/platform.js
index 7df0e51..76ca330 100644
--- a/cordova-lib/src/cordova/platform.js
+++ b/cordova-lib/src/cordova/platform.js
@@ -70,6 +70,7 @@ function addHelper(cmd, hooksRunner, projectRoot, targets, opts) {
     var xml = cordova_util.projectConfig(projectRoot);
     var cfg = new ConfigParser(xml);
     var config_json = config.read(projectRoot);
+    var autosave =  config_json.auto_save_platforms || false;
     opts = opts || {};
     opts.searchpath = opts.searchpath || config_json.plugin_search_path;
 
@@ -90,6 +91,12 @@ function addHelper(cmd, hooksRunner, projectRoot, targets, opts) {
                     version = platform;
                     platform = null;
                 }
+
+                // If --save/autosave on && no version specified, use the pinned
version
+                // e.g: 'cordova platform add android --save', 'cordova platform update android
--save'
+                if( (opts.save || autosave) && !version ){
+                    version = platforms[platform].version;
+                }
                 if (platform && !version && cmd == 'add') {
                     events.emit('verbose', 'No version supplied. Retrieving version from
config.xml...');
                     version = getVersionFromConfigFile(platform, cfg);
@@ -100,7 +107,6 @@ function addHelper(cmd, hooksRunner, projectRoot, targets, opts) {
                 return downloadPlatform(projectRoot, platform, version, opts);
             }).then(function(platDetails) {
                 platform = platDetails.platform;
-                version = platDetails.version;
                 var platformPath = path.join(projectRoot, 'platforms', platform);
                 var platformAlreadyAdded = fs.existsSync(platformPath);
 
@@ -147,6 +153,15 @@ function addHelper(cmd, hooksRunner, projectRoot, targets, opts) {
                     if (cmd == 'add') {
                         return installPluginsForNewPlatform(platform, projectRoot, cfg, opts);
                     }
+                }).then(function() {
+                    if(opts.save || autosave){
+                        // Save target into config.xml, overriding already existing settings
+                        events.emit('log', '--save flag or autosave detected');
+                        events.emit('log', 'Saving ' + platform + '@' + version + ' into
config.xml file ...');
+                        cfg.removeEngine(platform);
+                        cfg.addEngine(platform, version);
+                        cfg.write();
+                    }                    
                 });
             });
         });
@@ -254,6 +269,20 @@ function remove(hooksRunner, projectRoot, targets, opts) {
             if (fs.existsSync(plugins_json)) shell.rm(plugins_json);
         });
     }).then(function() {
+        var config_json = config.read(projectRoot);
+        var autosave =  config_json.auto_save_platforms || false;
+	if(opts.save || autosave){
+	    targets.forEach(function(target) {
+		var platformId = target.split('@')[0];
+		var xml = cordova_util.projectConfig(projectRoot);
+		var cfg = new ConfigParser(xml);
+		events.emit('log', 'Removing ' + target + ' from config.xml file ...');
+		cfg.removeEngine(platformId);
+		cfg.write();
+	    });
+	}
+    })
+    .then(function() {
         return hooksRunner.fire('after_platform_rm', opts);
     });
 }
@@ -464,7 +493,7 @@ function platform(command, targets, opts) {
         case 'add':
             // CB-6976 Windows Universal Apps. windows8 is now alias for windows
             var idxWindows8 = targets.indexOf('windows8');
-            if (idxWindows8 >= 0) {
+            if (idxWindows8 >=0) {
                 targets[idxWindows8] = 'windows';
             }
             return add(hooksRunner, projectRoot, targets, opts);


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message