This is an automated email from the ASF dual-hosted git repository.

purplecabbage pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-browser.git

commit 31070d9b2f376e601fabbb0da836dcf8e5212011
Merge: 30978e2 829f4ad
Author: Audrey <[email protected]>
AuthorDate: Mon Nov 13 10:10:42 2017 -0800

    Merge pull request #48 from audreyso/CB-13562
    
    CB-13562 : fixed asset tag when adding push plugin to browser
    
    CB-13614 Create file path before copying asset
    
    Fixes a bug that prevented copying over plugin assets that were nested in 
folders by creating a directory path before the copy command.
    
    CB-13614 Allow assets with a path to copy over correctly.
    
    CB-13614 Remove commented out code.

 bin/template/cordova/browser_handler.js | 12 ++++--
 spec/browser_handler.spec.js            | 69 +++++++++++++++++++++++++++++++++
 2 files changed, 77 insertions(+), 4 deletions(-)

diff --cc bin/template/cordova/browser_handler.js
index 6e732c7,3e12c25..4446bf0
--- a/bin/template/cordova/browser_handler.js
+++ b/bin/template/cordova/browser_handler.js
@@@ -115,12 -115,13 +115,16 @@@ module.exports = 
      asset: {
          install: function (asset, plugin_dir, wwwDest) {
              var src = path.join(plugin_dir, asset.src);
-             if (fs.statSync(src).isDirectory()) {
-                 src = path.join(src, '*');
-             }
              var dest = path.join(wwwDest, asset.target);
  
-             shell.cp('-rf', src, dest);
+             if (fs.statSync(src).isDirectory()) {
+                 shell.cp('-Rf', src + '/*', dest);
+             } else {
++                if (path.parse(asset.target).dir !== '') {
++                    shell.mkdir(path.parse(dest).dir);
++                }
+                 shell.cp('-f', src, dest);
+             }
          },
          uninstall: function (asset, wwwDest, plugin_id) {
              shell.rm('-rf', path.join(wwwDest, asset.target));
diff --cc spec/browser_handler.spec.js
index 0000000,70a0682..31e91ef
mode 000000,100644..100644
--- a/spec/browser_handler.spec.js
+++ b/spec/browser_handler.spec.js
@@@ -1,0 -1,54 +1,69 @@@
+ /**
+     Licensed to the Apache Software Foundation (ASF) under one
+     or more contributor license agreements.  See the NOTICE file
+     distributed with this work for additional information
+     regarding copyright ownership.  The ASF licenses this file
+     to you under the Apache License, Version 2.0 (the
+     "License"); you may not use this file except in compliance
+     with the License.  You may obtain a copy of the License at
+ 
+     http://www.apache.org/licenses/LICENSE-2.0
+ 
+     Unless required by applicable law or agreed to in writing,
+     software distributed under the License is distributed on an
+     "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+     KIND, either express or implied.  See the License for the
+     specific language governing permissions and limitations
+     under the License.
+ */
+ 
+ var browser_handler = require('../bin/template/cordova/browser_handler');
+ var shell = require('shelljs');
+ var fs = require('fs');
+ var path = require('path');
+ 
+ describe('Asset install tests', function () {
+     var fsstatMock;
+     var asset = { itemType: 'asset', src: 'someSrc/ServiceWorker.js', target: 
'ServiceWorker.js' };
++    var assetPath = { itemType: 'asset', src: 'someSrc/reformat.js', target: 
'js/deepdown/reformat.js' };
+     var plugin_dir = 'pluginDir';
+     var wwwDest = 'dest';
 -    var cpPath = path.join(plugin_dir, asset.src);
+ 
+     it('if src is a directory, should be called with cp, -Rf', function () {
+         var cp = spyOn(shell, 'cp').and.returnValue('-Rf');
+         fsstatMock = {
+             isDirectory: function () {
+                 return true;
+             }
+         };
+         spyOn(fs, 'statSync').and.returnValue(fsstatMock);
+         browser_handler.asset.install(asset, plugin_dir, wwwDest);
+         expect(cp).toHaveBeenCalledWith('-Rf', jasmine.any(String), 
path.join('dest', asset.target));
+     });
 -    it('if src is not a directory, should be called with cp, -f', function () 
{
++    it('if src is not a directory and asset has no path, should be called 
with cp, -f', function () {
+         var cp = spyOn(shell, 'cp').and.returnValue('-f');
++        var mkdir = spyOn(shell, 'mkdir');
+         fsstatMock = {
+             isDirectory: function () {
+                 return false;
+             }
+         };
+         spyOn(fs, 'statSync').and.returnValue(fsstatMock);
+         browser_handler.asset.install(asset, plugin_dir, wwwDest);
 -        expect(cp).toHaveBeenCalledWith('-f', cpPath, path.join('dest', 
asset.target));
++        expect(mkdir).not.toHaveBeenCalled();
++        expect(cp).toHaveBeenCalledWith('-f', 
'pluginDir/someSrc/ServiceWorker.js', 'dest/ServiceWorker.js');
++    });
++    it('if src is not a directory and asset has a path, should be called with 
cp, -f', function () {
++        var cp = spyOn(shell, 'cp').and.returnValue('-f');
++        var mkdir = spyOn(shell, 'mkdir');
++        fsstatMock = {
++            isDirectory: function () {
++                return false;
++            }
++        };
++        spyOn(fs, 'statSync').and.returnValue(fsstatMock);
++        browser_handler.asset.install(assetPath, plugin_dir, wwwDest);
++        expect(mkdir).toHaveBeenCalledWith('dest/js/deepdown');
++        expect(cp).toHaveBeenCalledWith('-f', 
'pluginDir/someSrc/reformat.js', 'dest/js/deepdown/reformat.js');
+     });
+ });

-- 
To stop receiving notification emails like this one, please contact
"[email protected]" <[email protected]>.

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to