Permalink
Browse files

added ability to add+remove ref to .winmd files

  • Loading branch information...
purplecabbage committed Feb 15, 2014
1 parent f0a339f commit 0fe9cf223a538ea27e947a016e39d1ac0a5887b5
Showing with 103 additions and 2 deletions.
  1. +30 −0 src/platforms/windows8.js
  2. +73 −2 src/util/w8jsproj.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);
}
}
};
@@ -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;
}

0 comments on commit 0fe9cf2

Please sign in to comment.