cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From purplecabb...@apache.org
Subject [1/5] git commit: added ability to add+remove ref to .winmd files
Date Wed, 19 Feb 2014 00:38:32 GMT
Repository: cordova-plugman
Updated Branches:
  refs/heads/master d082830b9 -> 5d09da295


added ability to add+remove ref to .winmd files


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

Branch: refs/heads/master
Commit: 0fe9cf223a538ea27e947a016e39d1ac0a5887b5
Parents: f0a339f
Author: Jesse MacFadyen <purplecabbage@gmail.com>
Authored: Fri Feb 14 17:09:26 2014 -0800
Committer: Jesse MacFadyen <purplecabbage@gmail.com>
Committed: Fri Feb 14 17:09:26 2014 -0800

----------------------------------------------------------------------
 src/platforms/windows8.js | 30 +++++++++++++++++
 src/util/w8jsproj.js      | 75 ++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 103 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/0fe9cf22/src/platforms/windows8.js
----------------------------------------------------------------------
diff --git a/src/platforms/windows8.js b/src/platforms/windows8.js
index bd25562..426c4ff 100644
--- a/src/platforms/windows8.js
+++ b/src/platforms/windows8.js
@@ -64,5 +64,35 @@ module.exports = {
         },
         uninstall:function(el, project_dir) {
         }
+    },
+    "framework": {
+        install:function(el, plugin_dir, project_dir, plugin_id, project_file) {
+            require('../../plugman').emit('verbose', 'windows8 framework install :: ' + plugin_id);
+
+            var src = el.attrib['src'];
+            var dest = src; // if !isCustom, we will just add a reference to the file in
place
+            var isCustom = el.attrib.custom == "true";
+
+            if(isCustom) {
+                dest = path.join('plugins', plugin_id, path.basename(src));
+                common.copyFile(plugin_dir, src, project_dir, dest);
+            }
+
+            project_file.addReference(dest);
+
+        },
+        uninstall:function(el, project_dir, plugin_id, project_file) {
+            require('../../plugman').emit('verbose', 'windows8 framework uninstall :: ' +
plugin_id  );
+
+            var src = el.attrib['src'];
+            var isCustom = el.attrib.custom == "true";
+
+            if(isCustom) {
+                var dest = path.join('plugins', plugin_id);//, path.basename(src));
+                common.removeFile(project_dir, dest);
+            }
+
+            project_file.removeReference(src);
+        }
     }
 };

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/0fe9cf22/src/util/w8jsproj.js
----------------------------------------------------------------------
diff --git a/src/util/w8jsproj.js b/src/util/w8jsproj.js
index bd5dd41..c28d92a 100644
--- a/src/util/w8jsproj.js
+++ b/src/util/w8jsproj.js
@@ -5,7 +5,8 @@
 
 var xml_helpers = require('./xml-helpers'),
     et = require('elementtree'),
-    fs = require('fs');
+    fs = require('fs'),
+    path = require('path');
 
 function jsproj(location) {
     require('../../plugman').emit('verbose','creating jsproj from project at : ' + location);
@@ -14,24 +15,77 @@ function jsproj(location) {
     return this;
 }
 
+function getBinaryResource(relPath,bIsDLL) {
+    var elem = new et.Element('Reference');
+    // add dll file name
+    elem.attrib.Include = path.basename(relPath, bIsDLL ? '.dll' : ".winmd");
+    // add hint path with full path
+    var hint_path = new et.Element('HintPath');
+        hint_path.text = relPath;
+    elem.append(hint_path);
+
+    if(!bIsDLL) {
+        var mdFileTag = new et.Element("IsWinMDFile");
+            mdFileTag.text = "true";
+        elem.append(mdFileTag);
+    }
+
+    return elem;
+}
+
 jsproj.prototype = {
     location:null,
     xml:null,
     write:function() {
         fs.writeFileSync(this.location, this.xml.write({indent:4}), 'utf-8');
     },
+
+    addReference:function(relPath) {
+        var item = new et.Element('ItemGroup');
+        var extName = path.extname(relPath);
+
+        item.append(getBinaryResource(relPath,extName == ".dll"));
+        
+
+        this.xml.getroot().append(item);
+    },
+    removeReference:function(relPath) {
+        var item = new et.Element('ItemGroup');
+        var extName = path.extname(relPath);
+        var includeText = path.basename(relPath,extName);
+
+
+        // <ItemGroup>
+        //   <Reference Include="WindowsRuntimeComponent1">
+
+        var item_groups = this.xml.findall('ItemGroup/Reference[@Include="' + includeText
+ '"]/..');
+
+        console.log("item_groups.length = " + item_groups.length);
+
+        if(item_groups.length > 0 ) {
+            this.xml.getroot().remove(0, item_groups[0]);
+        }
+    },
+
     addSourceFile:function(relative_path) {
+        console.log("addSourceFile::" + relative_path);
+
         relative_path = relative_path.split('/').join('\\');
         // make ItemGroup to hold file.
         var item = new et.Element('ItemGroup');
 
         var content = new et.Element('Content');
             content.attrib.Include = relative_path;
-            item.append(content);
+        item.append(content);
+
         this.xml.getroot().append(item);
     },
+
     removeSourceFile:function(relative_path) {
+        console.log("removeSourceFile::" + relative_path);
+
         relative_path = relative_path.split('/').join('\\');
+
         var item_groups = this.xml.findall('ItemGroup');
         for (var i = 0, l = item_groups.length; i < l; i++) {
             var group = item_groups[i];
@@ -49,6 +103,23 @@ jsproj.prototype = {
                     return true;
                 }
             }
+
+            // for removing .dll reference
+            // var references = group.findall('Reference');
+            // for (var j = 0, k = references.length; j < k; j++) {
+            //     var reference = references[j];
+            //     var dll_name = path.basename(relative_path, '.dll');
+            //     if(reference.attrib.Include == dll_name) {
+            //         // remove file reference
+            //         group.remove(0, reference);
+            //          // remove ItemGroup if empty
+            //         var new_group = group.findall('Compile').concat(group.findall('Page'));
// ??? -jm
+            //         if(new_group.length < 1) {
+            //             this.xml.getroot().remove(0, group);
+            //         }
+            //         return true;
+            //     }
+            // }
         }
         return false;
     }


Mime
View raw message