Repository: cordova-lib Updated Branches: refs/heads/master a01ff2b18 -> 3ce67606e
CB-11022 Save modulesMetadata to both www and platform_www when necessary This closes #427 Project: http://git-wip-us.apache.org/repos/asf/cordova-lib/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-lib/commit/3ce67606 Tree: http://git-wip-us.apache.org/repos/asf/cordova-lib/tree/3ce67606 Diff: http://git-wip-us.apache.org/repos/asf/cordova-lib/diff/3ce67606 Branch: refs/heads/master Commit: 3ce67606e968c129f3433c2f1ccb21f29263e13a Parents: a01ff2b Author: Vladimir Kotikov <[email protected]> Authored: Thu Apr 14 15:53:35 2016 +0300 Committer: Vladimir Kotikov <[email protected]> Committed: Mon Apr 18 12:16:37 2016 +0300 ---------------------------------------------------------------------- cordova-common/spec/PluginManager.spec.js | 50 +++++++++++++++++++++++--- cordova-common/src/PluginManager.js | 10 ++++-- 2 files changed, 53 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/3ce67606/cordova-common/spec/PluginManager.spec.js ---------------------------------------------------------------------- diff --git a/cordova-common/spec/PluginManager.spec.js b/cordova-common/spec/PluginManager.spec.js index e99ab05..cba7c79 100644 --- a/cordova-common/spec/PluginManager.spec.js +++ b/cordova-common/spec/PluginManager.spec.js @@ -20,9 +20,10 @@ require ('promise-matchers'); var Q = require('q'); +var fs = require('fs'); var path = require('path'); +var shell = require('shelljs'); var rewire = require('rewire'); -var PlatformJson = require('../src/PlatformJson'); var PluginManager = rewire('../src/PluginManager'); var PluginInfo = require('../src/PluginInfo/PluginInfo'); var ConfigChanges = require('../src/ConfigChanges/ConfigChanges'); @@ -30,14 +31,17 @@ var ConfigChanges = require('../src/ConfigChanges/ConfigChanges'); var DUMMY_PLUGIN = path.join(__dirname, 'fixtures/plugins/org.test.plugins.dummyplugin'); var FAKE_PLATFORM = 'cordova-atari'; var FAKE_LOCATIONS = { - root: '/some/fake/path' + root: '/some/fake/path', + platformWww: '/some/fake/path/platform_www', + www: '/some/www/dir' }; describe('PluginManager class', function() { beforeEach(function () { - spyOn(PlatformJson, 'load'); spyOn(ConfigChanges, 'PlatformMunger'); + spyOn(fs, 'writeFileSync'); + spyOn(shell, 'mkdir'); }); it('should be constructable', function () { @@ -53,6 +57,7 @@ describe('PluginManager class', function() { describe('instance', function () { var actions, manager; var FAKE_PROJECT; + var fail = jasmine.createSpy('fail'); var ActionStackOrig = PluginManager.__get__('ActionStack'); beforeEach(function () { @@ -78,7 +83,7 @@ describe('PluginManager class', function() { expect(manager.addPlugin(new PluginInfo(DUMMY_PLUGIN), {})).not.toHaveBeenRejected(); }); - it('should iterate through all plugin\'s files and frameworks', function () { + it('should iterate through all plugin\'s files and frameworks', function (done) { manager.addPlugin(new PluginInfo(DUMMY_PLUGIN), {}) .then(function () { expect(FAKE_PROJECT.getInstaller.calls.length).toBe(16); @@ -87,6 +92,43 @@ describe('PluginManager class', function() { expect(actions.push.calls.length).toBe(16); expect(actions.process).toHaveBeenCalled(); expect(FAKE_PROJECT.write).toHaveBeenCalled(); + }) + .fail(fail) + .done(function () { + expect(fail).not.toHaveBeenCalled(); + done(); + }); + }); + + it('should save plugin metadata to www directory', function (done) { + var metadataPath = path.join(manager.locations.www, 'cordova_plugins.js'); + var platformWwwMetadataPath = path.join(manager.locations.platformWww, 'cordova_plugins.js'); + + manager.addPlugin(new PluginInfo(DUMMY_PLUGIN), {}) + .then(function () { + expect(fs.writeFileSync).toHaveBeenCalledWith(metadataPath, jasmine.any(String), 'utf-8'); + expect(fs.writeFileSync).not.toHaveBeenCalledWith(platformWwwMetadataPath, jasmine.any(String), 'utf-8'); + }) + .fail(fail) + .done(function () { + expect(fail).not.toHaveBeenCalled(); + done(); + }); + }); + + it('should save plugin metadata to both www ans platform_www directories when options.usePlatformWww is specified', function (done) { + var metadataPath = path.join(manager.locations.www, 'cordova_plugins.js'); + var platformWwwMetadataPath = path.join(manager.locations.platformWww, 'cordova_plugins.js'); + + manager.addPlugin(new PluginInfo(DUMMY_PLUGIN), {usePlatformWww: true}) + .then(function () { + expect(fs.writeFileSync).toHaveBeenCalledWith(metadataPath, jasmine.any(String), 'utf-8'); + expect(fs.writeFileSync).toHaveBeenCalledWith(platformWwwMetadataPath, jasmine.any(String), 'utf-8'); + }) + .fail(fail) + .done(function () { + expect(fail).not.toHaveBeenCalled(); + done(); }); }); }); http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/3ce67606/cordova-common/src/PluginManager.js ---------------------------------------------------------------------- diff --git a/cordova-common/src/PluginManager.js b/cordova-common/src/PluginManager.js index ea4d688..deeb92f 100644 --- a/cordova-common/src/PluginManager.js +++ b/cordova-common/src/PluginManager.js @@ -133,9 +133,13 @@ PluginManager.prototype.doOperation = function (operation, plugin, options) { // Save everything (munge and plugin/modules metadata) self.munger.save_all(); - var targetDir = options.usePlatformWww ? self.locations.platformWww : self.locations.www; - fs.writeFileSync(path.join(targetDir, 'cordova_plugins.js'), - self.munger.platformJson.generateMetadata(), 'utf-8'); + var metadata = self.munger.platformJson.generateMetadata(); + fs.writeFileSync(path.join(self.locations.www, 'cordova_plugins.js'), metadata, 'utf-8'); + + // CB-11022 save plugin metadata to both www and platform_www if options.usePlatformWww is specified + if (options.usePlatformWww) { + fs.writeFileSync(path.join(self.locations.platformWww, 'cordova_plugins.js'), metadata, 'utf-8'); + } }); }; --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
