Repository: cordova-lib
Updated Branches:
  refs/heads/master 71c380a53 -> 68a0b5b7a


CB-6874 Consolidate <Content> tag additions into 1 ItemGroup


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

Branch: refs/heads/master
Commit: d2605c7e981df14528eea34dbcbb122e82d7932f
Parents: ab49973
Author: sgrebnov <[email protected]>
Authored: Tue Jul 8 16:01:32 2014 +0400
Committer: sgrebnov <[email protected]>
Committed: Tue Jul 8 16:01:32 2014 +0400

----------------------------------------------------------------------
 .../src/cordova/metadata/windows_parser.js      |  5 +-
 cordova-lib/src/cordova/metadata/wp8_parser.js  |  4 +-
 cordova-lib/src/util/windows/csproj.js          | 84 +++++++++++---------
 cordova-lib/src/util/windows/jsproj.js          | 21 +++--
 4 files changed, 62 insertions(+), 52 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/d2605c7e/cordova-lib/src/cordova/metadata/windows_parser.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/cordova/metadata/windows_parser.js 
b/cordova-lib/src/cordova/metadata/windows_parser.js
index 5233167..9de55c5 100644
--- a/cordova-lib/src/cordova/metadata/windows_parser.js
+++ b/cordova-lib/src/cordova/metadata/windows_parser.js
@@ -284,9 +284,8 @@ module.exports.prototype = {
 
         // now add all www references back in from the root www folder
         var www_files = this.folder_contents('www', this.www_dir());
-        for(var file in www_files) {
-            projFile.addSourceFile(www_files[file]);
-        }
+        projFile.addSourceFile(www_files);
+
         // save file
         projFile.write();
     },

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/d2605c7e/cordova-lib/src/cordova/metadata/wp8_parser.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/cordova/metadata/wp8_parser.js 
b/cordova-lib/src/cordova/metadata/wp8_parser.js
index f305209..54231b5 100644
--- a/cordova-lib/src/cordova/metadata/wp8_parser.js
+++ b/cordova-lib/src/cordova/metadata/wp8_parser.js
@@ -230,9 +230,7 @@ module.exports.prototype = {
 
         // now add all www references back in from the root www folder
         var www_files = this.folder_contents('www', this.www_dir());
-        for(var file in www_files) {
-            projFile.addSourceFile(www_files[file]);
-        }
+        projFile.addSourceFile(www_files);
         // save file
         projFile.write();
     },

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/d2605c7e/cordova-lib/src/util/windows/csproj.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/util/windows/csproj.js 
b/cordova-lib/src/util/windows/csproj.js
index 90f84da..a422bba 100644
--- a/cordova-lib/src/util/windows/csproj.js
+++ b/cordova-lib/src/util/windows/csproj.js
@@ -73,50 +73,58 @@ csproj.prototype = {
     },
 
     addSourceFile:function(relative_path) {
+        // we allow multiple paths to be passed at once as array so that
+        // we don't create separate ItemGroup for each source file, CB-6874
+        if (!(relative_path instanceof Array)) {
+            relative_path = [relative_path];
+        }
         var compile;
-        relative_path = relative_path.split('/').join('\\');
         // make ItemGroup to hold file.
         var item = new et.Element('ItemGroup');
+        var me = this;
+        relative_path.forEach(function(filePath) {
+
+            filePath = filePath.split('/').join('\\');
+            var extName = path.extname(filePath);
+            // check if it's a .xaml page
+            if(extName == '.xaml') {
+                var page = new et.Element('Page');
+                var sub_type = new et.Element('SubType');
+
+                sub_type.text = 'Designer';
+                page.append(sub_type);
+                page.attrib.Include = filePath;
+
+                var gen = new et.Element('Generator');
+                gen.text = 'MSBuild:Compile';
+                page.append(gen);
+                var item_groups = me.xml.findall('ItemGroup');
+                if(item_groups.length === 0) {
+                    item.append(page);
+                } else {
+                    item_groups[0].append(page);
+                }
 
-        var extName = path.extname(relative_path);
-        // check if it's a .xaml page
-        if(extName == '.xaml') {
-            var page = new et.Element('Page');
-            var sub_type = new et.Element('SubType');
-
-            sub_type.text = 'Designer';
-            page.append(sub_type);
-            page.attrib.Include = relative_path;
-
-            var gen = new et.Element('Generator');
-            gen.text = 'MSBuild:Compile';
-            page.append(gen);
-
-            var item_groups = this.xml.findall('ItemGroup');
-            if(item_groups.length === 0) {
-                item.append(page);
-            } else {
-                item_groups[0].append(page);
             }
-        }
-        else if (extName == '.cs') {
-            compile = new et.Element('Compile');
-            compile.attrib.Include = relative_path;
-            // check if it's a .xaml.cs page that would depend on a .xaml of 
the same name
-            if (relative_path.indexOf('.xaml.cs', relative_path.length - 8) > 
-1) {
-                var dep = new et.Element('DependentUpon');
-                var parts = relative_path.split('\\');
-                var xaml_file = parts[parts.length - 1].substr(0, 
parts[parts.length - 1].length - 3); // Benn, really !?
-                dep.text = xaml_file;
-                compile.append(dep);
+            else if (extName == '.cs') {
+                compile = new et.Element('Compile');
+                compile.attrib.Include = filePath;
+                // check if it's a .xaml.cs page that would depend on a .xaml 
of the same name
+                if (filePath.indexOf('.xaml.cs', filePath.length - 8) > -1) {
+                    var dep = new et.Element('DependentUpon');
+                    var parts = filePath.split('\\');
+                    var xaml_file = parts[parts.length - 1].substr(0, 
parts[parts.length - 1].length - 3); // Benn, really !?
+                    dep.text = xaml_file;
+                    compile.append(dep);
+                }
+                item.append(compile);
             }
-            item.append(compile);
-        }
-        else { // otherwise add it normally
-            compile = new et.Element('Content');
-            compile.attrib.Include = relative_path;
-            item.append(compile);
-        }
+            else { // otherwise add it normally
+                compile = new et.Element('Content');
+                compile.attrib.Include = filePath;
+                item.append(compile);
+            }
+        });
         this.xml.getroot().append(item);
     },
 

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/d2605c7e/cordova-lib/src/util/windows/jsproj.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/util/windows/jsproj.js 
b/cordova-lib/src/util/windows/jsproj.js
index 538e44b..d1cd7e4 100644
--- a/cordova-lib/src/util/windows/jsproj.js
+++ b/cordova-lib/src/util/windows/jsproj.js
@@ -124,17 +124,22 @@ jsproj.prototype = {
     },
 
     addSourceFile:function(relative_path) {
-
-        relative_path = relative_path.split('/').join('\\');
-        relative_path = this.isUniversalWindowsApp ? 
'$(MSBuildThisFileDirectory)' + relative_path : relative_path;
-
+        // we allow multiple paths to be passed at once as array so that
+        // we don't create separate ItemGroup for each source file, CB-6874
+        if (!(relative_path instanceof Array)) {
+            relative_path = [relative_path];
+        }
         // 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);
-
+        relative_path.forEach(function(filePath) {
+            filePath = filePath.split('/').join('\\');
+            filePath = this.isUniversalWindowsApp ? 
'$(MSBuildThisFileDirectory)' + filePath : filePath;
+            
+            var content = new et.Element('Content');
+            content.attrib.Include = filePath;
+            item.append(content);
+        });
         this.xml.getroot().append(item);
     },
 

Reply via email to