You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by an...@apache.org on 2015/03/06 23:37:42 UTC

[2/3] cordova-lib git commit: CB-8499 When deleting a platform, remove it from platforms.json

CB-8499 When deleting a platform, remove it from platforms.json


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

Branch: refs/heads/master
Commit: fc96f4911f615ab4a53d62e2e69350a4bce30288
Parents: 53714bd
Author: Omar Mefire <om...@microsoft.com>
Authored: Wed Feb 18 12:21:12 2015 -0800
Committer: Vladimir Kotikov <an...@ya.ru>
Committed: Fri Mar 6 23:26:48 2015 +0300

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


http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/fc96f491/cordova-lib/src/cordova/platform.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/cordova/platform.js b/cordova-lib/src/cordova/platform.js
index e2b82dd..6b902d3 100644
--- a/cordova-lib/src/cordova/platform.js
+++ b/cordova-lib/src/cordova/platform.js
@@ -211,6 +211,19 @@ function savePlatformVersion(platformsDir, platform, version) {
     fs.writeFileSync(jsonPath, JSON.stringify(data, null, 4), 'utf-8');
 }
 
+function removePlatformVersion(platformsDir, platform){
+    var jsonPath = path.join(platformsDir, 'platforms.json');
+    if(!fs.existsSync(jsonPath)){
+        return;
+    }
+    var data = getJson(jsonPath);
+
+    // test: what if version is null ? non-null ?
+    delete data[platform]; //test: what if data[platform] is null? non-null?
+    // how does JSON.stringify() work ?
+    fs.writeFileSync(jsonPath, JSON.stringify(data, null, 4), 'utf-8');
+}
+
 function getJson(jsonPath) {  // jsonPath -> jsonFile  
     return JSON.parse(fs.readFileSync(jsonPath, 'utf-8'));
 }
@@ -311,8 +324,14 @@ function remove(hooksRunner, projectRoot, targets, opts) {
 		cfg.write();
 	    });
 	}
-    })
-    .then(function() {
+    }).then(function() {
+        // Remove targets from platforms.json
+        var platformsDir = path.join(projectRoot, 'platforms');
+        targets.forEach(function(target) {
+            events.emit('verbose', 'Removing ' + target + ' from platforms.json file ...');
+            removePlatformVersion(platformsDir, target);
+        });
+    }).then(function() {
         return hooksRunner.fire('after_platform_rm', opts);
     });
 }


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