Skip to content

Commit

Permalink
CB-6699 Include files from www folder via single element (use ** glob…
Browse files Browse the repository at this point in the history
… pattern)
  • Loading branch information
Vladimir Kotikov committed Aug 15, 2014
1 parent 1cf8104 commit ede4a86
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 99 deletions.
40 changes: 1 addition & 39 deletions cordova-lib/src/cordova/metadata/windows_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ var fs = require('fs'),
ConfigParser = require('../../configparser/ConfigParser'),
CordovaError = require('../../CordovaError'),
xml = require('../../util/xml-helpers'),
hooker = require('../hooker'),
jsproj = require('../../util/windows/jsproj');
hooker = require('../hooker');

module.exports = function windows_parser(project) {
try {
Expand Down Expand Up @@ -229,42 +228,6 @@ module.exports.prototype = {
shell.cp('-rf', path.join(platform_www, '*'), this.www_dir());
},

// Returns an array of all the files in the given directory with relative paths
// - name : the name of the top level directory (i.e all files will start with this in their path)
// - dir : the directory whos contents will be listed under 'name' directory
folder_contents:function(name, dir) {
var results = [];
var folder_dir = fs.readdirSync(dir);
for(var item in folder_dir) {
var stat = fs.statSync(path.join(dir, folder_dir[item]));
// Add all subfolder item paths if it's not a .svn dir.
if( stat.isDirectory() && (folder_dir[item] !== '.svn') ) {
var sub_dir = this.folder_contents(path.join(name, folder_dir[item]), path.join(dir, folder_dir[item]));
for(var sub_item in sub_dir) {
results.push(sub_dir[sub_item]);
}
} else if(stat.isFile()) {
results.push(path.join(name, folder_dir[item]));
}
// else { it is a FIFO, or a Socket, Symbolic Link or something ... }
}
return results;
},

// updates the jsproj file to explicitly list all www content.
update_jsproj:function() {
var projFile = new jsproj(this.projFilePath);
// remove any previous references to the www files
projFile.removeSourceFile(/^(\$\(MSBuildThisFileDirectory\))?www\\/i);

// now add all www references back in from the root www folder
var www_files = this.folder_contents('www', this.www_dir());
projFile.addSourceFile(www_files);

// save file
projFile.write();
},

// calls the nessesary functions to update the windows8 project
update_project:function(cfg) {
// console.log("Updating windows8 project...");
Expand All @@ -282,7 +245,6 @@ module.exports.prototype = {
return hooks.fire('pre_package', { wwwPath:this.www_dir(), platforms: ['windows8'] })
.then(function() {
// overrides (merges) are handled in update_www()
that.update_jsproj();
that.add_bom();
util.deleteSvnFolders(that.www_dir());
});
Expand Down
41 changes: 1 addition & 40 deletions cordova-lib/src/cordova/metadata/wp8_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ var fs = require('fs'),
ConfigParser = require('../../configparser/ConfigParser'),
CordovaError = require('../../CordovaError'),
xml = require('../../util/xml-helpers'),
hooker = require('../hooker'),
csproj = require('../../util/windows/csproj');
hooker = require('../hooker');

module.exports = function wp8_parser(project) {
try {
Expand Down Expand Up @@ -197,43 +196,6 @@ module.exports.prototype = {
shell.cp('-rf', path.join(platform_www, '*'), this.www_dir());
},

// updates the csproj file to explicitly list all www content.
update_csproj:function() {
var projFile = new csproj(this.csproj_path);

// remove any previous references to the www files
projFile.removeSourceFile(new RegExp('www\\\\*', 'i'));

// now add all www references back in from the root www folder
var www_files = this.folder_contents('www', this.www_dir());
projFile.addSourceFile(www_files);
// save file
projFile.write();
},
// Returns an array of all the files in the given directory with relative paths
// - name : the name of the top level directory (i.e all files will start with this in their path)
// - dir : the directory whos contents will be listed under 'name' directory
folder_contents:function(name, dir) {
var results = [];
var folder_dir = fs.readdirSync(dir);
for(var item in folder_dir) {
var stat = fs.statSync(path.join(dir, folder_dir[item]));

if(stat.isDirectory()) {
var sub_dir = this.folder_contents(path.join(name, folder_dir[item]), path.join(dir, folder_dir[item]));
//Add all subfolder item paths
for(var sub_item in sub_dir) {
results.push(sub_dir[sub_item]);
}
}
else if(stat.isFile()) {
results.push(path.join(name, folder_dir[item]));
}
// else { it is a FIFO, or a Socket or something ... }
}
return results;
},

// calls the nessesary functions to update the wp8 project
// Returns a promise.
update_project:function(cfg) {
Expand All @@ -250,7 +212,6 @@ module.exports.prototype = {
var hooks = new hooker(projectRoot);
return hooks.fire('pre_package', { wwwPath:this.www_dir(), platforms: ['wp8'] })
.then(function() {
that.update_csproj();
util.deleteSvnFolders(that.www_dir());
});
}
Expand Down
20 changes: 0 additions & 20 deletions cordova-lib/src/plugman/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ var platform_modules = require('./platforms'),
path = require('path'),
config_changes = require('./util/config-changes'),
xml_helpers = require('../util/xml-helpers'),
wp8 = require('./platforms/wp8'),
windows = require('./platforms/windows'),
common = require('./platforms/common'),
fs = require('fs'),
shell = require('shelljs'),
Expand Down Expand Up @@ -73,16 +71,6 @@ module.exports = function handlePrepare(project_dir, platform, plugins_dir, www_
events.emit('verbose', 'Processing configuration changes for plugins.');
config_changes.process(plugins_dir, project_dir, platform);

// for windows phone and windows8 platforms we need to add all www resources to the .csproj(.jsproj) file
// first we need to remove them all to prevent duplicates
var projFile;
if (platform == 'wp8' || platform == 'windows8' || platform == 'windows') {
projFile = (platform == 'wp8') ? wp8.parseProjectFile(project_dir) :
windows.parseProjectFile(project_dir);
// remove reference to cordova_plugins.js and all files inside plugins folder
projFile.removeSourceFile(/^(\$\(MSBuildThisFileDirectory\))?www\\(cordova_plugins.js|plugins\\)/i);
}

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));
Expand Down Expand Up @@ -155,9 +143,6 @@ module.exports = function handlePrepare(project_dir, platform, plugins_dir, www_
}
scriptContent = 'cordova.define("' + moduleName + '", function(require, exports, module) { ' + scriptContent + '\n});\n';
fs.writeFileSync(path.join(platformPluginsDir, plugin_id, fsPath), scriptContent, 'utf-8');
if(platform == 'wp8' || platform == 'windows8') {
projFile.addSourceFile(path.join('www', 'plugins', plugin_id, fsPath));
}

// Prepare the object for cordova_plugins.json.
var obj = {
Expand Down Expand Up @@ -198,9 +183,4 @@ module.exports = function handlePrepare(project_dir, platform, plugins_dir, www_

events.emit('verbose', 'Writing out cordova_plugins.js...');
fs.writeFileSync(path.join(wwwDir, 'cordova_plugins.js'), final_contents, 'utf-8');

if(platform == 'wp8' || platform == 'windows8' || platform == 'windows') {
projFile.addSourceFile(path.join('www', 'cordova_plugins.js'));
projFile.write();
}
};

0 comments on commit ede4a86

Please sign in to comment.