cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [1/2] git commit: Wp now adds www content to .csproj file
Date Mon, 15 Jul 2013 21:45:52 GMT
Updated Branches:
  refs/heads/plugman-registry ae545bc86 -> d10834690


Wp now adds www content to .csproj file


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

Branch: refs/heads/plugman-registry
Commit: 24e452a583c8e2d0f115d6d6b3a2184fd76ed91e
Parents: b340813
Author: Benn Mapes <benn.mapes@gmail.com>
Authored: Sun Jul 14 20:10:57 2013 -0700
Committer: Benn Mapes <benn.mapes@gmail.com>
Committed: Sun Jul 14 20:25:04 2013 -0700

----------------------------------------------------------------------
 src/platforms/wp7.js | 70 -----------------------------------------------
 src/platforms/wp8.js | 70 -----------------------------------------------
 src/prepare.js       | 33 ++++++++++++++++++++++
 src/util/csproj.js   |  7 ++++-
 4 files changed, 39 insertions(+), 141 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/24e452a5/src/platforms/wp7.js
----------------------------------------------------------------------
diff --git a/src/platforms/wp7.js b/src/platforms/wp7.js
index 4ede3f9..b1f1660 100644
--- a/src/platforms/wp7.js
+++ b/src/platforms/wp7.js
@@ -23,76 +23,6 @@ var common = require('./common'),
     csproj = require('../util/csproj');
     xml_helpers = require('../util/xml-helpers');
 
