cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bra...@apache.org
Subject git commit: Add --www option to install and uninstall. Fix specs, add new specs.
Date Tue, 07 May 2013 19:07:03 GMT
Updated Branches:
  refs/heads/master ca883de68 -> 18c46eb83


Add --www option to install and uninstall. Fix specs, add new specs.


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

Branch: refs/heads/master
Commit: 18c46eb838a28e0fc5c7f5fe7bdeb366f9b2ba0a
Parents: ca883de
Author: Braden Shepherdson <braden.shepherdson@gmail.com>
Authored: Tue May 7 15:06:35 2013 -0400
Committer: Braden Shepherdson <braden.shepherdson@gmail.com>
Committed: Tue May 7 15:06:35 2013 -0400

----------------------------------------------------------------------
 main.js                           |    9 ++++---
 spec/install.spec.js              |   41 +++++++++++++++++++++++++++++++-
 spec/platforms/android.spec.js    |    2 +-
 spec/platforms/blackberry.spec.js |    2 +-
 src/install.js                    |   21 ++++++++-------
 5 files changed, 58 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/18c46eb8/main.js
----------------------------------------------------------------------
diff --git a/main.js b/main.js
index 83a5280..8913d02 100755
--- a/main.js
+++ b/main.js
@@ -36,6 +36,7 @@ var known_opts = { 'platform' : [ 'ios', 'android', 'blackberry', 'wp7',
'wp8' ]
             , 'plugins': path
             , 'link': Boolean
             , 'variable' : Array
+            , 'www': path
             }, shortHands = { 'var' : 'variable' };
 
 var cli_opts = nopt(known_opts);
@@ -62,7 +63,7 @@ else if (!cli_opts.platform || !cli_opts.project || !cli_opts.plugin) {
     printUsage();
 }
 else if (cli_opts.uninstall) {
-    plugman.uninstall(cli_opts.platform, cli_opts.project, cli_opts.plugin, plugins_dir);
+    plugman.uninstall(cli_opts.platform, cli_opts.project, cli_opts.plugin, plugins_dir,
cli_opts.www);
 }
 else {
     var cli_variables = {}
@@ -73,13 +74,13 @@ else {
             if (/^[\w-_]+$/.test(key)) cli_variables[key] = tokens.join('=');
         });
     }
