Repository: cordova-ios Updated Branches: refs/heads/master 1078411d1 -> 410081646
CB-8980 - fix <resource-file> target attribute in config.xml The target attribute was not working properly - reflecting how the <resource-file> target attribute works in plugin.xml (related CB-12009) This closes #308 Project: http://git-wip-us.apache.org/repos/asf/cordova-ios/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-ios/commit/41008164 Tree: http://git-wip-us.apache.org/repos/asf/cordova-ios/tree/41008164 Diff: http://git-wip-us.apache.org/repos/asf/cordova-ios/diff/41008164 Branch: refs/heads/master Commit: 4100816464cca3c4dd4fea394e84c349b973a908 Parents: 1078411 Author: Shazron Abdullah <[email protected]> Authored: Thu Apr 20 16:27:37 2017 -0700 Committer: Shazron Abdullah <[email protected]> Committed: Thu Apr 20 17:14:29 2017 -0700 ---------------------------------------------------------------------- bin/templates/scripts/cordova/lib/prepare.js | 4 +- .../fixtures/resource-file-support/config.xml | 1 + .../resource-file-support/image-1234.png | Bin 0 -> 142687 bytes tests/spec/unit/prepare.spec.js | 59 +++++++++++-------- 4 files changed, 38 insertions(+), 26 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/41008164/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 d2a3379..a2b38f8 100644 --- a/bin/templates/scripts/cordova/lib/prepare.js +++ b/bin/templates/scripts/cordova/lib/prepare.js @@ -480,8 +480,8 @@ function updateFileResources(cordovaProject, locations) { resourceMap, { rootDir: cordovaProject.root }, logFileOp); Object.keys(resourceMap).sort().forEach(function (targetPath) { - var sourcePath = resourceMap[targetPath]; - project.xcode.addResourceFile(path.join('Resources', path.basename(sourcePath))); + var resfile = path.join('Resources', path.relative(project.resources_dir, targetPath)); + project.xcode.addResourceFile(resfile); }); project.write(); http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/41008164/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 2705da7..f927107 100644 --- a/tests/spec/unit/fixtures/resource-file-support/config.xml +++ b/tests/spec/unit/fixtures/resource-file-support/config.xml @@ -13,6 +13,7 @@ <platform name="ios"> <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/41008164/tests/spec/unit/fixtures/resource-file-support/image-1234.png ---------------------------------------------------------------------- diff --git a/tests/spec/unit/fixtures/resource-file-support/image-1234.png b/tests/spec/unit/fixtures/resource-file-support/image-1234.png new file mode 100644 index 0000000..6a357be Binary files /dev/null and b/tests/spec/unit/fixtures/resource-file-support/image-1234.png differ http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/41008164/tests/spec/unit/prepare.spec.js ---------------------------------------------------------------------- diff --git a/tests/spec/unit/prepare.spec.js b/tests/spec/unit/prepare.spec.js index 273977e..a091e47 100644 --- a/tests/spec/unit/prepare.spec.js +++ b/tests/spec/unit/prepare.spec.js @@ -1489,13 +1489,22 @@ describe('prepare', function() { }); describe('<resource-file> tests', function() { - const imageFileName = 'image-5678.png'; + const images = [ + { + 'src': 'image-5678.png', + 'target': 'image-5678.png' + }, + { + 'src': 'image-1234.png', + 'target': path.join('images', 'image-3456.png') + } + ]; const projectRoot = path.join(FIXTURES, 'resource-file-support'); const updateFileResources = prepare.__get__('updateFileResources'); const cleanFileResources = prepare.__get__('cleanFileResources'); const cfgResourceFiles = new ConfigParser(path.join(FIXTURES, 'resource-file-support', 'config.xml')); - function findImageFileRef(pbxproj) { + function findImageFileRef(pbxproj, imageFileName) { const buildfiles = pbxproj.pbxBuildFileSection(); return Object.keys(buildfiles).filter(function(uuid) { var filename = buildfiles[uuid].fileRef_comment; @@ -1528,34 +1537,36 @@ describe('prepare', function() { updateFileResources(cordovaProject, p.locations); const project = projectFile.parse(p.locations); - // check whether the file is copied in the correct location - const copiedImageFile = path.join(project.resources_dir, imageFileName); - expect(fs.existsSync(copiedImageFile)).toBeTruthy(); - - // find PBXBuildFile file reference - const imagefileRefs = findImageFileRef(project.xcode); - expect(imagefileRefs.length).toEqual(1); - - // find file reference in PBXResourcesBuildPhase - const resBuildPhaseFileRefs = findResourcesBuildPhaseRef(project.xcode, imagefileRefs[0]); - expect(resBuildPhaseFileRefs.length).toEqual(1); + for (let image of images) { + // check whether the file is copied to the target location + let copiedImageFile = path.join(project.resources_dir, image.target); + expect(fs.existsSync(copiedImageFile)).toEqual(true); + + // find PBXBuildFile file reference + let imagefileRefs = findImageFileRef(project.xcode, path.basename(image.target)); + expect(imagefileRefs.length).toEqual(1); + // find file reference in PBXResourcesBuildPhase + let resBuildPhaseFileRefs = findResourcesBuildPhaseRef(project.xcode, imagefileRefs[0]); + expect(resBuildPhaseFileRefs.length).toEqual(1); + } }); it('<resource-file> clean - remove image-5678.png', function() { cleanFileResources(projectRoot, cfgResourceFiles, p.locations); const project = projectFile.parse(p.locations); - // check whether the file is removed from the correct location - const copiedImageFile = path.join(project.resources_dir, imageFileName); - expect(fs.existsSync(copiedImageFile)).toBeFalsy(); - - // find PBXBuildFile file reference - const imagefileRefs = findImageFileRef(project.xcode); - expect(imagefileRefs.length).toEqual(0); - - // find file reference in PBXResourcesBuildPhase - const resBuildPhaseFileRefs = findResourcesBuildPhaseRef(project.xcode, imagefileRefs[0]); - expect(resBuildPhaseFileRefs.length).toEqual(0); + for (let image of images) { + // check whether the file is removed from the target location + let copiedImageFile = path.join(project.resources_dir, image.target); + expect(fs.existsSync(copiedImageFile)).toEqual(false); + + // find PBXBuildFile file reference + let imagefileRefs = findImageFileRef(project.xcode, path.basename(image.target)); + expect(imagefileRefs.length).toEqual(0); + // find file reference in PBXResourcesBuildPhase + let resBuildPhaseFileRefs = findResourcesBuildPhaseRef(project.xcode, imagefileRefs[0]); + expect(resBuildPhaseFileRefs.length).toEqual(0); + } }); }); --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