-/*
-var unix_projPath,  //  for use with glob
-    projectFilename,//  first csproj returned by glob unix_projPath
-    projPath,       //  full path to the project file, including file name
-    configFilePath, //  path to config.xml
-    assets,         //  assets node et in root ./asset
-    platformTag,    //  wp7 platform node et
-    sourceFiles,    //  ./source-file inside platform
-    hosts,          //  ./access inside root
-    projectChanges; //  <config-file target=".csproj" parent=".">, inside platform
-
-function initPaths(project_dir, plugin_dir, plugin_et, variables) {
-
-    unix_projPath = project_dir.split("\\").join("/");
-    configFilePath = path.join(unix_projPath,'config.xml');
-    projectFilename = glob.sync('*.csproj',{nocase:true,cwd:unix_projPath})[0];
-    projPath = path.join(unix_projPath,projectFilename);
-    assets = plugin_et.findall('./asset');
-    platformTag = plugin_et.find('./platform[@name="wp7"]');
-    sourceFiles = platformTag.findall('./source-file');
-    projectChanges = platformTag.findall('./config-file[@target=".csproj"]');
-    hosts = plugin_et.findall('./access');
-}
-  projectChanges && projectChanges.forEach(function (configNode) {
-
-    var docStr = fs.readFileSync(projPath,"utf8");
-
-    // child is the configNode child that we will insert into csproj
-    var child = configNode.find('*'); 
-    // we use empty text as a default, so we always modify the project file so Visual Studio
will notice if open.
-    var newNodeText = "";
-    if(child) {
-
-      newNodeText = new et.ElementTree(child).write({xml_declaration:false});
-      newNodeText = newNodeText.split("&#xA;").join("\n").split("&#xD;").join("\r");
-      newNodeText += "\n\r";
-    }
-
-    // insert text right before closing tag
-    var newDocStr = docStr.replace("</Project>", newNodeText + "</Project>");
-
-    // save it, and get out
-    fs.writeFileSync(projPath, newDocStr);
-  });
-
-   projectChanges && projectChanges.forEach(function (configNode) {
-
-    var docStr = fs.readFileSync(projPath,"utf8");
-
-    // child is the configNode child that we will insert into csproj
-    var child = configNode.find('*'); 
-    if(child) {
-      var newNodeText = new et.ElementTree(child).write({xml_declaration:false});
-          
-      newNodeText = newNodeText.split("&#xA;").join("\n").split("&#xD;").join("\r");
-      
-      // insert text right before closing tag
-      var splitString = docStr.split(newNodeText);
-      console.log("split length = " + splitString.length);
-      var newDocStr = splitString.join("");
-
-      // save it, and get out
-      fs.writeFileSync(projPath, newDocStr);
-    }
-    else {
-      // this just lets Visual Studio know to reload the project if it is open
-      fs.writeFileSync(projPath, docStr);
-    }
-  });
-*/
 module.exports = {
     www_dir:function(project_dir) {
         return path.join(project_dir, 'www');

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/24e452a5/src/platforms/wp8.js
----------------------------------------------------------------------
diff --git a/src/platforms/wp8.js b/src/platforms/wp8.js
index aab4d8b..1b67d37 100644
--- a/src/platforms/wp8.js
+++ b/src/platforms/wp8.js
@@ -23,76 +23,6 @@ var common = require('./common'),
     csproj = require('../util/csproj');
     xml_helpers = require('../util/xml-helpers');
 
-/*
-var unix_projPath,  //  for use with glob
-    projectFilename,//  first csproj returned by glob unix_projPath
-    projPath,       //  full path to the project file, including file name
-    configFilePath, //  path to config.xml
-    assets,         //  assets node et in root ./asset
-    platformTag,    //  wp8 platform node et
-    sourceFiles,    //  ./source-file inside platform
-    hosts,          //  ./access inside root
-    projectChanges; //  <config-file target=".csproj" parent=".">, inside platform
-
-function initPaths(project_dir, plugin_dir, plugin_et, variables) {
-
-    unix_projPath = project_dir.split("\\").join("/");
-    configFilePath = path.join(unix_projPath,'config.xml');
-    projectFilename = glob.sync('*.csproj',{nocase:true,cwd:unix_projPath})[0];
-    projPath = path.join(unix_projPath,projectFilename);
-    assets = plugin_et.findall('./asset');
-    platformTag = plugin_et.find('./platform[@name="wp8"]');
-    sourceFiles = platformTag.findall('./source-file');
-    projectChanges = platformTag.findall('./config-file[@target=".csproj"]');
-    hosts = plugin_et.findall('./access');
-}
-  projectChanges && projectChanges.forEach(function (configNode) {
-
-    var docStr = fs.readFileSync(projPath,"utf8");
-
-    // child is the configNode child that we will insert into csproj
-    var child = configNode.find('*'); 
-    // we use empty text as a default, so we always modify the project file so Visual Studio
will notice if open.
-    var newNodeText = "";
-    if(child) {
-
-      newNodeText = new et.ElementTree(child).write({xml_declaration:false});
-      newNodeText = newNodeText.split("&#xA;").join("\n").split("&#xD;").join("\r");
-      newNodeText += "\n\r";
-    }
-
-    // insert text right before closing tag
-    var newDocStr = docStr.replace("</Project>", newNodeText + "</Project>");
-
-    // save it, and get out
-    fs.writeFileSync(projPath, newDocStr);
-  });
-
-   projectChanges && projectChanges.forEach(function (configNode) {
-
-    var docStr = fs.readFileSync(projPath,"utf8");
-
-    // child is the configNode child that we will insert into csproj
-    var child = configNode.find('*'); 
-    if(child) {
-      var newNodeText = new et.ElementTree(child).write({xml_declaration:false});
-          
-      newNodeText = newNodeText.split("&#xA;").join("\n").split("&#xD;").join("\r");
-      
-      // insert text right before closing tag
-      var splitString = docStr.split(newNodeText);
-      console.log("split length = " + splitString.length);
-      var newDocStr = splitString.join("");
-
-      // save it, and get out
-      fs.writeFileSync(projPath, newDocStr);
-    }
-    else {
-      // this just lets Visual Studio know to reload the project if it is open
-      fs.writeFileSync(projPath, docStr);
-    }
-  });
-*/
 module.exports = {
     www_dir:function(project_dir) {
         return path.join(project_dir, 'www');

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/24e452a5/src/prepare.js
----------------------------------------------------------------------
diff --git a/src/prepare.js b/src/prepare.js
index a694d75..b56c6bf 100644
--- a/src/prepare.js
+++ b/src/prepare.js
@@ -21,6 +21,8 @@ var platform_modules = require('./platforms'),
     path            = require('path'),
     config_changes  = require('./util/config-changes'),
     xml_helpers     = require('./util/xml-helpers'),
+    wp7             = require('./platforms/wp7'),
+    wp8             = require('./platforms/wp8'),
     fs              = require('fs'),
     shell           = require('shelljs'),
     util            = require('util'),
@@ -65,6 +67,30 @@ module.exports = function handlePrepare(project_dir, platform, plugins_dir)
{
     require('../plugman').emit('log', 'Processing configuration changes for plugins.');
     config_changes.process(plugins_dir, project_dir, platform);
 
+    // for windows phone plaform we need to add all www resources to the .csproj file
+    // first we need to remove them all to prevent duplicates
+    var wp_csproj;
+    if(platform == 'wp7' || platform == 'wp8') {
+        wp_csproj = (platform == wp7? wp7.parseWP7ProjectFile(project_dir) : wp8.parseWP8ProjectFile(project_dir));
+        var item_groups = wp_csproj.xml.findall('ItemGroup');
+        for (var i = 0, l = item_groups.length; i < l; i++) {
+            var group = item_groups[i];
+            var files = group.findall('Content');
+            for (var j = 0, k = files.length; j < k; j++) {
+                var file = files[j];
+                if (file.attrib.Include.substr(0,11) == "www\\plugins" || file.attrib.Include
== "www\\cordova_plugins.js") {
+                    // remove file reference
+                    group.remove(0, file);
+                    // remove ItemGroup if empty
+                    var new_group = group.findall('Content');
+                    if(new_group.length < 1) {
+                        wp_csproj.xml.getroot().remove(0, group);
+                    }
+                }
+            }
+        }
+    }
+
     platform_json = config_changes.get_platform_json(plugins_dir, platform);
     // This array holds all the metadata for each module and ends up in cordova_plugins.json
     var plugins = Object.keys(platform_json.installed_plugins).concat(Object.keys(platform_json.dependent_plugins));
@@ -109,6 +135,9 @@ module.exports = function handlePrepare(project_dir, platform, plugins_dir)
{
                 var scriptContent = fs.readFileSync(path.join(pluginDir, module.attrib.src),
'utf-8');
                 scriptContent = 'cordova.define("' + moduleName + '", function(require, exports,
module) {' + scriptContent + '});\n';
                 fs.writeFileSync(path.join(platformPluginsDir, plugin_id, module.attrib.src),
scriptContent, 'utf-8');
+                if(platform == 'wp7' || platform == 'wp8') {
+                    wp_csproj.addSourceFile(path.join('www', 'plugins', plugin_id, module.attrib.src));
+                }
     
                 // Prepare the object for cordova_plugins.json.
                 var obj = {
@@ -144,4 +173,8 @@ module.exports = function handlePrepare(project_dir, platform, plugins_dir)
{
     final_contents += 'module.exports = ' + JSON.stringify(moduleObjects,null,'    ') + '\n});';
     require('../plugman').emit('log', 'Writing out cordova_plugins.js...');
     fs.writeFileSync(path.join(wwwDir, 'cordova_plugins.js'), final_contents, 'utf-8');
+    if(platform == 'wp7' || platform == 'wp8') {
+        wp_csproj.addSourceFile (path.join('www', 'cordova_plugins.js'));
+        wp_csproj.write();
+    }
 };

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/24e452a5/src/util/csproj.js
----------------------------------------------------------------------
diff --git a/src/util/csproj.js b/src/util/csproj.js
index 572bbbc..475a5d6 100644
--- a/src/util/csproj.js
+++ b/src/util/csproj.js
@@ -53,11 +53,16 @@ csproj.prototype = {
             item.append(compile);
         }
         // otherwise add it normally
-        else {
+        else if (relative_path.indexOf('.cs', relative_path.length - 3) > -1) {
             var compile = new et.Element('Compile');
             compile.attrib.Include = relative_path;
             item.append(compile);
         }
+        else {
+            var compile = new et.Element('Content');
+            compile.attrib.Include = relative_path;
+            item.append(compile);
+        }
         this.xml.getroot().append(item);
     },
     removeSourceFile:function(relative_path) {


Mime
View raw message