Repository: cordova-ios Updated Branches: refs/heads/master 28276fc6b -> 3d82225df
CB-12009 - <resource-file> target attribute ignored on iOS when installing a Cordova plugin This closes #310 Project: http://git-wip-us.apache.org/repos/asf/cordova-ios/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-ios/commit/3d82225d Tree: http://git-wip-us.apache.org/repos/asf/cordova-ios/tree/3d82225d Diff: http://git-wip-us.apache.org/repos/asf/cordova-ios/diff/3d82225d Branch: refs/heads/master Commit: 3d82225dfaa67882202f7a92f511a98b780b8ccb Parents: 28276fc Author: Shazron Abdullah <[email protected]> Authored: Fri Apr 21 15:47:53 2017 -0700 Committer: Shazron Abdullah <[email protected]> Committed: Fri Apr 21 16:50:28 2017 -0700 ---------------------------------------------------------------------- .../cordova/lib/plugman/pluginHandlers.js | 30 +++++++++++++++----- tests/spec/unit/Plugman/pluginHandler.spec.js | 2 +- 2 files changed, 24 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/3d82225d/bin/templates/scripts/cordova/lib/plugman/pluginHandlers.js ---------------------------------------------------------------------- diff --git a/bin/templates/scripts/cordova/lib/plugman/pluginHandlers.js b/bin/templates/scripts/cordova/lib/plugman/pluginHandlers.js index d6724a2..416aba9 100644 --- a/bin/templates/scripts/cordova/lib/plugman/pluginHandlers.js +++ b/bin/templates/scripts/cordova/lib/plugman/pluginHandlers.js @@ -49,18 +49,34 @@ var handlers = { 'resource-file':{ install:function(obj, plugin, project, options) { var src = obj.src, - srcFile = path.resolve(plugin.dir, src), - destFile = path.resolve(project.resources_dir, path.basename(src)); - if (!fs.existsSync(srcFile)) throw new CordovaError('Cannot find resource file "' + srcFile + '" for plugin ' + plugin.id + ' in iOS platform'); - if (fs.existsSync(destFile)) throw new CordovaError('File already exists at detination "' + destFile + '" for resource file specified by plugin ' + plugin.id + ' in iOS platform'); - project.xcode.addResourceFile(path.join('Resources', path.basename(src))); + target = obj.target, + srcFile = path.resolve(plugin.dir, src); + + if (!target) { + target = path.basename(src); + } + var destFile = path.resolve(project.resources_dir, target); + + if (!fs.existsSync(srcFile)) { + throw new CordovaError('Cannot find resource file "' + srcFile + '" for plugin ' + plugin.id + ' in iOS platform'); + } + if (fs.existsSync(destFile)) { + throw new CordovaError('File already exists at destination "' + destFile + '" for resource file specified by plugin ' + plugin.id + ' in iOS platform'); + } + project.xcode.addResourceFile(path.join('Resources', target)); var link = !!(options && options.link); copyFile(plugin.dir, src, project.projectDir, destFile, link); }, uninstall:function(obj, plugin, project, options) { var src = obj.src, - destFile = path.resolve(project.resources_dir, path.basename(src)); - project.xcode.removeResourceFile(path.join('Resources', path.basename(src))); + target = obj.target; + + if (!target) { + target = path.basename(src); + } + var destFile = path.resolve(project.resources_dir, target); + + project.xcode.removeResourceFile(path.join('Resources', target)); shell.rm('-rf', destFile); } }, http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/3d82225d/tests/spec/unit/Plugman/pluginHandler.spec.js ---------------------------------------------------------------------- diff --git a/tests/spec/unit/Plugman/pluginHandler.spec.js b/tests/spec/unit/Plugman/pluginHandler.spec.js index 6a94d12..d615bc6 100644 --- a/tests/spec/unit/Plugman/pluginHandler.spec.js +++ b/tests/spec/unit/Plugman/pluginHandler.spec.js @@ -206,7 +206,7 @@ describe('ios plugin handler', function() { fs.writeFileSync(target, 'some bs', 'utf-8'); expect(function() { install(resources[0], dummyPluginInfo, dummyProject); - }).toThrow(new Error('File already exists at detination "' + target + '" for resource file specified by plugin ' + dummyPluginInfo.id + ' in iOS platform')); + }).toThrow(new Error('File already exists at destination "' + target + '" for resource file specified by plugin ' + dummyPluginInfo.id + ' in iOS platform')); }); it('Test 016 : should call into xcodeproj\'s addResourceFile', function() { var resources = copyArray(valid_resources); --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
