cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From an-s...@apache.org
Subject [1/3] cordova-lib git commit: CB-8499 When adding a platform, capture version/folder/url being added to allow us to be able to save all installed platforms and their versions later on by doing 'cordova platform save'
Date Fri, 06 Mar 2015 22:37:41 GMT
Repository: cordova-lib
Updated Branches:
  refs/heads/master d2c99fc6c -> 764c9cb12


CB-8499 When adding a platform, capture version/folder/url being added to allow us to be able
to save all installed platforms and their versions later on by doing 'cordova platform save'


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

Branch: refs/heads/master
Commit: 53714bd75b6d89b623a74ddf77a4a736af893d81
Parents: d2c99fc
Author: Omar Mefire <ommenjik@microsoft.com>
Authored: Wed Feb 18 11:15:53 2015 -0800
Committer: Vladimir Kotikov <an-selm@ya.ru>
Committed: Fri Mar 6 23:26:47 2015 +0300

----------------------------------------------------------------------
 cordova-lib/src/cordova/platform.js | 41 +++++++++++++++++++++++++++++++-
 1 file changed, 40 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/53714bd7/cordova-lib/src/cordova/platform.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/cordova/platform.js b/cordova-lib/src/cordova/platform.js
index c599734..e2b82dd 100644
--- a/cordova-lib/src/cordova/platform.js
+++ b/cordova-lib/src/cordova/platform.js
@@ -75,7 +75,8 @@ function addHelper(cmd, hooksRunner, projectRoot, targets, opts) {
 
     // The "platforms" dir is safe to delete, it's almost equivalent to
     // cordova platform rm <list of all platforms>
-    shell.mkdir('-p', path.join(projectRoot, 'platforms'));
+    var platformsDir = path.join(projectRoot, 'platforms');
+    shell.mkdir('-p', platformsDir);
 
     return hooksRunner.fire('before_platform_' + cmd, opts)
     .then(function() {
@@ -162,6 +163,8 @@ function addHelper(cmd, hooksRunner, projectRoot, targets, opts) {
                         return installPluginsForNewPlatform(platform, projectRoot, cfg, opts);
                     }
                 }).then(function() {
+                    savePlatformVersion(platformsDir, platform, version);
+                }).then(function() {
                     if(opts.save || autosave){
                         // Save target into config.xml, overriding already existing settings
                         events.emit('log', '--save flag or autosave detected');
@@ -178,6 +181,40 @@ function addHelper(cmd, hooksRunner, projectRoot, targets, opts) {
     });
 }
 
+// save the platform's installed or updated version
+// tests: add, update
+// 
+function savePlatformVersion(platformsDir, platform, version) {
+    debugger;
+    // if no version set, save current edge version
+    if(!version){
+        version = platforms[platform].version;
+    }
+
+    events.emit('verbose', 'saving ' + platform + '@' + version + ' into platforms.json');
+    
+    // test: what if platforms.json already contains this platform and version => override
it
+    // test: what if platforms.json is empty ?
+    // test: what if platforms.json hasn't been created yet ? => create it and write into
it
+    var jsonPath = path.join(platformsDir, 'platforms.json');
+    if(!fs.existsSync(jsonPath)){
+        // ugly. create in a better way
+        var fd = fs.openSync(jsonPath, 'w'); // test: what if there is an error while creating
? 
+        fs.writeFileSync(jsonPath, JSON.stringify({}, null, 4), 'utf-8');
+        fs.closeSync(fd);
+    }
+    var data = getJson(jsonPath);
+
+    // test: what if version is null ? non-null ?
+    data[platform] = version; //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'));
+}
+
 // Downloads via npm or via git clone (tries both)
 // Returns a Promise
 function downloadPlatform(projectRoot, platform, version, opts) {
@@ -498,6 +535,8 @@ function platform(command, targets, opts) {
             return update(hooksRunner, projectRoot, targets, opts);
         case 'check':
             return check(hooksRunner, projectRoot);
+        //case 'save':
+            //return save(hooksRunner, projectRoot);
         default:
             return list(hooksRunner, projectRoot);
     }


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


Mime
View raw message