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 2012/11/28 19:16:24 UTC
[26/50] git commit: Removed dependency on git (closes #55 #53 and
#13). Using request + unzip libs to handle downloading the cordova libs.
Removed dependency on git (closes #55 #53 and #13). Using request + unzip libs to handle downloading the cordova libs.
Project: http://git-wip-us.apache.org/repos/asf/cordova-cli/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-cli/commit/40c06dd6
Tree: http://git-wip-us.apache.org/repos/asf/cordova-cli/tree/40c06dd6
Diff: http://git-wip-us.apache.org/repos/asf/cordova-cli/diff/40c06dd6
Branch: refs/heads/master
Commit: 40c06dd68a2c55d84a4368d7ca3f42fb4ac0693b
Parents: e805772
Author: Fil Maj <ma...@gmail.com>
Authored: Wed Oct 24 16:36:20 2012 -0700
Committer: Fil Maj <ma...@gmail.com>
Committed: Wed Oct 24 16:36:20 2012 -0700
----------------------------------------------------------------------
README.md | 25 ++++------
package.json | 4 +-
spec/metadata/ios_parser.spec.js | 2 +-
spec/platform.spec.js | 28 +++++------
src/metadata/ios_parser.js | 2 +-
src/platform.js | 82 +++++++++++++++++----------------
src/util.js | 69 ++++++++++++++++------------
test_bootstrap.js | 9 ++-
8 files changed, 114 insertions(+), 107 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/40c06dd6/README.md
----------------------------------------------------------------------
diff --git a/README.md b/README.md
index 43a1b07..8bc440d 100644
--- a/README.md
+++ b/README.md
@@ -5,7 +5,6 @@
# Requirements
* [nodejs](http://nodejs.org/)
-* [git](https://help.github.com/articles/set-up-git)
* SDKs for every platform you wish to support
- [BlackBerry WebWorks SDK](http://developer.blackberry.com)
- [iOS SDK](http://developer.apple.com)
@@ -15,8 +14,10 @@
cordova-client has been tested on Mas OS X and Linux.
-In it's prototype stages, cordova-client will only work on Cordova
-v2.1.0.
+If you are using cordova-client for building iOS applications, you will need to run the latest Mac OS with the latest XCode (4.5+) and XCode Command Line Tools.
+
+In it's prototype stages, cordova-client only works with Cordova
+v2.2.0rc1.
# Install
@@ -96,19 +97,11 @@ If you are using cordova-client as a module within a larger node application, yo
## Creating a new cordova project
This example shows how to create a project from scratch named KewlApp with iOS and Android platform support, and includes a plugin named Kewlio. The project will live in ~/MyProjects/KewlApp
-```
-cordova create ~/KewlApp KewlApp
-
-cd ~/KewlApp
-
-cordova platform add ios
-
-cordova platform add android
-
-cordova plugin add http://example.org/Kewlio-1.2.3.tar.gz
-
-cordova build
-```
+ cordova create ~/KewlApp KewlApp
+ cd ~/KewlApp
+ cordova platform add ios android
+ cordova plugin add http://example.org/Kewlio-1.2.3.tar.gz
+ cordova build
The directory structure of KewlApp now looks like this:
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/40c06dd6/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index 09c0bb5..ec0249d 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "cordova",
- "version": "0.1.6",
+ "version": "0.1.7",
"preferGlobal": "true",
"description": "Cordova client tool",
"main": "cordova",
@@ -28,6 +28,8 @@
"express":"3.0",
"shelljs":"0.0.7",
"ncallbacks":"1.0.0",
+ "adm-zip":"0.1.8",
+ "request":"2.11.4",
"prompt":"0.2.7"
},
"devDependencies": {
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/40c06dd6/spec/metadata/ios_parser.spec.js
----------------------------------------------------------------------
diff --git a/spec/metadata/ios_parser.spec.js b/spec/metadata/ios_parser.spec.js
index 266c06d..2914604 100644
--- a/spec/metadata/ios_parser.spec.js
+++ b/spec/metadata/ios_parser.spec.js
@@ -119,7 +119,7 @@ describe('ios project parser', function() {
runs(function() {
parser = new ios_parser(ios_platform);
parser.update_www();
- expect(fs.readFileSync(path.join(ios_platform, 'www', 'cordova.js'),'utf-8')).toBe(fs.readFileSync(path.join(__dirname, '..', '..', 'lib', 'ios', 'CordovaLib', 'javascript', 'cordova.ios.js'), 'utf-8'));
+ expect(fs.readFileSync(path.join(ios_platform, 'www', 'cordova.js'),'utf-8')).toBe(fs.readFileSync(path.join(__dirname, '..', '..', 'lib', 'ios', 'bin', 'templates', 'project', 'www', 'cordova-2.2.0rc1.js'), 'utf-8'));
});
});
});
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/40c06dd6/spec/platform.spec.js
----------------------------------------------------------------------
diff --git a/spec/platform.spec.js b/spec/platform.spec.js
index 3dfd197..e6f9425 100644
--- a/spec/platform.spec.js
+++ b/spec/platform.spec.js
@@ -1,6 +1,7 @@
var cordova = require('../cordova'),
path = require('path'),
shell = require('shelljs'),
+ request = require('request'),
fs = require('fs'),
et = require('elementtree'),
config_parser = require('../src/config_parser'),
@@ -106,42 +107,39 @@ describe('platform command', function() {
});
afterEach(function() {
libs.forEach(function(p) {
- var s = path.join(lib, p + '-bkup');
+ var s = path.join(lib, p + '-bkup', '*');
var d = path.join(lib, p);
+ shell.mkdir(d);
shell.mv(s, d);
+ shell.rm('-rf', path.join(lib, p + '-bkup'));
});
});
- it('should clone down the android library and checkout appropriate tag', function() {
- var s = spyOn(shell, 'exec').andReturn({code:0});
+ it('should download the android library', function() {
+ var s = spyOn(request, 'get');
try {
cordova.platform('add', 'android', function() {});
} catch(e) {}
expect(s).toHaveBeenCalled();
- expect(s.calls[0].args[0].match(/^git clone.*cordova-android/)).not.toBeNull();
- expect(s.calls[1].args[0].match(/git checkout 47daaaf/)).not.toBeNull();
+ expect(s.calls[0].args[0]).toMatch(/cordova-android\/zipball/);
});
- it('should clone down the ios library and checkout appropriate tag', function() {
- var s = spyOn(shell, 'exec').andReturn({code:0});
-
+ it('should download the ios library', function() {
+ var s = spyOn(request, 'get');
try {
cordova.platform('add', 'ios', function() {});
} catch(e) {}
expect(s).toHaveBeenCalled();
- expect(s.calls[0].args[0].match(/^git clone.*cordova-ios/)).not.toBeNull();
- expect(s.calls[1].args[0].match(/git checkout 2.1.0/)).not.toBeNull();
+ expect(s.calls[0].args[0]).toMatch(/cordova-ios\/zipball/);
});
- it('should clone down the blackberry library and checkout appropriate tag', function() {
- var s = spyOn(shell, 'exec').andReturn({code:0});
-
+ it('should download the blackberry library', function() {
+ var s = spyOn(request, 'get');
try {
cordova.platform('add', 'blackberry', function() {});
} catch(e) {}
expect(s).toHaveBeenCalled();
- expect(s.calls[0].args[0].match(/^git clone.*cordova-blackberry/)).not.toBeNull();
- expect(s.calls[1].args[0].match(/git checkout 2.1.0/)).not.toBeNull();
+ expect(s.calls[0].args[0]).toMatch(/cordova-blackberry-webworks\/zipball/);
});
it('should add a basic android project');
it('should add a basic ios project');
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/40c06dd6/src/metadata/ios_parser.js
----------------------------------------------------------------------
diff --git a/src/metadata/ios_parser.js b/src/metadata/ios_parser.js
index a2a877d..7581185 100644
--- a/src/metadata/ios_parser.js
+++ b/src/metadata/ios_parser.js
@@ -48,7 +48,7 @@ module.exports.prototype = {
var projectRoot = util.isCordova(process.cwd());
var www = path.join(projectRoot, 'www');
shell.cp('-rf', www, this.path);
- var jsPath = path.join(__dirname, '..', '..', 'lib', 'ios', 'CordovaLib', 'javascript', 'cordova.ios.js');
+ var jsPath = path.join(__dirname, '..', '..', 'lib', 'ios', 'bin', 'templates', 'project', 'www', 'cordova-2.2.0rc1.js');
fs.writeFileSync(path.join(this.path, 'www', 'cordova.js'), fs.readFileSync(jsPath, 'utf-8'), 'utf-8');
},
update_project:function(cfg, callback) {
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/40c06dd6/src/platform.js
----------------------------------------------------------------------
diff --git a/src/platform.js b/src/platform.js
index 291fd3f..3a9e4c6 100644
--- a/src/platform.js
+++ b/src/platform.js
@@ -43,51 +43,53 @@ module.exports = function platform(command, targets, callback) {
hooks.fire('before_platform_add');
var output = path.join(projectRoot, 'platforms', target);
- // If the Cordova library for this platform is missing, get it.
- if (!cordova_util.havePlatformLib(target)) {
- cordova_util.getPlatformLib(target);
- }
+ var shell_to_cordova = function() {
+ // Create a platform app using the ./bin/create scripts that exist in each repo.
+ // TODO: eventually refactor to allow multiple versions to be created.
+ // Check if output directory already exists.
+ if (fs.existsSync(output)) {
+ throw new Error('Platform "' + target + '" already exists' );
+ }
- // Create a platform app using the ./bin/create scripts that exist in each repo.
- // TODO: eventually refactor to allow multiple versions to be created.
- // Check if output directory already exists.
- if (fs.existsSync(output)) {
- throw new Error('Platform "' + target + '" already exists' );
- }
+ // Run platform's create script
+ var bin = path.join(__dirname, '..', 'lib', cordova_util.underlyingLib(target), 'bin', 'create');
+ var pkg = cfg.packageName().replace(/[^\w.]/g,'_');
+ var name = cfg.name().replace(/\W/g,'_');
+ var command = util.format('"%s" "%s" "%s" "%s"', bin, output, (cordova_util.underlyingLib(target)=='blackberry'?name:pkg), name);
- // Run platform's create script
- var bin = path.join(__dirname, '..', 'lib', cordova_util.underlyingLib(target), 'bin', 'create');
- var pkg = cfg.packageName().replace(/[^\w.]/g,'_');
- var name = cfg.name().replace(/\W/g,'_');
- var command = util.format('"%s" "%s" "%s" "%s"', bin, output, (cordova_util.underlyingLib(target)=='blackberry'?name:pkg), name);
+ var create = shell.exec(command, {silent:true});
+ if (create.code > 0) {
+ throw new Error('An error occured during creation of ' + target + ' sub-project. ' + create.output);
+ }
- var create = shell.exec(command, {silent:true});
- if (create.code > 0) {
- throw new Error('An error occured during creation of ' + target + ' sub-project. ' + create.output);
- }
-
- switch(cordova_util.underlyingLib(target)) {
- case 'android':
- var android = new android_parser(output);
- android.update_project(cfg);
- hooks.fire('after_platform_add');
- end();
- break;
- case 'ios':
- var ios = new ios_parser(output);
- ios.update_project(cfg, function() {
- hooks.fire('after_platform_add');
- end();
- });
- break;
- case 'blackberry':
- var bb = new blackberry_parser(output);
- bb.update_project(cfg, function() {
+ switch(cordova_util.underlyingLib(target)) {
+ case 'android':
+ var android = new android_parser(output);
+ android.update_project(cfg);
hooks.fire('after_platform_add');
end();
- });
- break;
- }
+ break;
+ case 'ios':
+ var ios = new ios_parser(output);
+ ios.update_project(cfg, function() {
+ hooks.fire('after_platform_add');
+ end();
+ });
+ break;
+ case 'blackberry':
+ var bb = new blackberry_parser(output);
+ bb.update_project(cfg, function() {
+ hooks.fire('after_platform_add');
+ end();
+ });
+ break;
+ }
+ };
+
+ // If the Cordova library for this platform is missing, get it.
+ if (!cordova_util.havePlatformLib(target)) {
+ cordova_util.getPlatformLib(target, shell_to_cordova);
+ } else shell_to_cordova();
});
break;
case 'rm':
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/40c06dd6/src/util.js
----------------------------------------------------------------------
diff --git a/src/util.js b/src/util.js
index 587a47e..342a373 100644
--- a/src/util.js
+++ b/src/util.js
@@ -1,15 +1,16 @@
var fs = require('fs'),
path = require('path'),
util = require('util'),
+ request = require('request'),
+ admzip = require('adm-zip'),
shell = require('shelljs');
var repos = {
- ios:'https://git-wip-us.apache.org/repos/asf/incubator-cordova-ios.git',
- android:'https://git-wip-us.apache.org/repos/asf/incubator-cordova-android.git',
- blackberry:'https://git-wip-us.apache.org/repos/asf/incubator-cordova-blackberry-webworks.git'
+ ios:'https://github.com/apache/incubator-cordova-ios/',
+ android:'https://github.com/apache/incubator-cordova-android/',
+ blackberry:'https://github.com/apache/incubator-cordova-blackberry-webworks/'
};
-
module.exports = {
// Runs up the directory chain looking for a .cordova directory.
// IF it is found we are in a Cordova project.
@@ -29,7 +30,7 @@ module.exports = {
},
// Determines whether the library has a copy of the specified
// Cordova implementation
- havePlatformLib: function havePlatformLib(platform) {
+ havePlatformLib: function havePlatformLib(platform, callback) {
var dir = path.join(__dirname, '..', 'lib', module.exports.underlyingLib(platform));
return fs.existsSync(dir);
},
@@ -38,41 +39,49 @@ module.exports = {
* @param target string platform to get (enum of 'ios' or 'android' for now)
* @throws Javascript Error on failure
*/
- getPlatformLib: function getPlatformLib(target) {
+ getPlatformLib: function getPlatformLib(target, callback) {
// verify platform is supported
target = module.exports.underlyingLib(target);
if (!repos[target]) {
throw new Error('platform "' + target + '" not found.');
}
- // verify git command line is available
- if (!shell.which('git')) {
- throw new Error('"git" command not found.');
- }
-
- // specify which project tag to check out. minimum tag is 2.1.0rc1
- var cordova_lib_tag = '2.1.0';
- if (target == 'android') {
- // TODO: android hack. 2.1.0 tag messed up the create script
- cordova_lib_tag = '47daaaf';
- }
+ // specify which project tag to check out. minimum tag is 2.2.0rc1
+ var cordova_lib_tag = '2.2.0rc1';
- // Shell out to git.
var outPath = path.join(__dirname, '..', 'lib', target);
- var cmd = util.format('git clone %s "%s"', repos[target], outPath);
+ shell.mkdir('-p', outPath);
- console.log('Cloning ' + repos[target] + ', this may take a while...');
- var clone = shell.exec(cmd, {silent:true});
- if (clone.code > 0) {
- throw ('An error occured during git-clone of ' + repos[target] + '. ' + clone.output);
- }
+ var tempPath = path.join(__dirname, '..', 'temp');
+ shell.mkdir('-p', tempPath);
- // Check out the right version.
- cmd = util.format('cd "%s" && git checkout %s', outPath, cordova_lib_tag);
- var checkout = shell.exec(cmd, {silent:true});
- if (checkout.code > 0) {
- throw ('An error occured during git-checkout of ' + outPath + ' to tag ' + cordova_lib_tag + '. ' + checkout.output);
- }
+ var tempFile = path.join(tempPath, target + '-' + cordova_lib_tag + '.zip');
+
+ console.log('Downloading ' + target + ' library, this may take a while...');
+ request.get(repos[target] + 'zipball/' + cordova_lib_tag, function(err) {
+ if (err) throw ('Error during download of ' + target + 'library.');
+ var zip = new admzip(tempFile);
+ var extractPoint = path.join(tempPath, target);
+ zip.extractAllTo(extractPoint);
+ var tempDir = path.join(extractPoint, fs.readdirSync(extractPoint)[0]);
+ shell.mv('-f', path.join(tempDir, '*'), outPath);
+
+ // chmod the create file
+ var create = path.join(outPath, 'bin', 'create');
+ shell.exec('chmod +x "' + create + '"', {silent:true});
+
+ if (target == 'ios') {
+ shell.exec('chmod +x "' + path.join(outPath, 'bin', 'replaces') + '"', {silent:true});
+ shell.exec('chmod +x "' + path.join(outPath, 'bin', 'update_cordova_subproject') + '"', {silent:true});
+ }
+
+ // Clean up
+ shell.rm('-rf', tempFile);
+ shell.rm('-rf', extractPoint);
+
+ // Callback
+ if (callback) callback();
+ }).pipe(fs.createWriteStream(tempFile));
},
underlyingLib:function underlyingLib(name) {
var pos = name.indexOf('-');
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/40c06dd6/test_bootstrap.js
----------------------------------------------------------------------
diff --git a/test_bootstrap.js b/test_bootstrap.js
index 4ed34a0..1d149ff 100644
--- a/test_bootstrap.js
+++ b/test_bootstrap.js
@@ -6,13 +6,16 @@
var fs = require('fs'),
path = require('path'),
util = require('./src/util'),
+ ncallbacks=require('ncallbacks'),
platforms = require('./platforms');
+var end = ncallbacks(platforms.length, function() {
+ process.exit(0);
+});
+
// If a platform library dependency does not exist, will clone it down.
platforms.forEach(function(p) {
if (!util.havePlatformLib(p)) {
- util.getPlatformLib(p);
+ util.getPlatformLib(p, end);
}
});
-process.exit(0);
-