You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by GitBox <gi...@apache.org> on 2017/12/06 06:46:08 UTC

[GitHub] purplecabbage closed pull request #49: CB-13614: (browser) Fix asset copy bug.

purplecabbage closed pull request #49: CB-13614: (browser) Fix asset copy bug.
URL: https://github.com/apache/cordova-browser/pull/49
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/bin/template/cordova/browser_handler.js b/bin/template/cordova/browser_handler.js
index 3e12c25..da1be3f 100644
--- a/bin/template/cordova/browser_handler.js
+++ b/bin/template/cordova/browser_handler.js
@@ -120,6 +120,9 @@ module.exports = {
             if (fs.statSync(src).isDirectory()) {
                 shell.cp('-Rf', src + '/*', dest);
             } else {
+                if (path.parse(asset.target).dir !== '') {
+                    shell.mkdir('-p', path.parse(dest).dir);
+                }
                 shell.cp('-f', src, dest);
             }
         },
diff --git a/spec/browser_handler.spec.js b/spec/browser_handler.spec.js
index 70a0682..1654b75 100644
--- a/spec/browser_handler.spec.js
+++ b/spec/browser_handler.spec.js
@@ -24,10 +24,10 @@ var path = require('path');
 
 describe('Asset install tests', function () {
     var fsstatMock;
-    var asset = { itemType: 'asset', src: 'someSrc/ServiceWorker.js', target: 'ServiceWorker.js' };
+    var asset = { itemType: 'asset', src: path.join('someSrc', 'ServiceWorker.js'), target: 'ServiceWorker.js' };
+    var assetWithPath = { itemType: 'asset', src: path.join('someSrc', 'reformat.js'), target: path.join('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');
@@ -40,8 +40,9 @@ describe('Asset install tests', function () {
         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;
@@ -49,6 +50,20 @@ describe('Asset install tests', function () {
         };
         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', path.join('pluginDir', 'someSrc', 'ServiceWorker.js'), path.join('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(assetWithPath, plugin_dir, wwwDest);
+        expect(mkdir).toHaveBeenCalledWith('-p', path.join('dest', 'js', 'deepdown'));
+        expect(cp).toHaveBeenCalledWith('-f', path.join('pluginDir', 'someSrc', 'reformat.js'), path.join('dest', 'js', 'deepdown', 'reformat.js'));
     });
 });


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org