cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From purplecabb...@apache.org
Subject [3/5] git commit: applied same addReference logic to csproj for WP8
Date Wed, 19 Feb 2014 00:38:34 GMT
applied same addReference logic to csproj for WP8


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

Branch: refs/heads/master
Commit: 7682173465edce2dddc514dc8dd1472475ec2b8f
Parents: f541d3c
Author: Jesse MacFadyen <purplecabbage@gmail.com>
Authored: Mon Feb 17 23:24:14 2014 -0800
Committer: Jesse MacFadyen <purplecabbage@gmail.com>
Committed: Mon Feb 17 23:24:14 2014 -0800

----------------------------------------------------------------------
 src/platforms/wp8.js | 30 +++++++++++++++++++++++
 src/util/csproj.js   | 41 ++++++++++++++++++++++++++++++-
 src/util/w8jsproj.js | 62 ++++++++++++++++++-----------------------------
 3 files changed, 93 insertions(+), 40 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/76821734/src/platforms/wp8.js
----------------------------------------------------------------------
diff --git a/src/platforms/wp8.js b/src/platforms/wp8.js
index 2ffb9a5..e4d73bb 100644
--- a/src/platforms/wp8.js
+++ b/src/platforms/wp8.js
@@ -59,5 +59,35 @@ module.exports = {
         },
         uninstall:function(el, project_dir) {
         }
+    },
+    "framework":{
+        install:function(el, plugin_dir, project_dir, plugin_id, project_file) {
+            require('../../plugman').emit('verbose', 'wp8 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', 'wp8 framework uninstall :: ' + plugin_id
 );
+
+            var src = el.attrib['src'];
+            var isCustom = el.attrib.custom == "true";
+
+            if(isCustom) {
+                var dest = path.join('plugins', plugin_id);
+                common.removeFile(project_dir, dest);
+            }
+
+            project_file.removeReference(src);            
+        }
     }
 };

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/76821734/src/util/csproj.js
----------------------------------------------------------------------
diff --git a/src/util/csproj.js b/src/util/csproj.js
index fb67158..92e3f06 100644
--- a/src/util/csproj.js
+++ b/src/util/csproj.js
@@ -1,6 +1,7 @@
 var xml_helpers = require('./xml-helpers'),
     et = require('elementtree'),
-    fs = require('fs');
+    fs = require('fs'),
+    path = require('path');
 
 function csproj(location) {
     this.location = location;
@@ -12,6 +13,43 @@ csproj.prototype = {
     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);
+
+        var elem = new et.Element('Reference');
+        // add dll file name
+        elem.attrib.Include = path.basename(relPath, extName);
+        // add hint path with full path
+        var hint_path = new et.Element('HintPath');
+        hint_path.text = relPath;
+        elem.append(hint_path);
+
+        if(extName == ".winmd") {
+            var mdFileTag = new et.Element("IsWinMDFile");
+                mdFileTag.text = "true";
+            elem.append(mdFileTag);
+        }
+
+        item.append(elem);
+        
+        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
+ '"]/..');
+
+        if(item_groups.length > 0 ) {
+            this.xml.getroot().remove(0, item_groups[0]);
+        }
+    },
+
     addSourceFile:function(relative_path) {
         relative_path = relative_path.split('/').join('\\');
         // make ItemGroup to hold file.
@@ -70,6 +108,7 @@ csproj.prototype = {
         }
         this.xml.getroot().append(item);
     },
+
     removeSourceFile:function(relative_path) {
         relative_path = relative_path.split('/').join('\\');
         var item_groups = this.xml.findall('ItemGroup');

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/76821734/src/util/w8jsproj.js
----------------------------------------------------------------------
diff --git a/src/util/w8jsproj.js b/src/util/w8jsproj.js
index c2a9f76..943d4bd 100644
--- a/src/util/w8jsproj.js
+++ b/src/util/w8jsproj.js
@@ -15,24 +15,6 @@ 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,
@@ -41,16 +23,34 @@ jsproj.prototype = {
     },
 
     addReference:function(relPath) {
+        require('../../plugman').emit('verbose','addReference::' + relPath);
+
         var item = new et.Element('ItemGroup');
         var extName = path.extname(relPath);
 
-        item.append(getBinaryResource(relPath,extName == ".dll"));
-        
+        var elem = new et.Element('Reference');
+        // add file name
+        elem.attrib.Include = path.basename(relPath, extName);
+
+        // add hint path with full path
+        var hint_path = new et.Element('HintPath');
+            hint_path.text = relPath;
 
+        elem.append(hint_path);
+
+        if(extName == ".winmd") {
+            var mdFileTag = new et.Element("IsWinMDFile");
+                mdFileTag.text = "true";
+            elem.append(mdFileTag);
+        }
+
+        item.append(elem);
         this.xml.getroot().append(item);
     },
     
     removeReference:function(relPath) {
+        require('../../plugman').emit('verbose','removeReference::' + relPath);
+
         var item = new et.Element('ItemGroup');
         var extName = path.extname(relPath);
         var includeText = path.basename(relPath,extName);
@@ -64,7 +64,6 @@ jsproj.prototype = {
     },
 
     addSourceFile:function(relative_path) {
-        console.log("addSourceFile::" + relative_path);
 
         relative_path = relative_path.split('/').join('\\');
         // make ItemGroup to hold file.
@@ -78,10 +77,12 @@ jsproj.prototype = {
     },
 
     removeSourceFile:function(relative_path) {
-        console.log("removeSourceFile::" + relative_path);
 
+        // path.normalize(relative_path);// ??
         relative_path = relative_path.split('/').join('\\');
 
+        // var oneStep = this.xml.findall('ItemGroup/Content[@Include="' + relative_path
+ '""]/..');
+
         var item_groups = this.xml.findall('ItemGroup');
         for (var i = 0, l = item_groups.length; i < l; i++) {
             var group = item_groups[i];
@@ -99,23 +100,6 @@ 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