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/07/03 19:19:24 UTC

[1/4] git commit: updated xcode dependency to 0.6.1 which supports compiler flags. added compiler flag support to ios plugin installation for elements.

Updated Branches:
  refs/heads/master bb21db9a9 -> 823f9a82f


updated xcode dependency to 0.6.1 which supports compiler flags. added compiler flag support to ios plugin installation for <source-file> elements.


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugman/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugman/commit/7c9e7f80
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugman/tree/7c9e7f80
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugman/diff/7c9e7f80

Branch: refs/heads/master
Commit: 7c9e7f80628c30c96535b2dc6b918f22e8b5a245
Parents: bb21db9
Author: Fil Maj <ma...@gmail.com>
Authored: Wed Jul 3 09:07:44 2013 -0700
Committer: Fil Maj <ma...@gmail.com>
Committed: Wed Jul 3 09:07:44 2013 -0700

----------------------------------------------------------------------
 package.json               | 2 +-
 spec/platforms/ios.spec.js | 4 ++--
 src/platforms/ios.js       | 3 ++-
 3 files changed, 5 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/7c9e7f80/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index 4433ae8..eb483f4 100644
--- a/package.json
+++ b/package.json
@@ -20,7 +20,7 @@
     "nopt": "1.0.x",
     "glob": "3.2.x",
     "elementtree": "0.1.x",