-    plugman.install(cli_opts.platform, cli_opts.project, cli_opts.plugin, plugins_dir, cli_variables);
+    plugman.install(cli_opts.platform, cli_opts.project, cli_opts.plugin, plugins_dir, cli_variables,
cli_opts.www);
 }
 
 function printUsage() {
     platforms = known_opts.platform.join('|');
     console.log('Usage\n---------');
-    console.log('Install a plugin (will call fetch if cannot be found):\n\t' + package.name
+ ' --platform <'+ platforms +'> --project <directory> --plugin <name> [--plugins_dir
<directory>] [--variable <name>=<value>]\n');
-    console.log('Uninstall a plugin:\n\t' + package.name + ' --uninstall --platform <'+
platforms +'> --project <directory> --plugin <name> [--plugins_dir <directory>]\n');
+    console.log('Install a plugin (will call fetch if cannot be found):\n\t' + package.name
+ ' --platform <'+ platforms +'> --project <directory> --plugin <name> [--www
<directory>] [--plugins_dir <directory>] [--variable <name>=<value>]\n');
+    console.log('Uninstall a plugin:\n\t' + package.name + ' --uninstall --platform <'+
platforms +'> --project <directory> --plugin <name> [--www <directory>]
[--plugins_dir <directory>]\n');
     console.log('\n\t--plugins_dir defaults to <project>/cordova/plugins, but can be
any directory containing a subdirectory for each plugin');
 }

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/18c46eb8/spec/install.spec.js
----------------------------------------------------------------------
diff --git a/spec/install.spec.js b/spec/install.spec.js
index c0c705b..c471747 100644
--- a/spec/install.spec.js
+++ b/spec/install.spec.js
@@ -74,6 +74,45 @@ describe('install', function() {
             expect(fs.existsSync(path.join(temp, 'assets', 'www', 'dummyplugin.js'))).toBe(false);
             expect(fs.existsSync(path.join(temp, 'assets', 'www', 'dummyplugin'))).toBe(false);
         });
+
+        it('should properly install assets into a custom www dir', function() {
+            var s = spyOn(common, 'copyFile').andCallThrough();
+            install('android', temp, 'DummyPlugin', plugins_dir, {}, path.join(temp, 'staging'));
+            // making sure the right methods were called
+            expect(s).toHaveBeenCalled();
+            expect(s.calls.length).toEqual(2);
+
+            expect(fs.existsSync(path.join(temp, 'staging', 'dummyplugin.js'))).toBe(true);
+            expect(fs.existsSync(path.join(temp, 'staging', 'dummyplugin'))).toBe(true);
+            expect(fs.existsSync(path.join(temp, 'staging', 'dummyplugin', 'image.jpg'))).toBe(true);
+            expect(fs.statSync(path.join(temp, 'staging', 'dummyplugin.js')).isFile()).toBe(true);
+            expect(fs.statSync(path.join(temp, 'staging', 'dummyplugin')).isDirectory()).toBe(true);
+            expect(fs.statSync(path.join(temp, 'staging', 'dummyplugin', 'image.jpg')).isFile()).toBe(true);
+        });
+
+        it('should revert all assets on asset install error with a custom www dir', function()
{
+            var sCopyFile = spyOn(common, 'copyFile').andCallThrough();
+            var sRemoveFile = spyOn(common, 'removeFile').andCallThrough();
+            var sRemoveFileF = spyOn(common, 'removeFileF').andCallThrough();
+            
+            // messing the plugin
+            shell.rm('-rf', path.join(plugins_dir, 'dummyplugin', 'www', 'dummyplugin'));

+            expect(function() {
+                install('android', temp, 'DummyPlugin', plugins_dir, {}, path.join(temp,
'staging'));
+            }).toThrow();
+            // making sure the right methods were called
+            expect(sCopyFile).toHaveBeenCalled();
+            expect(sCopyFile.calls.length).toEqual(2);
+
+            expect(sRemoveFile).toHaveBeenCalled();
+            expect(sRemoveFile.calls.length).toEqual(1);
+            expect(sRemoveFileF).toHaveBeenCalled();
+            expect(sRemoveFileF.calls.length).toEqual(1);
+           
+            expect(fs.existsSync(path.join(temp, 'staging', 'dummyplugin.js'))).toBe(false);
+            expect(fs.existsSync(path.join(temp, 'staging', 'dummyplugin'))).toBe(false);
+        });
+
         it('should call prepare after a successful install', function() {
             var s = spyOn(plugman, 'prepare');
             install('android', temp, 'DummyPlugin', plugins_dir, {});
@@ -145,7 +184,7 @@ describe('install', function() {
             shell.cp('-rf', dummyplugin, plugins_dir);
             shell.rm(path.join(plugins_dir, 'DummyPlugin', 'src', 'android', 'DummyPlugin.java'));

             
-            install('android', temp, 'DummyPlugin', plugins_dir, {}, function() {});
+            install('android', temp, 'DummyPlugin', plugins_dir, {}, undefined, function()
{});
             
             expect(sRemoveFile).toHaveBeenCalled();
             expect(sRemoveFile.calls.length).toEqual(2);

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/18c46eb8/spec/platforms/android.spec.js
----------------------------------------------------------------------
diff --git a/spec/platforms/android.spec.js b/spec/platforms/android.spec.js
index f20e68a..57ed4c9 100644
--- a/spec/platforms/android.spec.js
+++ b/spec/platforms/android.spec.js
@@ -109,7 +109,7 @@ describe('android project handler', function() {
         describe('of <source-file> elements', function() {
             it('should remove stuff by calling common.deleteJava', function(done) {
                 var s = spyOn(common, 'deleteJava');
-                install('android', temp, 'DummyPlugin', plugins_dir, {}, function() {
+                install('android', temp, 'DummyPlugin', plugins_dir, {}, undefined, function()
{
                     var source = copyArray(valid_source);
                     android.uninstall(source, dummy_id, temp, path.join(plugins_dir, 'DummyPlugin'));
                     expect(s).toHaveBeenCalledWith(temp, 'src/com/phonegap/plugins/dummyplugin/DummyPlugin.java');

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/18c46eb8/spec/platforms/blackberry.spec.js
----------------------------------------------------------------------
diff --git a/spec/platforms/blackberry.spec.js b/spec/platforms/blackberry.spec.js
index 204d5e0..c59af0c 100644
--- a/spec/platforms/blackberry.spec.js
+++ b/spec/platforms/blackberry.spec.js
@@ -98,7 +98,7 @@ describe('blackberry project handler', function() {
         describe('of <source-file> elements', function() {
             it('should remove stuff by calling common.deleteJava', function(done) {
                 var s = spyOn(common, 'deleteJava');
-                install('blackberry', temp, 'DummyPlugin', plugins_dir, {}, function() {
+                install('blackberry', temp, 'DummyPlugin', plugins_dir, {}, undefined, function()
{
                     var source = copyArray(valid_source);
                     blackberry.uninstall(source, dummy_id, temp, path.join(plugins_dir, 'DummyPlugin'));
                     expect(s).toHaveBeenCalledWith(temp, 'ext-qnx/cordova.echo/client.js');

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/18c46eb8/src/install.js
----------------------------------------------------------------------
diff --git a/src/install.js b/src/install.js
index 8626f4f..617b065 100644
--- a/src/install.js
+++ b/src/install.js
@@ -5,10 +5,10 @@ var path = require('path'),
     platform_modules = require('./platforms');
 
 // TODO: is name necessary as a param ehre?
-module.exports = function installPlugin(platform, project_dir, name, plugins_dir, cli_variables,
callback) {
+module.exports = function installPlugin(platform, project_dir, name, plugins_dir, cli_variables,
www_dir, callback) {
     if (!platform_modules[platform]) {
         var err = new Error(platform + " not supported.");
-        if (callback) { 
+        if (callback) {
             callback(err);
             return;
         }
@@ -25,15 +25,15 @@ module.exports = function installPlugin(platform, project_dir, name, plugins_dir
                 callback(err);
             } else {
                 // update ref to plugin_dir after successful fetch, via fetch callback
-                runInstall(platform, project_dir, plugin_dir, plugins_dir, cli_variables,
callback);
+                runInstall(platform, project_dir, plugin_dir, plugins_dir, cli_variables,
www_dir, callback);
             }
         });
     } else {
-        runInstall(platform, project_dir, plugin_dir, plugins_dir, cli_variables, callback);
+        runInstall(platform, project_dir, plugin_dir, plugins_dir, cli_variables, www_dir,
callback);
     }
 };
 
-function runInstall(platform, project_dir, plugin_dir, plugins_dir, cli_variables, callback)
{
+function runInstall(platform, project_dir, plugin_dir, plugins_dir, cli_variables, www_dir,
callback) {
     var xml_path     = path.join(plugin_dir, 'plugin.xml')
       , xml_text     = fs.readFileSync(xml_path, 'utf-8')
       , plugin_et    = new et.ElementTree(et.XML(xml_text))
@@ -104,11 +104,12 @@ function runInstall(platform, project_dir, plugin_dir, plugins_dir,
cli_variable
     // asset installation
     var installedAssets = [];
     var common = require('./platforms/common');
+    www_dir = www_dir || handler.www_dir(project_dir);
     try {
         for(var i = 0, j = assets.length ; i < j ; i++) {
             var src = assets[i].attrib['src'],
                 target = assets[i].attrib['target'];
-            common.copyFile(plugin_dir, src, handler.www_dir(project_dir), target);
+            common.copyFile(plugin_dir, src, www_dir, target);
             installedAssets.push(assets[i]);
         }
     } catch(err) {
@@ -116,9 +117,9 @@ function runInstall(platform, project_dir, plugin_dir, plugins_dir, cli_variable
         try {
             // removing assets and reverting install
             for(var i = 0, j = installedAssets.length ; i < j ; i++) {
-               common.removeFile(handler.www_dir(project_dir), installedAssets[i].attrib.target);
+               common.removeFile(www_dir, installedAssets[i].attrib.target);
             }
-            common.removeFileF(path.resolve(handler.www_dir(project_dir), 'plugins', plugin_id));
+            common.removeFileF(path.resolve(www_dir, 'plugins', plugin_id));
             issue += 'but successfully reverted\n';
         } catch(err2) {
             issue += 'and reversion failed :(\n' + err2.stack;
@@ -135,9 +136,9 @@ function runInstall(platform, project_dir, plugin_dir, plugins_dir, cli_variable
             var issue = '';
             try {
                 for(var i = 0, j = installedAssets.length ; i < j ; i++) {
-                   common.removeFile(handler.www_dir(project_dir), installedAssets[i].attrib.target);
+                   common.removeFile(www_dir, installedAssets[i].attrib.target);
                 }
-                common.removeFileF(path.resolve(handler.www_dir(project_dir), 'plugins',
plugin_id));
+                common.removeFileF(path.resolve(www_dir, 'plugins', plugin_id));
             } catch(err2) {
                 issue += 'Could not revert assets' + err2.stack + '\n';
             }


Mime
View raw message