You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by fi...@apache.org on 2013/06/14 22:24:38 UTC
[2/4] git commit: [CB-3812] Platform parsers nwo support custom
directory locations. Added helper "has_custom_path" to config module.
[CB-3812] Platform parsers nwo support custom directory locations. Added helper "has_custom_path" to config module.
Project: http://git-wip-us.apache.org/repos/asf/cordova-cli/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-cli/commit/9758d9fe
Tree: http://git-wip-us.apache.org/repos/asf/cordova-cli/tree/9758d9fe
Diff: http://git-wip-us.apache.org/repos/asf/cordova-cli/diff/9758d9fe
Branch: refs/heads/master2
Commit: 9758d9fe1c3630c345f5aac6385501b26c3ee034
Parents: d2392da
Author: Fil Maj <ma...@gmail.com>
Authored: Fri Jun 14 11:27:29 2013 -0700
Committer: Fil Maj <ma...@gmail.com>
Committed: Fri Jun 14 11:27:29 2013 -0700
----------------------------------------------------------------------
spec/platform.spec.js | 18 +++++++++---------
src/config.js | 10 ++++++++++
src/metadata/android_parser.js | 21 +++++++++++++++++----
src/metadata/blackberry_parser.js | 16 ++++++++++------
src/metadata/ios_parser.js | 10 +++++++---
src/metadata/wp7_parser.js | 16 +++++++++++-----
src/metadata/wp8_parser.js | 20 +++++++++++++-------
src/platform.js | 6 +++---
8 files changed, 80 insertions(+), 37 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/9758d9fe/spec/platform.spec.js
----------------------------------------------------------------------
diff --git a/spec/platform.spec.js b/spec/platform.spec.js
index 3ea285a..3205811 100644
--- a/spec/platform.spec.js
+++ b/spec/platform.spec.js
@@ -30,10 +30,10 @@ var cordova = require('../cordova'),
var cwd = process.cwd();
var supported_platforms = Object.keys(platforms).filter(function(p) { return p != 'www'; });
+var project_dir = '/some/path';
describe('platform command', function() {
var is_cordova, list_platforms, fire, config_parser, find_plugins, config_read, load_custom, load_cordova, rm, mkdir, existsSync, supports, pkg, name, exec, prep_spy, plugman_install;
- var project_dir = '/some/path';
beforeEach(function() {
is_cordova = spyOn(util, 'isCordova').andReturn(project_dir);
fire = spyOn(hooker.prototype, 'fire').andCallFake(function(e, opts, cb) {
@@ -58,7 +58,7 @@ describe('platform command', function() {
rm = spyOn(shell, 'rm');
mkdir = spyOn(shell, 'mkdir');
existsSync = spyOn(fs, 'existsSync').andReturn(false);
- supports = spyOn(platform, 'supports').andCallFake(function(name, cb) {
+ supports = spyOn(platform, 'supports').andCallFake(function(project_root, name, cb) {
cb();
});
exec = spyOn(shell, 'exec').andCallFake(function(cmd, opts, cb) {
@@ -190,24 +190,24 @@ describe('platform.supports(name, callback)', function() {
var supports = {};
beforeEach(function() {
supported_platforms.forEach(function(p) {
- supports[p] = spyOn(platforms[p].parser, 'check_requirements').andCallFake(function(cb) { cb(); });
+ supports[p] = spyOn(platforms[p].parser, 'check_requirements').andCallFake(function(project, cb) { cb(); });
});
});
it('should require a platform name', function() {
expect(function() {
- cordova.platform.supports(undefined, function(e){});
+ cordova.platform.supports(project_dir, undefined, function(e){});
}).toThrow();
});
it('should require a callback function', function() {
expect(function() {
- cordova.platform.supports('android', undefined);
+ cordova.platform.supports(project_dir, 'android', undefined);
}).toThrow();
});
describe('when platform is unknown', function() {
it('should trigger callback with false', function(done) {
- cordova.platform.supports('windows-3.1', function(e) {
+ cordova.platform.supports(project_dir, 'windows-3.1', function(e) {
expect(e).toEqual(jasmine.any(Error));
done();
});
@@ -216,7 +216,7 @@ describe('platform.supports(name, callback)', function() {
describe('when platform is supported', function() {
it('should trigger callback without error', function(done) {
- cordova.platform.supports('android', function(e) {
+ cordova.platform.supports(project_dir, 'android', function(e) {
expect(e).toBeNull();
done();
});
@@ -226,9 +226,9 @@ describe('platform.supports(name, callback)', function() {
describe('when platform is unsupported', function() {
it('should trigger callback with error', function(done) {
supported_platforms.forEach(function(p) {
- supports[p].andCallFake(function(cb) { cb(new Error('no sdk')); });
+ supports[p].andCallFake(function(project, cb) { cb(new Error('no sdk')); });
});
- cordova.platform.supports('android', function(e) {
+ cordova.platform.supports(project_dir, 'android', function(e) {
expect(e).toEqual(jasmine.any(Error));
done();
});
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/9758d9fe/src/config.js
----------------------------------------------------------------------
diff --git a/src/config.js b/src/config.js
index fb0a59b..ca41ee6 100644
--- a/src/config.js
+++ b/src/config.js
@@ -19,6 +19,7 @@
var path = require('path'),
fs = require('fs'),
+ url = require('url'),
shell = require('shelljs'),
events = require('./events'),
util = require('./util');
@@ -52,3 +53,12 @@ module.exports.write = function set_config(project_root, json) {
fs.writeFileSync(config_json, JSON.stringify(json), 'utf-8');
return json;
};
+
+module.exports.has_custom_path = function(project_root, platform) {
+ var json = module.exports.read(project_root);
+ if (json.lib && json.lib[platform]) {
+ var uri = url.parse(json.lib[platform].uri);
+ if (!(uri.protocol)) return uri.path;
+ }
+ return false;
+};
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/9758d9fe/src/metadata/android_parser.js
----------------------------------------------------------------------
diff --git a/src/metadata/android_parser.js b/src/metadata/android_parser.js
index d71473e..f03ee8f 100644
--- a/src/metadata/android_parser.js
+++ b/src/metadata/android_parser.js
@@ -22,6 +22,7 @@ var fs = require('fs'),
util = require('../util'),
events = require('../events'),
shell = require('shelljs'),
+ project_config= require('../config'),
config_parser = require('../config_parser');
var default_prefs = {
@@ -39,7 +40,7 @@ module.exports = function android_parser(project) {
this.android_config = path.join(this.path, 'res', 'xml', 'config.xml');
};
-module.exports.check_requirements = function(callback) {
+module.exports.check_requirements = function(project_root, callback) {
events.emit('log', 'Checking Android requirements...');
var command = 'android list target';
events.emit('log', 'Running "' + command + '" (output to follow)');
@@ -51,7 +52,14 @@ module.exports.check_requirements = function(callback) {
if (output.indexOf('android-17') == -1) {
callback('Please install Android target 17 (the Android 4.2 SDK). Make sure you have the latest Android tools installed as well. Run `android` from your command-line to install/update any missing SDKs or tools.');
} else {
- var cmd = 'android update project -p ' + path.join(util.libDirectory, 'android', 'cordova', util.cordovaTag, 'framework') + ' -t android-17';
+ var custom_path = project_config.has_custom_path(project_root, 'android');
+ var framework_path;
+ if (custom_path) {
+ framework_path = path.resolve(path.join(custom_path, 'framework'));
+ } else {
+ framework_path = path.join(util.libDirectory, 'android', 'cordova', util.cordovaTag, 'framework');
+ }
+ var cmd = 'android update project -p "' + framework_path + '" -t android-17';
events.emit('log', 'Running "' + cmd + '" (output to follow)...');
shell.exec(cmd, {silent:true, async:true}, function(code, output) {
events.emit('log', output);
@@ -160,9 +168,14 @@ module.exports.prototype = {
shell.cp('-rf', www, platformWww);
// write out android lib's cordova.js
- var jsPath = path.join(util.libDirectory, 'android', 'cordova', util.cordovaTag, 'framework', 'assets', 'www', 'cordova.js');
+ var custom_path = project_config.has_custom_path(projectRoot, 'android');
+ var jsPath;
+ if (custom_path) {
+ jsPath = path.resolve(path.join(custom_path, 'framework', 'assets', 'www', 'cordova.js'));
+ } else {
+ jsPath = path.join(util.libDirectory, 'android', 'cordova', util.cordovaTag, 'framework', 'assets', 'www', 'cordova.js');
+ }
fs.writeFileSync(path.join(this.www_dir(), 'cordova.js'), fs.readFileSync(jsPath, 'utf-8'), 'utf-8');
-
},
// update the overrides folder into the www folder
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/9758d9fe/src/metadata/blackberry_parser.js
----------------------------------------------------------------------
diff --git a/src/metadata/blackberry_parser.js b/src/metadata/blackberry_parser.js
index 6cb39a0..b348d9e 100644
--- a/src/metadata/blackberry_parser.js
+++ b/src/metadata/blackberry_parser.js
@@ -23,7 +23,8 @@ var fs = require('fs'),
shell = require('shelljs'),
util = require('../util'),
events = require('../events'),
- config_parser = require('../config_parser');
+ config_parser = require('../config_parser'),
+ config = require('../config');
module.exports = function blackberry_parser(project) {
if (!fs.existsSync(path.join(project, 'project.json')) || !fs.existsSync(path.join(project, 'www'))) {
@@ -34,7 +35,7 @@ module.exports = function blackberry_parser(project) {
this.xml = new config_parser(this.config_path);
};
-module.exports.check_requirements = function(callback) {
+module.exports.check_requirements = function(project_root, callback) {
if (process.env && process.env.QNX_HOST) {
callback(false);
} else {
@@ -121,19 +122,22 @@ module.exports.prototype = {
// copy over project www assets
shell.cp('-rf', www, this.path);
+ var custom_path = config.has_custom_path(projectRoot, 'blackberry');
+ var lib_path = path.join(util.libDirectory, 'blackberry', 'cordova', util.cordovaTag);
+ if (custom_path) lib_path = custom_path;
// add cordova.js
- shell.cp('-f', path.join(util.libDirectory, 'blackberry', 'cordova', util.cordovaTag, 'javascript', 'cordova.blackberry10.js'), path.join(this.www_dir(), 'cordova.js'));
+ shell.cp('-f', path.join(lib_path, 'javascript', 'cordova.blackberry10.js'), path.join(this.www_dir(), 'cordova.js'));
// add webworks ext directories
- shell.cp('-rf', path.join(util.libDirectory, 'blackberry', 'cordova', util.cordovaTag, 'framework', 'ext*'), this.www_dir());
+ shell.cp('-rf', path.join(lib_path, 'framework', 'ext*'), this.www_dir());
// add config.xml
// @TODO should use project www/config.xml but it must use BBWP elements
- shell.cp('-f', path.join(util.libDirectory, 'blackberry', 'cordova', util.cordovaTag, 'bin', 'templates', 'project', 'www', 'config.xml'), this.www_dir());
+ shell.cp('-f', path.join(lib_path, 'bin', 'templates', 'project', 'www', 'config.xml'), this.www_dir());
// add res/
// @TODO remove this when config.xml is generalized
- shell.cp('-rf', path.join(util.libDirectory, 'blackberry', 'cordova', util.cordovaTag, 'bin', 'templates', 'project', 'www', 'res'), this.www_dir());
+ shell.cp('-rf', path.join(lib_path, 'bin', 'templates', 'project', 'www', 'res'), this.www_dir());
},
// update the overrides folder into the www folder
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/9758d9fe/src/metadata/ios_parser.js
----------------------------------------------------------------------
diff --git a/src/metadata/ios_parser.js b/src/metadata/ios_parser.js
index 99e5a5e..bcf7718 100644
--- a/src/metadata/ios_parser.js
+++ b/src/metadata/ios_parser.js
@@ -25,7 +25,8 @@ var fs = require('fs'),
plist = require('plist'),
semver = require('semver'),
et = require('elementtree'),
- config_parser = require('../config_parser');
+ config_parser = require('../config_parser'),
+ config = require('../config');
var MIN_XCODE_VERSION = '4.5.x';
@@ -60,7 +61,7 @@ module.exports = function ios_parser(project) {
this.config = new config_parser(this.config_path);
};
-module.exports.check_requirements = function(callback) {
+module.exports.check_requirements = function(project_root, callback) {
events.emit('log', 'Checking iOS requirements...');
// Check xcode + version.
var command = 'xcodebuild -version';
@@ -177,7 +178,10 @@ module.exports.prototype = {
shell.cp('-rf', www, this.path);
// write out proper cordova.js
- shell.cp('-f', path.join(util.libDirectory, 'ios', 'cordova', util.cordovaTag, 'CordovaLib', 'cordova.js'), path.join(project_www, 'cordova.js'));
+ var custom_path = config.has_custom_path(projectRoot, 'ios');
+ var lib_path = path.join(util.libDirectory, 'ios', 'cordova', util.cordovaTag);
+ if (custom_path) lib_path = custom_path;
+ shell.cp('-f', path.join(lib_path, 'CordovaLib', 'cordova.js'), path.join(project_www, 'cordova.js'));
},
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/9758d9fe/src/metadata/wp7_parser.js
----------------------------------------------------------------------
diff --git a/src/metadata/wp7_parser.js b/src/metadata/wp7_parser.js
index d5aeb51..f786025 100644
--- a/src/metadata/wp7_parser.js
+++ b/src/metadata/wp7_parser.js
@@ -23,7 +23,8 @@ var fs = require('fs'),
events = require('../events'),
shell = require('shelljs'),
events = require('../events'),
- config_parser = require('../config_parser');
+ config_parser = require('../config_parser'),
+ config = require('../config');
module.exports = function wp7_parser(project) {
try {
@@ -39,10 +40,12 @@ module.exports = function wp7_parser(project) {
this.manifest_path = path.join(this.wp7_proj_dir, 'Properties', 'WMAppManifest.xml');
};
-module.exports.check_requirements = function(callback) {
- // TODO: requires the libraries to be available.
+module.exports.check_requirements = function(project_root, callback) {
events.emit('log', 'Checking WP7 requirements...');
- var command = '"' + path.join(util.libDirectory, 'wp7', 'cordova', util.cordovaTag, 'bin', 'check_reqs') + '"';
+ var lib_path = path.join(util.libDirectory, 'wp7', 'cordova', util.cordovaTag);
+ var custom_path = config.has_custom_path(project_root, 'wp7');
+ if (custom_path) lib_path = custom_path;
+ var command = '"' + path.join(lib_path, 'bin', 'check_reqs') + '"';
events.emit('log', 'Running "' + command + '" (output to follow)');
shell.exec(command, {silent:true, async:true}, function(code, output) {
events.emit('log', output);
@@ -145,7 +148,10 @@ module.exports.prototype = {
shell.cp('-rf', project_www, this.wp7_proj_dir);
// copy over wp7 lib's cordova.js
- var cordovajs_path = path.join(util.libDirectory, 'wp7', 'cordova', util.cordovaTag, 'templates', 'standalone', 'www', 'cordova.js');
+ var lib_path = path.join(util.libDirectory, 'wp7', 'cordova', util.cordovaTag);
+ var custom_path = config.has_custom_path(project_root, 'wp7');
+ if (custom_path) lib_path = custom_path;
+ var cordovajs_path = path.join(lib_path, 'templates', 'standalone', 'www', 'cordova.js');
fs.writeFileSync(path.join(this.www_dir(), 'cordova.js'), fs.readFileSync(cordovajs_path, 'utf-8'), 'utf-8');
this.update_csproj();
},
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/9758d9fe/src/metadata/wp8_parser.js
----------------------------------------------------------------------
diff --git a/src/metadata/wp8_parser.js b/src/metadata/wp8_parser.js
index 14d5fb4..ee7bcd0 100644
--- a/src/metadata/wp8_parser.js
+++ b/src/metadata/wp8_parser.js
@@ -39,10 +39,13 @@ module.exports = function wp8_parser(project) {
this.manifest_path = path.join(this.wp8_proj_dir, 'Properties', 'WMAppManifest.xml');
};
-module.exports.check_requirements = function(callback) {
+module.exports.check_requirements = function(project_root, callback) {
events.emit('log', 'Checking WP8 requirements...');
- // TODO: requires the libraries to be available.
- var command = '"' + path.join(util.libDirectory, 'wp8', 'cordova', util.cordovaTag, 'bin', 'check_reqs') + '"';
+ var custom_path = config.has_custom_path(project_root, 'wp8');
+ var lib_path = path.join(util.libDirectory, 'wp8', 'cordova', util.cordovaTag);
+ if (custom_path) lib_path = custom_path;
+
+ var command = '"' + path.join(lib_path, 'bin', 'check_reqs') + '"';
events.emit('log', 'Running "' + command + '" (output to follow)');
shell.exec(command, {silent:true, async:true}, function(code, output) {
events.emit('log', output);
@@ -101,8 +104,7 @@ module.exports.prototype = {
var cleanedPage = raw.replace(/^\uFEFF/i, '');
var csproj = new et.ElementTree(et.XML(cleanedPage));
prev_name = csproj.find('.//RootNamespace').text;
- if(prev_name != pkg)
- {
+ if (prev_name != pkg) {
//console.log("Updating package name from " + prev_name + " to " + pkg);
//CordovaAppProj.csproj
csproj.find('.//RootNamespace').text = pkg;
@@ -138,14 +140,18 @@ module.exports.prototype = {
},
// copies the app www folder into the wp8 project's www folder and updates the csproj file.
update_www:function() {
- var project_www = util.projectWww(path.join(this.wp8_proj_dir, '..', '..'));
+ var projectRoot = util.isCordova(this.wp8_proj_dir);
+ var project_www = util.projectWww(projectRoot);
// remove stock platform assets
shell.rm('-rf', this.www_dir());
// copy over all app www assets
shell.cp('-rf', project_www, this.wp8_proj_dir);
+ var custom_path = config.has_custom_path(projectRoot, 'wp8');
+ var lib_path = path.join(util.libDirectory, 'wp8', 'cordova', util.cordovaTag);
+ if (custom_path) lib_path = custom_path;
// copy over wp8 lib's cordova.js
- var cordovajs_path = path.join(util.libDirectory, 'wp8', 'cordova', util.cordovaTag, 'templates', 'standalone', 'www', 'cordova.js');
+ var cordovajs_path = path.join(lib_path, 'templates', 'standalone', 'www', 'cordova.js');
fs.writeFileSync(path.join(this.www_dir(), 'cordova.js'), fs.readFileSync(cordovajs_path, 'utf-8'), 'utf-8');
this.update_csproj();
},
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/9758d9fe/src/platform.js
----------------------------------------------------------------------
diff --git a/src/platform.js b/src/platform.js
index 62bf05e..1149f23 100644
--- a/src/platform.js
+++ b/src/platform.js
@@ -168,7 +168,7 @@ module.exports = function platform(command, targets, callback) {
* - {Error} `e` null when a platform is supported otherwise describes error.
*/
-module.exports.supports = function(name, callback) {
+module.exports.supports = function(project_root, name, callback) {
// required parameters
if (!name) throw new Error('requires a platform name parameter');
if (!callback) throw new Error('requires a callback parameter');
@@ -188,7 +188,7 @@ module.exports.supports = function(name, callback) {
}
// check for platform support
- platformParser.check_requirements(function(e) {
+ platformParser.check_requirements(project_root, function(e) {
// typecast String to Error
e = (e instanceof String) ? new Error(e) : e;
// typecast false Boolean to null
@@ -217,7 +217,7 @@ function call_into_create(target, projectRoot, cfg, id, version, callback, end)
} else {
// Make sure we have minimum requirements to work with specified platform
events.emit('log', 'Checking if platform "' + target + '" passes minimum requirements...');
- module.exports.supports(target, function(err) {
+ module.exports.supports(projectRoot, target, function(err) {
if (err) {
if (callback) callback(err);
else throw err;