-    "xcode": "https://github.com/filmaj/node-xcode/tarball/master",
+    "xcode": "0.6.1",
     "plist": "0.4.x",
     "bplist-parser": "0.0.x",
     "shelljs": "0.1.x",

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/7c9e7f80/spec/platforms/ios.spec.js
----------------------------------------------------------------------
diff --git a/spec/platforms/ios.spec.js b/spec/platforms/ios.spec.js
index 7d69338..79a45a2 100644
--- a/spec/platforms/ios.spec.js
+++ b/spec/platforms/ios.spec.js
@@ -133,13 +133,13 @@ describe('ios project handler', function() {
                 var source = copyArray(valid_source).filter(function(s) { return s.attrib['target-dir'] == undefined});
                 var spy = spyOn(proj_files.xcode, 'addSourceFile');
                 ios['source-file'].install(source[0], dummyplugin, temp, dummy_id, proj_files);
-                expect(spy).toHaveBeenCalledWith(path.join('Plugins', dummy_id, 'DummyPluginCommand.m'));
+                expect(spy).toHaveBeenCalledWith(path.join('Plugins', dummy_id, 'DummyPluginCommand.m'), {});
             });
             it('should call into xcodeproj\'s addSourceFile appropriately when element has a target-dir', function() {
                 var source = copyArray(valid_source).filter(function(s) { return s.attrib['target-dir'] != undefined});
                 var spy = spyOn(proj_files.xcode, 'addSourceFile');
                 ios['source-file'].install(source[0], dummyplugin, temp, dummy_id, proj_files);
-                expect(spy).toHaveBeenCalledWith(path.join('Plugins', dummy_id, 'targetDir', 'TargetDirTest.m'));
+                expect(spy).toHaveBeenCalledWith(path.join('Plugins', dummy_id, 'targetDir', 'TargetDirTest.m'), {});
             });
             it('should cp the file to the right target location when element has no target-dir', function() {
                 var source = copyArray(valid_source).filter(function(s) { return s.attrib['target-dir'] == undefined});

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/7c9e7f80/src/platforms/ios.js
----------------------------------------------------------------------
diff --git a/src/platforms/ios.js b/src/platforms/ios.js
index bc2c704..eea59b3 100644
--- a/src/platforms/ios.js
+++ b/src/platforms/ios.js
@@ -39,11 +39,12 @@ module.exports = {
             var targetDir = path.resolve(project.plugins_dir, plugin_id, getRelativeDir(source_el));
             var destFile = path.resolve(targetDir, path.basename(src));
             var is_framework = source_el.attrib['framework'] && (source_el.attrib['framework'] == 'true' || source_el.attrib['framework'] == true);
+            var has_flags = source_el.attrib['compiler-flags'] && source_el.attrib['compiler-flags'].length ? true : false ;
 
             if (!fs.existsSync(srcFile)) throw new Error('cannot find "' + srcFile + '" ios <source-file>');
             if (fs.existsSync(destFile)) throw new Error('target destination "' + destFile + '" already exists');
             var project_ref = path.join('Plugins', path.relative(project.plugins_dir, destFile));
-            project.xcode.addSourceFile(project_ref);
+            project.xcode.addSourceFile(project_ref, has_flags ? {compilerFlags:source_el.attrib['compiler-flags']} : {});
             if (is_framework) {
                 var weak = source_el.attrib['weak'];
                 var opt = { weak: (weak == undefined || weak == null || weak != 'true' ? false : true ) };


[3/4] git commit: Most console.logs should be removed in favour of events now. Hooked it up properly to cli shim.

Posted by fi...@apache.org.
Most console.logs should be removed in favour of events now. Hooked it up properly to cli shim.


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugman/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugman/commit/ab34d898
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugman/tree/ab34d898
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugman/diff/ab34d898

Branch: refs/heads/master
Commit: ab34d898066052f42402a433097acc3379b884cd
Parents: ce7a21e
Author: Fil Maj <ma...@gmail.com>
Authored: Wed Jul 3 10:12:34 2013 -0700
Committer: Fil Maj <ma...@gmail.com>
Committed: Wed Jul 3 10:13:40 2013 -0700

----------------------------------------------------------------------
 doc/help.txt               |  5 ++++
 main.js                    |  3 ++
 spec/install.spec.js       |  5 ++--
 spec/util/plugins.spec.js  | 38 ++++++++++--------------
 src/install.js             | 15 ++++++----
 src/prepare.js             |  5 ++++
 src/uninstall.js           | 14 ++++-----
 src/util/action-stack.js   | 14 +++++++--
 src/util/config-changes.js |  1 +
 src/util/plugins.js        | 66 ++++++++++++++++++++++-------------------
 10 files changed, 94 insertions(+), 72 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/ab34d898/doc/help.txt
----------------------------------------------------------------------
diff --git a/doc/help.txt b/doc/help.txt
index 3a45a73..412b3ba 100644
--- a/doc/help.txt
+++ b/doc/help.txt
@@ -28,3 +28,8 @@ Optional parameters
 
  - www <directory>: www assets for the plugin will be installed into this directory. Default is to install into the standard www directory for the platform specified
  - plugins_dir <directory>: a copy of the plugin will be stored in this directory. Default is to install into the <project directory>/plugins folder
+
+Optional flags
+--------------
+
+ --debug : Verbose mode

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/ab34d898/main.js
----------------------------------------------------------------------
diff --git a/main.js b/main.js
index 159f97e..262c264 100755
--- a/main.js
+++ b/main.js
@@ -60,9 +60,12 @@ process.on('uncaughtException', function(error){
     process.exit(1);
 });
 
+// Set up appropriate logging based on events
 if (cli_opts.debug) {
     plugman.on('log', console.log);
 }
+plugman.on('warn', console.warn);
+plugman.on('error', console.error);
 
 if (cli_opts.v) {
     console.log(package.name + ' version ' + package.version);

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/ab34d898/spec/install.spec.js
----------------------------------------------------------------------
diff --git a/spec/install.spec.js b/spec/install.spec.js
index 644834a..f51d92a 100644
--- a/spec/install.spec.js
+++ b/spec/install.spec.js
@@ -8,6 +8,7 @@ var install = require('../src/install'),
     path    = require('path'),
     shell   = require('shelljs'),
     semver  = require('semver'),
+    events = require('../src/events'),
     temp    = __dirname,
     dummyplugin = 'DummyPlugin',
     dummy_id = 'com.phonegap.plugins.dummyplugin',
@@ -50,7 +51,7 @@ describe('install', function() {
             expect(add_to_queue).toHaveBeenCalledWith(plugins_dir, 'DummyPlugin', 'android', {}, true);
         });
         it('should notify if plugin is already installed into project', function() {
-            var spy = spyOn(console, 'log');
+            var spy = spyOn(events, 'emit');
             get_json.andReturn({
                 installed_plugins:{
                     'com.phonegap.plugins.dummyplugin':{}
@@ -58,7 +59,7 @@ describe('install', function() {
                 dependent_plugins:{}
             });
             install('android', temp, dummyplugin, plugins_dir, {});
-            expect(spy).toHaveBeenCalledWith('Plugin "'+dummy_id+'" already installed, \'sall good.');
+            expect(spy).toHaveBeenCalledWith('log', 'Plugin "'+dummy_id+'" already installed, \'sall good.');
         });
         it('should check version if plugin has engine tag', function(){
             var spy = spyOn(semver, 'satisfies').andReturn(true);

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/ab34d898/spec/util/plugins.spec.js
----------------------------------------------------------------------
diff --git a/spec/util/plugins.spec.js b/spec/util/plugins.spec.js
index 8f217cf..6653819 100644
--- a/spec/util/plugins.spec.js
+++ b/spec/util/plugins.spec.js
@@ -28,22 +28,24 @@ var http   = require('http'),
 
 describe('plugins utility module', function(){
     describe('clonePluginGitRepo', function(){
-        it('should shell out to git clone with correct arguments', function(){
-            var execSpy = spyOn(shell, 'exec').andReturn({
-                code: 0,
-                output: 'git output'
+        var fake_id = 'VillageDrunkard';
+        var execSpy, cp_spy, xml_spy;
+        beforeEach(function() {
+            execSpy = spyOn(shell, 'exec').andCallFake(function(cmd, opts, cb) {
+                cb(0, 'git output');
             });
-            var fake_id = 'fake.plugin.id';
-            var xml = {
-                getroot: function() {
-                    return { attrib: { id: fake_id } };
+            spyOn(shell, 'which').andReturn(true);
+            cp_spy = spyOn(shell, 'cp');
+            xml_spy = spyOn(xml_helpers, 'parseElementtreeSync').andReturn({
+                getroot:function() {
+                    return {
+                        attrib:{id:fake_id}
+                    };
                 }
-            };
-
-            spyOn(xml_helpers, 'parseElementtreeSync').andReturn(xml);
-            spyOn(shell, 'cp');
+            });
+        });
+        it('should shell out to git clone with correct arguments', function(){
             var plugin_git_url = 'https://github.com/imhotep/ChildBrowser'
-
             var callback = jasmine.createSpy();
 
             plugins.clonePluginGitRepo(plugin_git_url, temp, '.', undefined, callback);
@@ -57,16 +59,6 @@ describe('plugins utility module', function(){
             expect(callback.mostRecentCall.args[1]).toMatch(new RegExp('/' + fake_id + '$'));
         });
         it('should take into account subdirectory argument when copying over final repository into plugins+plugin_id directory', function() {
-            var exec_spy = spyOn(shell, 'exec').andReturn({ code: 0, output: 'git clone output' });
-            var cp_spy = spyOn(shell, 'cp');
-            var fake_id = 'VillageDrunkard';
-            var xml_spy = spyOn(xml_helpers, 'parseElementtreeSync').andReturn({
-                getroot:function() {
-                    return {
-                        attrib:{id:fake_id}
-                    };
-                }
-            });
             var plugin_git_url = 'https://github.com/imhotep/ChildBrowser'
             
             var fake_subdir = 'TheBrainRecoilsInHorror';

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/ab34d898/src/install.js
----------------------------------------------------------------------
diff --git a/src/install.js b/src/install.js
index 179d228..e07b973 100644
--- a/src/install.js
+++ b/src/install.js
@@ -2,6 +2,7 @@ var path = require('path'),
     fs   = require('fs'),
     et   = require('elementtree'),
     n    = require('ncallbacks'),
+    events = require('./events'),
     action_stack = require('./util/action-stack'),
     shell = require('shelljs'),
     semver = require('semver'),
@@ -71,6 +72,7 @@ function runInstall(actions, platform, project_dir, plugin_dir, plugins_dir, opt
       , filtered_variables = {};
     var name         = plugin_et.findall('name').text;
     var plugin_id    = plugin_et.getroot().attrib['id'];
+    events.emit('log', 'Starting installation of "' + plugin_id + '"...');
 
     // check if platform has plugin installed already.
     var platform_config = config_changes.get_platform_json(plugins_dir, platform);
@@ -87,7 +89,7 @@ function runInstall(actions, platform, project_dir, plugin_dir, plugins_dir, opt
         }
     });
     if (is_installed) {
-        console.log('Plugin "' + plugin_id + '" already installed, \'sall good.');
+        events.emit('log', 'Plugin "' + plugin_id + '" already installed, \'sall good.');
         if (callback) callback();
         return;
     }
@@ -121,7 +123,7 @@ function runInstall(actions, platform, project_dir, plugin_dir, plugins_dir, opt
             });
         }
     } else {
-        console.log('Warning: cordova version not detected. installing anyway.');
+        events.emit('log', 'Cordova project version not detected (lacks a ./cordova/version script), continuing.');
     }
 
     // checking preferences, if certain variables are not provided, we should throw.
@@ -146,6 +148,7 @@ function runInstall(actions, platform, project_dir, plugin_dir, plugins_dir, opt
     // Check for dependencies, (co)recurse to install each one
     var dependencies = plugin_et.findall('dependency');
     if (dependencies && dependencies.length) {
+        events.emit('log', 'Dependencies detected, iterating through them...');
         var end = n(dependencies.length, function() {
             handleInstall(actions, plugin_id, plugin_et, platform, project_dir, plugins_dir, plugin_basename, plugin_dir, filtered_variables, options.www_dir, options.is_top_level, callback);
         });
@@ -201,7 +204,7 @@ function runInstall(actions, platform, project_dir, plugin_dir, plugins_dir, opt
 
             var dep_plugin_dir = path.join(plugins_dir, dep_plugin_id);
             if (fs.existsSync(dep_plugin_dir)) {
-                console.log('Dependent plugin ' + dep_plugin_id + ' already fetched, using that version.');
+                events.emit('log', 'Dependent plugin "' + dep_plugin_id + '" already fetched, using that version.');
                 var opts = {
                     cli_variables: filtered_variables,
                     www_dir: options.www_dir,
@@ -209,7 +212,7 @@ function runInstall(actions, platform, project_dir, plugin_dir, plugins_dir, opt
                 };
                 runInstall(actions, platform, project_dir, dep_plugin_dir, plugins_dir, opts, end);
             } else {
-                console.log('Dependent plugin ' + dep_plugin_id + ' not fetched, retrieving then installing.');
+                events.emit('log', 'Dependent plugin "' + dep_plugin_id + '" not fetched, retrieving then installing.');
                 var opts = {
                     cli_variables: filtered_variables,
                     www_dir: options.www_dir,
@@ -232,7 +235,7 @@ function runInstall(actions, platform, project_dir, plugin_dir, plugins_dir, opt
 }
 
 function handleInstall(actions, plugin_id, plugin_et, platform, project_dir, plugins_dir, plugin_basename, plugin_dir, filtered_variables, www_dir, is_top_level, callback) {
-    console.log('Installing plugin ' + plugin_id + '...');
+    events.emit('log', 'Installing plugin ' + plugin_id + '...');
     var handler = platform_modules[platform];
     www_dir = www_dir || handler.www_dir(project_dir);
 
@@ -292,7 +295,7 @@ function handleInstall(actions, plugin_id, plugin_et, platform, project_dir, plu
             // call prepare after a successful install
             require('./../plugman').prepare(project_dir, platform, plugins_dir);
 
-            console.log(plugin_id + ' installed.');
+            events.emit('log', plugin_id + ' installed.');
             if (callback) callback();
         }
     });

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/ab34d898/src/prepare.js
----------------------------------------------------------------------
diff --git a/src/prepare.js b/src/prepare.js
index 969c73e..a608dcc 100644
--- a/src/prepare.js
+++ b/src/prepare.js
@@ -18,6 +18,7 @@
 */
 
 var platform_modules = require('./platforms'),
+    events          = require('./events'),
     path            = require('path'),
     config_changes  = require('./util/config-changes'),
     xml_helpers     = require('./util/xml-helpers'),
@@ -42,6 +43,7 @@ module.exports = function handlePrepare(project_dir, platform, plugins_dir) {
     // - Write this object into www/cordova_plugins.json.
     // - Cordova.js contains code to load them at runtime from that file.
 
+    events.emit('log', 'Preparing ' + platform + ' project, starting with processing of config changes...');
     config_changes.process(plugins_dir, project_dir, platform);
 
     var wwwDir = platform_modules[platform].www_dir(project_dir);
@@ -52,6 +54,7 @@ module.exports = function handlePrepare(project_dir, platform, plugins_dir) {
 
     // This array holds all the metadata for each module and ends up in cordova_plugins.json
     var moduleObjects = [];
+    events.emit('log', 'Iterating over installed plugins...');
 
     plugins && plugins.forEach(function(plugin) {
         var pluginDir = path.join(plugins_dir, plugin);
@@ -121,6 +124,7 @@ module.exports = function handlePrepare(project_dir, platform, plugins_dir) {
         }
     });
 
+    events.emit('log', 'Writing out cordova_plugins.json...');
     // Write out moduleObjects as JSON to cordova_plugins.json
     fs.writeFileSync(path.join(wwwDir, 'cordova_plugins.json'), JSON.stringify(moduleObjects), 'utf-8');
     // Write out moduleObjects as JSON wrapped in a cordova module to cordova_plugins.js
@@ -128,5 +132,6 @@ module.exports = function handlePrepare(project_dir, platform, plugins_dir) {
     var final_contents = "cordova.define('cordova/plugin_list', function(require, exports, module) {\n";
     final_contents += 'module.exports = ' + JSON.stringify(moduleObjects) + '\n';
     final_contents += '});';
+    events.emit('log', 'Writing out cordova_plugins.js...');
     fs.writeFileSync(path.join(wwwDir, 'cordova_plugins.js'), final_contents, 'utf-8');
 };

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/ab34d898/src/uninstall.js
----------------------------------------------------------------------
diff --git a/src/uninstall.js b/src/uninstall.js
index 575012d..5cb807b 100644
--- a/src/uninstall.js
+++ b/src/uninstall.js
@@ -6,6 +6,7 @@ var path = require('path'),
     xml_helpers = require('./util/xml-helpers'),
     action_stack = require('./util/action-stack'),
     n = require('ncallbacks'),
+    events = require('./events'),
     dependencies = require('./util/dependencies'),
     underscore = require('underscore'),
     platform_modules = require('./platforms');
@@ -14,18 +15,16 @@ var path = require('path'),
 module.exports = function uninstallPlugin(platform, project_dir, id, plugins_dir, options, callback) {
     if (!platform_modules[platform]) {
         var err = new Error(platform + " not supported.");
-        if (callback) callback(err);
+        if (callback) return callback(err);
         else throw err;
-        return;
     }
 
     var plugin_dir = path.join(plugins_dir, id);
 
     if (!fs.existsSync(plugin_dir)) {
         var err = new Error('Plugin "' + id + '" not found. Already uninstalled?');
-        if (callback) callback(err);
+        if (callback) return callback(err);
         else throw err;
-        return;
     }
 
     var current_stack = new action_stack();
@@ -53,9 +52,8 @@ function runUninstall(actions, platform, project_dir, plugin_dir, plugins_dir, o
             var ds = graph.getChain(tlp);
             if (options.is_top_level && ds.indexOf(plugin_id) > -1) {
                 var err = new Error('Another top-level plugin (' + tlp + ') relies on plugin ' + plugin_id + ', therefore aborting uninstallation.');
-                if (callback) callback(err);
+                if (callback) return callback(err);
                 else throw err;
-                return;
             }
             diff_arr.push(ds);
         }
@@ -65,6 +63,7 @@ function runUninstall(actions, platform, project_dir, plugin_dir, plugins_dir, o
     diff_arr.unshift(dependents);
     var danglers = underscore.difference.apply(null, diff_arr);
     if (dependents.length && danglers && danglers.length) {
+        events.emit('log', 'Uninstalling ' + danglers.length + ' dangling dependent plugins...');
         var end = n(danglers.length, function() {
             handleUninstall(actions, platform, plugin_id, plugin_et, project_dir, options.www_dir, plugins_dir, plugin_dir, options.is_top_level, callback);
         });
@@ -88,6 +87,7 @@ function handleUninstall(actions, platform, plugin_id, plugin_et, project_dir, w
     var handler = platform_modules[platform];
     var platformTag = plugin_et.find('./platform[@name="'+platform+'"]');
     www_dir = www_dir || handler.www_dir(project_dir);
+    events.emit('log', 'Uninstalling ' + plugin_id + '...');
 
     var assets = plugin_et.findall('./asset');
     if (platformTag) {
@@ -134,7 +134,7 @@ function handleUninstall(actions, platform, plugin_id, plugin_et, project_dir, w
             require('./../plugman').prepare(project_dir, platform, plugins_dir);
             // axe the directory
             shell.rm('-rf', plugin_dir);
-            console.log(plugin_id + ' uninstalled.');
+            events.emit('log', plugin_id + ' uninstalled.');
             if (callback) callback();
         }
     });

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/ab34d898/src/util/action-stack.js
----------------------------------------------------------------------
diff --git a/src/util/action-stack.js b/src/util/action-stack.js
index 4643e8d..19602fb 100644
--- a/src/util/action-stack.js
+++ b/src/util/action-stack.js
@@ -1,6 +1,7 @@
 var ios = require('../platforms/ios'),
     wp7 = require('../platforms/wp7'),
     wp8 = require('../platforms/wp8'),
+    events = require('../events'),
     fs = require('fs');
 
 function ActionStack() {
@@ -25,15 +26,19 @@ ActionStack.prototype = {
         this.stack.push(tx);
     },
     process:function(platform, project_dir, callback) {
+        events.emit('log', 'Beginning processing of action stack for ' + platform + ' project...');
         var project_files;
         // parse platform-specific project files once
         if (platform == 'ios') {
+            events.emit('log', 'Parsing iOS project files...');
             project_files = ios.parseIOSProjectFiles(project_dir);
         }
         if (platform == 'wp7') {
+            events.emit('log', 'Parsing WP7 project files...');
             project_files = wp7.parseWP7ProjectFile(project_dir);
         }
         if (platform == 'wp8') {
+            events.emit('log', 'Parsing WP8 project files...');
             project_files = wp8.parseWP8ProjectFile(project_dir);
         } 
         while(this.stack.length) {
@@ -44,6 +49,7 @@ ActionStack.prototype = {
             try {
                 handler.apply(null, action_params);
             } catch(e) {
+                events.emit('warn', 'Error during processing of action! Attempting to revert...');
                 var incomplete = this.stack.unshift(action);
                 var issue = 'Uh oh!\n';
                 // revert completed tasks
@@ -55,22 +61,24 @@ ActionStack.prototype = {
                     try {
                         revert.apply(null, revert_params);
                     } catch(err) {
+                        events.emit('warn', 'Error during reversion of action! We probably really messed up your project now, sorry! D:');
                         issue += 'A reversion action failed: ' + err.message + '\n';
                     }
                 }
-                console.log(e.stack);
                 e.message = issue + e.message;
-                if (callback) callback(e);
+                if (callback) return callback(e);
                 else throw e;
-                return;
             }
             this.completed.push(action);
         }
+        events.emit('log', 'Action stack processing complete.');
         if (platform == 'ios') {
             // write out xcodeproj file
+            events.emit('log', 'Writing out iOS pbxproj file...');
             fs.writeFileSync(project_files.pbx, project_files.xcode.writeSync());
         }
         if (platform == 'wp7') {
+            events.emit('log', 'Writing out WP7 project files...');
             project_files.write();
         }
         if (callback) callback();

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/ab34d898/src/util/config-changes.js
----------------------------------------------------------------------
diff --git a/src/util/config-changes.js b/src/util/config-changes.js
index 4a4d7ac..c49c705 100644
--- a/src/util/config-changes.js
+++ b/src/util/config-changes.js
@@ -23,6 +23,7 @@ var fs   = require('fs'),
     plist = require('plist'),
     bplist = require('bplist-parser'),
     et   = require('elementtree'),
+    events = require('../events'),
     xml_helpers = require('./../util/xml-helpers'),
     plist_helpers = require('./../util/plist-helpers');
 

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/ab34d898/src/util/plugins.js
----------------------------------------------------------------------
diff --git a/src/util/plugins.js b/src/util/plugins.js
index 07c5d95..706d352 100644
--- a/src/util/plugins.js
+++ b/src/util/plugins.js
@@ -1,4 +1,3 @@
-#!/usr/bin/env node
 /*
  *
  * Copyright 2013 Anis Kadri
@@ -25,6 +24,7 @@ var http = require('http'),
     util = require('util'),
     shell = require('shelljs'),
     xml_helpers = require('./xml-helpers'),
+    events = require('../events'),
     tmp_dir = path.join(os.tmpdir(), 'plugman-tmp');
 
 module.exports = {
@@ -33,7 +33,7 @@ module.exports = {
     clonePluginGitRepo:function(plugin_git_url, plugins_dir, subdir, git_ref, callback) {
         if(!shell.which('git')) {
             var err = new Error('git command line is not installed');
-            if (callback) callback(err);
+            if (callback) return callback(err);
             else throw err;
         }
 
@@ -41,39 +41,43 @@ module.exports = {
 
         shell.cd(path.dirname(tmp_dir));
         var cmd = util.format('git clone "%s" "%s"', plugin_git_url, path.basename(tmp_dir));
-        var result = shell.exec(cmd, {silent: true, async:false});
-        if (result.code > 0) {
-            var err = new Error('failed to get the plugin via git from URL '+ plugin_git_url + ', output: ' + result.output);
-            if (callback) callback(err)
-            else throw err;
-        } else {
-            console.log('Plugin "' + plugin_git_url + '" fetched.');
-            // Check out the specified revision, if provided.
-            if (git_ref) {
-                var cmd = util.format('cd "%s" && git checkout "%s"', tmp_dir, git_ref);
-                var result = shell.exec(cmd, { silent: true, async:false });
-                if (result.code > 0) {
-                    var err = new Error('failed to checkout git ref "' + git_ref + '" for plugin at git url "' + plugin_git_url + '", output: ' + result.output);
-                    if (callback) callback(err);
-                    else throw err;
+        events.emit('log', 'Fetching plugin via git-clone command: ' + cmd);
+        shell.exec(cmd, {silent: true, async:true}, function(code, output) {
+            if (code > 0) {
+                var err = new Error('failed to get the plugin via git from URL '+ plugin_git_url + ', output: ' + output);
+                if (callback) return callback(err)
+                else throw err;
+            } else {
+                events.emit('log', 'Plugin "' + plugin_git_url + '" fetched.');
+                // Check out the specified revision, if provided.
+                if (git_ref) {
+                    var cmd = util.format('cd "%s" && git checkout "%s"', tmp_dir, git_ref);
+                    var result = shell.exec(cmd, { silent: true, async:false });
+                    if (result.code > 0) {
+                        var err = new Error('failed to checkout git ref "' + git_ref + '" for plugin at git url "' + plugin_git_url + '", output: ' + result.output);
+                        if (callback) return callback(err);
+                        else throw err;
+                    }
+                    events.emit('log', 'Plugin "' + plugin_git_url + '" checked out to git ref "' + git_ref + '".');
                 }
-                console.log('Checked out ' + git_ref);
-            }
 
-            // Read the plugin.xml file and extract the plugin's ID.
-            tmp_dir = path.join(tmp_dir, subdir);
-            // TODO: what if plugin.xml does not exist?
-            var xml_file = path.join(tmp_dir, 'plugin.xml');
-            var xml = xml_helpers.parseElementtreeSync(xml_file);
-            var plugin_id = xml.getroot().attrib.id;
+                // Read the plugin.xml file and extract the plugin's ID.
+                tmp_dir = path.join(tmp_dir, subdir);
+                // TODO: what if plugin.xml does not exist?
+                var xml_file = path.join(tmp_dir, 'plugin.xml');
+                var xml = xml_helpers.parseElementtreeSync(xml_file);
+                var plugin_id = xml.getroot().attrib.id;
 
-            // TODO: what if a plugin dependended on different subdirectories of the same plugin? this would fail.
-            // should probably copy over entire plugin git repo contents into plugins_dir and handle subdir seperately during install.
-            var plugin_dir = path.join(plugins_dir, plugin_id);
-            shell.cp('-R', path.join(tmp_dir, '*'), plugin_dir);
+                // TODO: what if a plugin dependended on different subdirectories of the same plugin? this would fail.
+                // should probably copy over entire plugin git repo contents into plugins_dir and handle subdir seperately during install.
+                events.emit('log', 'Copying fetched plugin over "' + plugin_dir + '"...');
+                var plugin_dir = path.join(plugins_dir, plugin_id);
+                shell.cp('-R', path.join(tmp_dir, '*'), plugin_dir);
 
-            if (callback) callback(null, plugin_dir);
-        }
+                events.emit('log', 'Plugin "' + plugin_id + '" fetched.');
+                if (callback) callback(null, plugin_dir);
+            }
+        });
     }
 };
 


[2/4] git commit: part of the way there to refactor output into eventemitter.

Posted by fi...@apache.org.
part of the way there to refactor output into eventemitter.


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugman/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugman/commit/ce7a21ef
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugman/tree/ce7a21ef
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugman/diff/ce7a21ef

Branch: refs/heads/master
Commit: ce7a21efea3c386ad431c6f085b39d1e136184af
Parents: 7c9e7f8
Author: Fil Maj <ma...@gmail.com>
Authored: Tue Jul 2 10:48:35 2013 -0700
Committer: Fil Maj <ma...@gmail.com>
Committed: Wed Jul 3 10:12:40 2013 -0700

----------------------------------------------------------------------
 FUTURE.md      | 42 ------------------------------------------
 main.js        |  6 +++++-
 plugman.js     | 18 ++++++++++++------
 src/events.js  |  3 +++
 src/fetch.js   | 15 ++++++++++++---
 src/help.js    |  2 +-
 src/install.js |  5 ++---
 7 files changed, 35 insertions(+), 56 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/ce7a21ef/FUTURE.md
----------------------------------------------------------------------
diff --git a/FUTURE.md b/FUTURE.md
deleted file mode 100644
index 41c2c62..0000000
--- a/FUTURE.md
+++ /dev/null
@@ -1,42 +0,0 @@
-# The Future of Plugman and CLI
-
-In this branch, Plugman is undergoing major changes to make the split of responsibilities between plugman and cordova-cli clear.
-
-## Responsibilities
-
-* cordova-cli is responsible for handling multiple platforms. That means it has the separate `platforms/{ios,android,etc}` directories, a top-level `www/` and so on.
-* plugman is responsible for everything to do with plugins: fetching them, installing native code, installing JS code, keeping track of which ones are installed, removing them.
-
-## High-level changes
-
-Plugman now holds onto the code of the plugin, instead of cloning it into a temporary folder and throwing it away. By default it uses the `cordova/plugins` directory, but this can be overridden with `--plugins_dir=some/path`. This enables cordova-cli to use its top-level `plugins/` directory.
-
-See the next section for the changes to the commands and arguments.
-
-## Commands
-
-### `--fetch`
-
-Does the actual downloading of the plugin, from Github, the repository or the local disk.
-
-This supports cordova-cli, which will want to `--fetch` once into its top-level `plugins/` directory and then `--install` once for each platform.
-
-### `--install`
-
-Takes the previously fetched plugin files and installs them into a project. Needs a path to the plugin directory, the path to the project, and the platform, similar to now.
-
-Installs the native code and makes the necessary configuration changes.
-
-### `--uninstall`
-
-Removes the native code and undoes the configuration changes and so on.
-
-Care is required here not to remove permissions that are still needed by other plugins. (Read: config changes should be cleared and recreated from the currently installed plugins every time. This applies to permissions, `<plugin>` tags and so on.)
-
-### `--prepare`
-
-Takes over part of cordova-cli's `prepare` command. Copies all plugins' Javascript files (more precisely, those specified in `<js-module>` tags rather than `<asset>` tags) into `www/plugins/com.plugin.id/whatever/path/file.js` and constructs the `cordova_plugins.json` file.
-
-`cordova.js` in this new model will have code that reads this `cordova_plugins.json` file via XHR, loads the JS files for the plugins, and does their clobbers and merges.
-
-This is something of a change from the current cordova-cli method, but necessary because we won't be working with a fresh `cordova.js` file on each run anymore.

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/ce7a21ef/main.js
----------------------------------------------------------------------
diff --git a/main.js b/main.js
index 28a3358..159f97e 100755
--- a/main.js
+++ b/main.js
@@ -60,11 +60,15 @@ process.on('uncaughtException', function(error){
     process.exit(1);
 });
 
+if (cli_opts.debug) {
+    plugman.on('log', console.log);
+}
+
 if (cli_opts.v) {
     console.log(package.name + ' version ' + package.version);
 }
 else if (!cli_opts.platform || !cli_opts.project || !cli_opts.plugin) {
-    plugman.help();
+    console.log(plugman.help());
 }
 else if (cli_opts.uninstall) {
     plugman.uninstall(cli_opts.platform, cli_opts.project, cli_opts.plugin, plugins_dir, { www_dir: cli_opts.www });

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/ce7a21ef/plugman.js
----------------------------------------------------------------------
diff --git a/plugman.js b/plugman.js
index 23128ed..072d9b9 100755
--- a/plugman.js
+++ b/plugman.js
@@ -18,11 +18,17 @@
 */
 
 // copyright (c) 2013 Andrew Lunny, Adobe Systems
+
+var emitter = require('./src/events');
+
 module.exports = {
-    help:     require('./src/help'),
-    install:  require('./src/install'),
-    uninstall:require('./src/uninstall'),
-    fetch:    require('./src/fetch'),
-    prepare:  require('./src/prepare'),
-    config_changes:require('./src/util/config-changes')
+    help:           require('./src/help'),
+    install:        require('./src/install'),
+    uninstall:      require('./src/uninstall'),
+    fetch:          require('./src/fetch'),
+    prepare:        require('./src/prepare'),
+    config_changes: require('./src/util/config-changes'),
+    on:             emitter.addListener,
+    off:            emitter.removeListener,
+    removeAllListeners: emitter.removeAllListeners,
 };

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/ce7a21ef/src/events.js
----------------------------------------------------------------------
diff --git a/src/events.js b/src/events.js
new file mode 100644
index 0000000..1cec85a
--- /dev/null
+++ b/src/events.js
@@ -0,0 +1,3 @@
+var emitter = new (require('events').EventEmitter)();
+
+module.exports = emitter;

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/ce7a21ef/src/fetch.js
----------------------------------------------------------------------
diff --git a/src/fetch.js b/src/fetch.js
index c0ce5f1..f712b0a 100644
--- a/src/fetch.js
+++ b/src/fetch.js
@@ -4,10 +4,12 @@ var shell   = require('shelljs'),
     plugins = require('./util/plugins'),
     xml_helpers = require('./util/xml-helpers'),
     metadata = require('./util/metadata'),
+    events  = require('./events'),
     path    = require('path');
 
 // possible options: link, subdir, git_ref
 module.exports = function fetchPlugin(plugin_dir, plugins_dir, options, callback) {
+    events.emit('log', 'Fetching plugin from location "' + plugin_dir + '"...');
     // Ensure the containing directory exists.
     shell.mkdir('-p', plugins_dir);
 
@@ -32,7 +34,10 @@ module.exports = function fetchPlugin(plugin_dir, plugins_dir, options, callback
             };
 
             plugins.clonePluginGitRepo(plugin_dir, plugins_dir, options.subdir, options.git_ref, function(err, dir) {
-                if (!err) {
+                if (err) {
+                    if (callback) callback(err);
+                    else throw err;
+                } else {
                     metadata.save_fetch_metadata(dir, data);
                     if (callback) callback(null, dir);
                 }
@@ -43,17 +48,21 @@ module.exports = function fetchPlugin(plugin_dir, plugins_dir, options, callback
         // Copy from the local filesystem.
         // First, read the plugin.xml and grab the ID.
         plugin_dir = path.join(uri.path, options.subdir);
-        var xml = xml_helpers.parseElementtreeSync(path.join(plugin_dir, 'plugin.xml'));
+        var plugin_xml_path = path.join(plugin_dir, 'plugin.xml');
+        events.emit('log', 'Fetch is reading plugin.xml from location "' + plugin_xml_path + '"...');
+        var xml = xml_helpers.parseElementtreeSync(plugin_xml_path);
         var plugin_id = xml.getroot().attrib.id;
 
         var dest = path.join(plugins_dir, plugin_id);
 
         shell.rm('-rf', dest);
         if (options.link) {
+            events.emit('log', 'Symlinking from location "' + plugin_dir + '" to location "' + dest + '"');
             fs.symlinkSync(plugin_dir, dest, 'dir');
         } else {
             shell.mkdir('-p', dest);
-            shell.cp('-R', path.join(plugin_dir, '*') , dest);
+            events.emit('log', 'Copying from location "' + plugin_dir + '" to location "' + dest + '"');
+            shell.cp('-R', path.join(plugin_dir, '*'), dest);
         }
 
         var data = {

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/ce7a21ef/src/help.js
----------------------------------------------------------------------
diff --git a/src/help.js b/src/help.js
index 210cc48..775ea65 100644
--- a/src/help.js
+++ b/src/help.js
@@ -3,5 +3,5 @@ var fs = require('fs'),
 var doc_txt = path.join(__dirname, '..', 'doc', 'help.txt');
 
 module.exports = function help() {
-    console.log(fs.readFileSync(doc_txt, 'utf-8'));
+    return fs.readFileSync(doc_txt, 'utf-8');
 };

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/ce7a21ef/src/install.js
----------------------------------------------------------------------
diff --git a/src/install.js b/src/install.js
index 3f66fc1..179d228 100644
--- a/src/install.js
+++ b/src/install.js
@@ -22,7 +22,7 @@ var path = require('path'),
    3. runInstall
      a) checks if the plugin is already installed. if so, calls back (done).
      b) if possible, will check the version of the project and make sure it is compatible with the plugin (checks <engine> tags)
-     c) makes sure that any variables required by the plugin are specified
+     c) makes sure that any variables required by the plugin are specified. if they are not specified, plugman will throw or callback with an error.
      d) if dependencies are listed in the plugin, it will recurse for each dependent plugin and call possiblyFetch (2) on each one. When each dependent plugin is successfully installed, it will then proceed to call handleInstall (4)
    4. handleInstall
      a) queues up actions into a queue (asset, source-file, headers, etc)
@@ -34,9 +34,8 @@ var path = require('path'),
 module.exports = function installPlugin(platform, project_dir, id, plugins_dir, options, callback) {
     if (!platform_modules[platform]) {
         var err = new Error(platform + " not supported.");
-        if (callback) callback(err);
+        if (callback) return callback(err);
         else throw err;
-        return;
     }
 
     var current_stack = new action_stack();


[4/4] git commit: Slight tweak for wp8 support in action-stack.

Posted by fi...@apache.org.
Slight tweak for wp8 support in action-stack.


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugman/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugman/commit/823f9a82
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugman/tree/823f9a82
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugman/diff/823f9a82

Branch: refs/heads/master
Commit: 823f9a82fa63deb486d84eaf5264d22e2c46824d
Parents: ab34d89
Author: Fil Maj <ma...@gmail.com>
Authored: Wed Jul 3 10:17:55 2013 -0700
Committer: Fil Maj <ma...@gmail.com>
Committed: Wed Jul 3 10:17:55 2013 -0700

----------------------------------------------------------------------
 src/util/action-stack.js | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/823f9a82/src/util/action-stack.js
----------------------------------------------------------------------
diff --git a/src/util/action-stack.js b/src/util/action-stack.js
index 19602fb..c26bd9e 100644
--- a/src/util/action-stack.js
+++ b/src/util/action-stack.js
@@ -57,7 +57,7 @@ ActionStack.prototype = {
                     var undo = this.completed.shift();
                     var revert = undo.reverter.run;
                     var revert_params = undo.reverter.params;
-                    if (platform == 'ios' || platform == 'wp7') revert_params.push(project_files);
+                    if (platform == 'ios' || platform == 'wp7' || platform == 'wp8') revert_params.push(project_files);
                     try {
                         revert.apply(null, revert_params);
                     } catch(err) {
@@ -77,8 +77,8 @@ ActionStack.prototype = {
             events.emit('log', 'Writing out iOS pbxproj file...');
             fs.writeFileSync(project_files.pbx, project_files.xcode.writeSync());
         }
-        if (platform == 'wp7') {
-            events.emit('log', 'Writing out WP7 project files...');
+        if (platform == 'wp7' || platform == 'wp8') {
+            events.emit('log', 'Writing out ' + platform + ' project files...');
             project_files.write();
         }
         if (callback) callback();