Updated Branches: refs/heads/master f658f7014 -> 266c74f16
Starting point, breakout functions Project: http://git-wip-us.apache.org/repos/asf/cordova-plugman/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugman/commit/138877af Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugman/tree/138877af Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugman/diff/138877af Branch: refs/heads/master Commit: 138877af00431091908c76fc10b5b58285b66e5b Parents: f658f70 Author: purplecabbage <[email protected]> Authored: Wed Jul 24 12:49:39 2013 -0700 Committer: purplecabbage <[email protected]> Committed: Mon Jul 29 16:23:33 2013 -0700 ---------------------------------------------------------------------- src/platforms/windows8.js | 58 ++++++++++++++++++++++++++++++++++++++++++ src/util/w8jsproj.js | 54 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/138877af/src/platforms/windows8.js ---------------------------------------------------------------------- diff --git a/src/platforms/windows8.js b/src/platforms/windows8.js new file mode 100644 index 0000000..7fc3c45 --- /dev/null +++ b/src/platforms/windows8.js @@ -0,0 +1,58 @@ +/* + * + * Copyright 2013 Jesse MacFadyen + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * +*/ + +var common = require('./common'), + path = require('path'), + glob = require('glob'), + csproj = require('../util/w8jsproj'); + xml_helpers = require('../util/xml-helpers'); + + +module.exports = { + www_dir:function(project_dir) { + return path.join(project_dir, 'www'); + }, + package_name:function(project_dir) { + return xml_helpers.parseElementtreeSync(path.join(project_dir, 'Properties', 'WMAppManifest.xml')).find('App').attrib.ProductID; + }, + parseProjectFile:function(project_dir) { + var project_files = glob.sync('*.jsproj', { + cwd:project_dir + }); + if (project_files.length === 0) { + throw new Error('does not appear to be a Windows Store JS project (no .jsproj file)'); + } + return new jsproj(path.join(project_dir, project_files[0])); + }, + "source-file":{ + install:function(source_el, plugin_dir, project_dir, plugin_id, project_file) { + var targetDir = source_el.attrib['target-dir'] || ''; + var dest = path.join('Plugins', plugin_id, targetDir, path.basename(source_el.attrib['src'])); + common.copyFile(plugin_dir, source_el.attrib['src'], project_dir, dest); + // add reference to this file to csproj. + project_file.addSourceFile(dest); + }, + uninstall:function(source_el, project_dir, plugin_id, project_file) { + var dest = path.join('Plugins', plugin_id, source_el.attrib['target-dir'] ? source_el.attrib['target-dir'] : '', path.basename(source_el.attrib['src'])); + common.removeFile(project_dir, dest); + // remove reference to this file from csproj. + project_file.removeSourceFile(dest); + } + } +}; http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/138877af/src/util/w8jsproj.js ---------------------------------------------------------------------- diff --git a/src/util/w8jsproj.js b/src/util/w8jsproj.js new file mode 100644 index 0000000..608999b --- /dev/null +++ b/src/util/w8jsproj.js @@ -0,0 +1,54 @@ +/* + Helper for dealing with Windows Store JS app .jsproj files +*/ + + +var xml_helpers = require('./xml-helpers'), + et = require('elementtree'), + fs = require('fs'); + +function jsproj(location) { + this.location = location; + this.xml = xml_helpers.parseElementtreeSync(location); + return this; +} + +jsproj.prototype = { + write:function() { + fs.writeFileSync(this.location, this.xml.write({indent:4}), 'utf-8'); + }, + addSourceFile:function(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); + this.xml.getroot().append(item); + }, + removeSourceFile:function(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]; + var files = group.findall('Content'); + for (var j = 0, k = files.length; j < k; j++) { + var file = files[j]; + if (file.attrib.Include == relative_path) { + // remove file reference + group.remove(0, file); + // remove ItemGroup if empty + var new_group = group.findall('Content'); + if(new_group.length < 1) { + this.xml.getroot().remove(0, group); + } + return true; + } + } + } + return false; + } +}; + +module.exports = csproj;
