Repository: cordova-ios Updated Branches: refs/heads/master 410081646 -> 28276fc6b
CB-8980 - add missing 'target' attribute test for <resource-file> in config.xml Project: http://git-wip-us.apache.org/repos/asf/cordova-ios/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-ios/commit/28276fc6 Tree: http://git-wip-us.apache.org/repos/asf/cordova-ios/tree/28276fc6 Diff: http://git-wip-us.apache.org/repos/asf/cordova-ios/diff/28276fc6 Branch: refs/heads/master Commit: 28276fc6b59b061809b7b05baca4430f2eea0ad0 Parents: 4100816 Author: Shazron Abdullah <[email protected]> Authored: Fri Apr 21 16:36:50 2017 -0700 Committer: Shazron Abdullah <[email protected]> Committed: Fri Apr 21 16:36:50 2017 -0700 ---------------------------------------------------------------------- bin/templates/scripts/cordova/lib/prepare.js | 40 ++++++++++++------- .../fixtures/resource-file-support/config.xml | 1 + .../resource-file-support/image-8888.png | Bin 0 -> 56360 bytes tests/spec/unit/prepare.spec.js | 9 ++++- 4 files changed, 34 insertions(+), 16 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/28276fc6/bin/templates/scripts/cordova/lib/prepare.js ---------------------------------------------------------------------- diff --git a/bin/templates/scripts/cordova/lib/prepare.js b/bin/templates/scripts/cordova/lib/prepare.js index a2b38f8..c02c187 100644 --- a/bin/templates/scripts/cordova/lib/prepare.js +++ b/bin/templates/scripts/cordova/lib/prepare.js @@ -470,20 +470,26 @@ function updateFileResources(cordovaProject, locations) { let resourceMap = {}; files.forEach(function(res) { - let targetPath = path.join(project.resources_dir, res.target); + let src = res.src, + target = res.target; + + if (!target) { + target = src; + } + + let targetPath = path.join(project.resources_dir, target); targetPath = path.relative(cordovaProject.root, targetPath); - resourceMap[targetPath] = res.src; + + const resfile = path.join('Resources', path.relative(project.resources_dir, targetPath)); + project.xcode.addResourceFile(resfile); + + resourceMap[targetPath] = src; }); events.emit('verbose', 'Updating resource files at ' + platformDir); FileUpdater.updatePaths( resourceMap, { rootDir: cordovaProject.root }, logFileOp); - Object.keys(resourceMap).sort().forEach(function (targetPath) { - var resfile = path.join('Resources', path.relative(project.resources_dir, targetPath)); - project.xcode.addResourceFile(resfile); - }); - project.write(); } @@ -497,18 +503,24 @@ function cleanFileResources(projectRoot, projectConfig, locations) { var resourceMap = {}; files.forEach(function(res) { - let filePath = path.join(project.resources_dir, res.target); - filePath = path.relative(projectRoot, filePath); - resourceMap[filePath] = null; + let src = res.src, + target = res.target; + + if (!target) { + target = src; + } + + let targetPath = path.join(project.resources_dir, target); + targetPath = path.relative(projectRoot, targetPath); + const resfile = path.join('Resources', path.basename(targetPath)); + project.xcode.removeResourceFile(resfile); + + resourceMap[targetPath] = null; }); FileUpdater.updatePaths( resourceMap, { rootDir: projectRoot, all: true}, logFileOp); - Object.keys(resourceMap).sort().forEach(function (targetPath) { - project.xcode.removeResourceFile(path.join('Resources', path.basename(targetPath))); - }); - project.write(); } } http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/28276fc6/tests/spec/unit/fixtures/resource-file-support/config.xml ---------------------------------------------------------------------- diff --git a/tests/spec/unit/fixtures/resource-file-support/config.xml b/tests/spec/unit/fixtures/resource-file-support/config.xml index f927107..d49965a 100644 --- a/tests/spec/unit/fixtures/resource-file-support/config.xml +++ b/tests/spec/unit/fixtures/resource-file-support/config.xml @@ -12,6 +12,7 @@ <access origin="*" /> <platform name="ios"> + <resource-file src="image-8888.png" /> <resource-file src="image-5678.png" target="image-5678.png" /> <resource-file src="image-1234.png" target="images/image-3456.png" /> </platform> http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/28276fc6/tests/spec/unit/fixtures/resource-file-support/image-8888.png ---------------------------------------------------------------------- diff --git a/tests/spec/unit/fixtures/resource-file-support/image-8888.png b/tests/spec/unit/fixtures/resource-file-support/image-8888.png new file mode 100644 index 0000000..e2ec214 Binary files /dev/null and b/tests/spec/unit/fixtures/resource-file-support/image-8888.png differ http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/28276fc6/tests/spec/unit/prepare.spec.js ---------------------------------------------------------------------- diff --git a/tests/spec/unit/prepare.spec.js b/tests/spec/unit/prepare.spec.js index a091e47..5f43e38 100644 --- a/tests/spec/unit/prepare.spec.js +++ b/tests/spec/unit/prepare.spec.js @@ -1489,6 +1489,7 @@ describe('prepare', function() { }); describe('<resource-file> tests', function() { + // image-8888.png target attribute is missing in config.xml as a test const images = [ { 'src': 'image-5678.png', @@ -1497,6 +1498,10 @@ describe('prepare', function() { { 'src': 'image-1234.png', 'target': path.join('images', 'image-3456.png') + }, + { + 'src': 'image-8888.png', + 'target': 'image-8888.png' } ]; const projectRoot = path.join(FIXTURES, 'resource-file-support'); @@ -1524,7 +1529,7 @@ describe('prepare', function() { return resBuildPhaseFileRefs; } - it('<resource-file> prepare - copy image-5678.png', function() { + it('<resource-file> prepare - copy', function() { const cordovaProject = { root: projectRoot, projectConfig: cfgResourceFiles, @@ -1551,7 +1556,7 @@ describe('prepare', function() { } }); - it('<resource-file> clean - remove image-5678.png', function() { + it('<resource-file> clean - remove', function() { cleanFileResources(projectRoot, cfgResourceFiles, p.locations); const project = projectFile.parse(p.locations); --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
