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/12 23:49:21 UTC
[3/3] git commit: fixing platform add with new lazy load
fixing platform add with new lazy load
Project: http://git-wip-us.apache.org/repos/asf/cordova-cli/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-cli/commit/0c2ffe44
Tree: http://git-wip-us.apache.org/repos/asf/cordova-cli/tree/0c2ffe44
Diff: http://git-wip-us.apache.org/repos/asf/cordova-cli/diff/0c2ffe44
Branch: refs/heads/lazy
Commit: 0c2ffe4412d18db9aa06436c5c349020513b6be6
Parents: 1569274
Author: Fil Maj <ma...@gmail.com>
Authored: Wed Jun 12 14:49:13 2013 -0700
Committer: Fil Maj <ma...@gmail.com>
Committed: Wed Jun 12 14:49:13 2013 -0700
----------------------------------------------------------------------
platforms.js | 2 +-
src/metadata/android_parser.js | 4 +-
src/metadata/blackberry_parser.js | 8 +-
src/metadata/ios_parser.js | 2 +-
src/metadata/wp7_parser.js | 4 +-
src/metadata/wp8_parser.js | 4 +-
src/platform.js | 169 ++++++++++++++++++---------------
7 files changed, 107 insertions(+), 86 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/0c2ffe44/platforms.js
----------------------------------------------------------------------
diff --git a/platforms.js b/platforms.js
index 7d894b4..0096fcb 100644
--- a/platforms.js
+++ b/platforms.js
@@ -24,7 +24,7 @@ module.exports = {
},
'android' : {
parser : require('./src/metadata/android_parser'),
- url : 'https://git-wip-us.apache.org/repos/asf?p=cordova-ios.git'
+ url : 'https://git-wip-us.apache.org/repos/asf?p=cordova-android.git'
},
'wp7' : {
parser : require('./src/metadata/wp7_parser'),
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/0c2ffe44/src/metadata/android_parser.js
----------------------------------------------------------------------
diff --git a/src/metadata/android_parser.js b/src/metadata/android_parser.js
index dce21e2..c109b1a 100644
--- a/src/metadata/android_parser.js
+++ b/src/metadata/android_parser.js
@@ -51,7 +51,7 @@ 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, 'cordova-android-' + util.cordovaTag, 'framework') + ' -t android-17';
+ var cmd = 'android update project -p ' + path.join(util.libDirectory, 'android', 'cordova', util.cordovaTag, 'framework') + ' -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,7 +160,7 @@ module.exports.prototype = {
shell.cp('-rf', www, platformWww);
// write out android lib's cordova.js
- var jsPath = path.join(util.libDirectory, 'cordova-android-' + util.cordovaTag, 'framework', 'assets', 'www', 'cordova.js');
+ var 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');
},
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/0c2ffe44/src/metadata/blackberry_parser.js
----------------------------------------------------------------------
diff --git a/src/metadata/blackberry_parser.js b/src/metadata/blackberry_parser.js
index 853ae03..a9b03c5 100644
--- a/src/metadata/blackberry_parser.js
+++ b/src/metadata/blackberry_parser.js
@@ -120,18 +120,18 @@ module.exports.prototype = {
shell.cp('-rf', www, this.path);
// add cordova.js
- shell.cp('-f', path.join(util.libDirectory, 'cordova-blackberry-' + util.cordovaTag, 'javascript', 'cordova.blackberry10.js'), path.join(this.www_dir(), 'cordova.js'));
+ shell.cp('-f', path.join(util.libDirectory, 'blackberry', 'cordova', util.cordovaTag, 'javascript', 'cordova.blackberry10.js'), path.join(this.www_dir(), 'cordova.js'));
// add webworks ext directories
- shell.cp('-rf', path.join(util.libDirectory, 'cordova-blackberry-' + util.cordovaTag, 'framework', 'ext*'), this.www_dir());
+ shell.cp('-rf', path.join(util.libDirectory, 'blackberry', 'cordova', util.cordovaTag, '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, 'cordova-blackberry-' + util.cordovaTag, 'bin', 'templates', 'project', 'www', 'config.xml'), this.www_dir());
+ shell.cp('-f', path.join(util.libDirectory, 'blackberry', 'cordova', util.cordovaTag, '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, 'cordova-blackberry-' + util.cordovaTag, 'bin', 'templates', 'project', 'www', 'res'), this.www_dir());
+ shell.cp('-rf', path.join(util.libDirectory, 'blackberry', 'cordova', util.cordovaTag, '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/0c2ffe44/src/metadata/ios_parser.js
----------------------------------------------------------------------
diff --git a/src/metadata/ios_parser.js b/src/metadata/ios_parser.js
index 7570930..99e5a5e 100644
--- a/src/metadata/ios_parser.js
+++ b/src/metadata/ios_parser.js
@@ -177,7 +177,7 @@ module.exports.prototype = {
shell.cp('-rf', www, this.path);
// write out proper cordova.js
- shell.cp('-f', path.join(util.libDirectory, 'cordova-ios-' + util.cordovaTag, 'CordovaLib', 'cordova.js'), path.join(project_www, 'cordova.js'));
+ shell.cp('-f', path.join(util.libDirectory, 'ios', 'cordova', util.cordovaTag, 'CordovaLib', 'cordova.js'), path.join(project_www, 'cordova.js'));
},
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/0c2ffe44/src/metadata/wp7_parser.js
----------------------------------------------------------------------
diff --git a/src/metadata/wp7_parser.js b/src/metadata/wp7_parser.js
index 0ec0983..420231b 100644
--- a/src/metadata/wp7_parser.js
+++ b/src/metadata/wp7_parser.js
@@ -42,7 +42,7 @@ module.exports = function wp7_parser(project) {
module.exports.check_requirements = function(callback) {
// TODO: requires the libraries to be available.
events.emit('log', 'Checking WP7 requirements...');
- var command = '"' + path.join(util.libDirectory, 'cordova-wp7-' + util.cordovaTag, 'bin', 'check_reqs') + '"';
+ var command = '"' + path.join(util.libDirectory, 'wp7', 'cordova', util.cordovaTag, '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 +145,7 @@ 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, 'cordova-wp7-' + util.cordovaTag, 'templates', 'standalone', 'www', 'cordova.js');
+ var cordovajs_path = path.join(util.libDirectory, 'wp7', 'cordova', util.cordovaTag, 'templates', 'standalone', 'www', 'cordova.js');
fs.writeFileSync(path.join(this.www_dir(), 'cordova.js'), fs.readFileSync(cordovajs_path, 'utf-8'), 'utf-8');
},
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/0c2ffe44/src/metadata/wp8_parser.js
----------------------------------------------------------------------
diff --git a/src/metadata/wp8_parser.js b/src/metadata/wp8_parser.js
index 080b3ac..1a3f723 100644
--- a/src/metadata/wp8_parser.js
+++ b/src/metadata/wp8_parser.js
@@ -42,7 +42,7 @@ module.exports = function wp8_parser(project) {
module.exports.check_requirements = function(callback) {
events.emit('log', 'Checking WP8 requirements...');
// TODO: requires the libraries to be available.
- var command = '"' + path.join(util.libDirectory, 'cordova-wp8-' + util.cordovaTag, 'bin', 'check_reqs') + '"';
+ var command = '"' + path.join(util.libDirectory, 'wp8', 'cordova', util.cordovaTag, '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 +145,7 @@ module.exports.prototype = {
shell.cp('-rf', project_www, this.wp8_proj_dir);
// copy over wp8 lib's cordova.js
- var cordovajs_path = path.join(util.libDirectory, 'cordova-wp8-' + util.cordovaTag, 'templates', 'standalone', 'www', 'cordova.js');
+ var cordovajs_path = path.join(util.libDirectory, 'wp8', 'cordova', util.cordovaTag, 'templates', 'standalone', 'www', 'cordova.js');
fs.writeFileSync(path.join(this.www_dir(), 'cordova.js'), fs.readFileSync(cordovajs_path, 'utf-8'), 'utf-8');
},
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/0c2ffe44/src/platform.js
----------------------------------------------------------------------
diff --git a/src/platform.js b/src/platform.js
index f0537de..58be9af 100644
--- a/src/platform.js
+++ b/src/platform.js
@@ -17,6 +17,7 @@
under the License.
*/
var config_parser = require('./config_parser'),
+ config = require('./config'),
cordova_util = require('./util'),
util = require('util'),
fs = require('fs'),
@@ -41,13 +42,17 @@ module.exports = function platform(command, targets, callback) {
var hooks = new hooker(projectRoot);
- var createOverrides = function(target) {
- shell.mkdir('-p', path.join(cordova_util.appDir(projectRoot), 'merges', target));
- };
if (arguments.length === 0) command = 'ls';
if (targets) {
if (!(targets instanceof Array)) targets = [targets];
+ targets.forEach(function(t) {
+ if (!(t in platforms)) {
+ var err = new Error('Platform "' + t + '" not recognized as core cordova platform.');
+ if (callback) return callback(err);
+ else throw err;
+ }
+ });
}
var xml = cordova_util.projectConfig(projectRoot);
@@ -86,77 +91,36 @@ module.exports = function platform(command, targets, callback) {
}
});
});
- var add_callback = n(targets.length, function() {
- hooks.fire('before_platform_add', opts, function(err) {
- if (err) {
- if (callback) callback(err);
- else throw err;
- } else {
- targets.forEach(function(target) {
- var output = path.join(projectRoot, 'platforms', target);
-
- // Check if output directory already exists.
- if (fs.existsSync(output)) {
- var err = new Error('Platform "' + target + '" already exists at "' + output + '"');
- if (callback) callback(err);
- else throw err;
- } 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) {
- if (err) {
- if (callback) callback(err);
- else throw err;
- } else {
- // Create a platform app using the ./bin/create scripts that exist in each repo.
- // Run platform's create script
- var bin = path.join(cordova_util.libDirectory, 'cordova-' + target + '-' + cordova_util.cordovaTag, 'bin', 'create');
- var args = (target=='ios') ? '--arc' : '';
- var pkg = cfg.packageName().replace(/[^\w.]/g,'_');
- var name = cfg.name().replace(/\W/g,'_');
- var command = util.format('"%s" %s "%s" "%s" "%s"', bin, args, output, pkg, name);
- events.emit('log', 'Running bin/create for platform "' + target + '" with command: "' + command + '" (output to follow)');
-
- shell.exec(command, {silent:true,async:true}, function(code, create_output) {
- events.emit('log', create_output);
- if (code > 0) {
- var err = new Error('An error occured during creation of ' + target + ' sub-project. ' + create_output);
- if (callback) callback(err);
- else throw err;
- } else {
- var parser = new platforms[target].parser(output);
- events.emit('log', 'Updating ' + target + ' project from config.xml...');
- parser.update_project(cfg, function() {
- createOverrides(target);
- end(); //platform add is done by now.
- // Install all currently installed plugins into this new platform.
- var pluginsDir = path.join(projectRoot, 'plugins');
- var plugins = fs.readdirSync(pluginsDir);
- plugins && plugins.forEach(function(plugin) {
- if (fs.statSync(path.join(projectRoot, 'plugins', plugin)).isDirectory()) {
- events.emit('log', 'Installing plugin "' + plugin + '" following successful platform add of ' + target);
- plugman.install(target, output, path.basename(plugin), pluginsDir, { www_dir: parser.staging_dir() });
- }
- });
- });
- }
- });
- }
- });
- }
- });
- }
- });
- });
- targets.forEach(function(t) {
- lazy_load(t, function(err) {
- if (err) {
- if (callback) callback(err);
- else throw err;
- } else {
- add_callback();
- }
- });
+ var config_json = config.read(projectRoot);
+ hooks.fire('before_platform_add', opts, function(err) {
+ if (err) {
+ if (callback) callback(err);
+ else throw err;
+ } else {
+ targets.forEach(function(t) {
+ if (config_json.lib && config_json.lib[t]) {
+ events.emit('log', 'Using custom cordova platform library for "' + t + '".');
+ lazy_load.custom(config_json.lib[t].uri, config_json.lib[t].id, t, config_json.lib[t].version, function(err) {
+ if (err) {
+ if (callback) callback(err);
+ else throw err;
+ } else {
+ call_into_create(t, projectRoot, true /* is_custom */, cfg, config_json.lib[t].id, config_json.lib[t].version, callback, end);
+ }
+ });
+ } else {
+ events.emit('log', 'Using stock cordova platform library for "' + t + '".');
+ lazy_load.cordova(t, function(err) {
+ if (err) {
+ if (callback) callback(err);
+ else throw err;
+ } else {
+ call_into_create(t, projectRoot, false /* is_custom */, cfg, 'cordova', cordova_util.cordovaTag, callback, end);
+ }
+ });
+ }
+ });
+ }
});
break;
case 'rm':
@@ -233,3 +197,60 @@ module.exports.supports = function(name, callback) {
for (var p in platforms) {
module.exports[p] = platforms[p];
}
+function createOverrides(projectRoot, target) {
+ shell.mkdir('-p', path.join(cordova_util.appDir(projectRoot), 'merges', target));
+};
+
+function call_into_create(target, projectRoot, is_custom, cfg, id, version, callback, end) {
+ var output = path.join(projectRoot, 'platforms', target);
+
+ // Check if output directory already exists.
+ if (fs.existsSync(output)) {
+ var err = new Error('Platform "' + target + '" already exists at "' + output + '"');
+ if (callback) callback(err);
+ else throw err;
+ } 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) {
+ if (err) {
+ if (callback) callback(err);
+ else throw err;
+ } else {
+ // Create a platform app using the ./bin/create scripts that exist in each repo.
+ // Run platform's create script
+ var bin = path.join(cordova_util.libDirectory, target, id, version, 'bin', 'create');
+ var args = (target=='ios') ? '--arc' : '';
+ var pkg = cfg.packageName().replace(/[^\w.]/g,'_');
+ var name = cfg.name().replace(/\W/g,'_');
+ var command = util.format('"%s" %s "%s" "%s" "%s"', bin, args, output, pkg, name);
+ events.emit('log', 'Running bin/create for platform "' + target + '" with command: "' + command + '" (output to follow)');
+
+ shell.exec(command, {silent:true,async:true}, function(code, create_output) {
+ events.emit('log', create_output);
+ if (code > 0) {
+ var err = new Error('An error occured during creation of ' + target + ' sub-project. ' + create_output);
+ if (callback) callback(err);
+ else throw err;
+ } else {
+ var parser = new platforms[target].parser(output);
+ events.emit('log', 'Updating ' + target + ' project from config.xml...');
+ parser.update_project(cfg, function() {
+ createOverrides(projectRoot, target);
+ end(); //platform add is done by now.
+ // Install all currently installed plugins into this new platform.
+ var pluginsDir = path.join(projectRoot, 'plugins');
+ var plugins = fs.readdirSync(pluginsDir);
+ plugins && plugins.forEach(function(plugin) {
+ if (fs.statSync(path.join(projectRoot, 'plugins', plugin)).isDirectory()) {
+ events.emit('log', 'Installing plugin "' + plugin + '" following successful platform add of ' + target);
+ plugman.install(target, output, path.basename(plugin), pluginsDir, { www_dir: parser.staging_dir() });
+ }
+ });
+ });
+ }
+ });
+ }
+ });
+ }
+}