diff --git a/lib/pbxProject.js b/lib/pbxProject.js index d2a9192..c9f7b85 100644 --- a/lib/pbxProject.js +++ b/lib/pbxProject.js @@ -435,8 +435,8 @@ pbxProject.prototype.pbxCopyfilesBuildPhaseObj = function(target) { return this.buildPhaseObject('PBXCopyFilesBuildPhase', 'Copy Files', target); } -pbxProject.prototype.addToPbxCopyfilesBuildPhase = function(file) { - var sources = this.buildPhaseObject('PBXCopyFilesBuildPhase', 'Copy Files', file.target); +pbxProject.prototype.addToPbxCopyfilesBuildPhase = function(file, comment, target) { + var sources = this.buildPhaseObject('PBXCopyFilesBuildPhase', comment || 'Copy Files', target || file.target); sources.files.push(pbxBuildPhaseObj(file)); } @@ -508,6 +508,17 @@ pbxProject.prototype.removeFromPbxBuildFileSection = function(file) { } } +pbxProject.prototype.removeFromPbxBuildFileSectionByFileRef = function(file) { + var fileUuid; + var pbxBuildFileSection = this.pbxBuildFileSection(); + + for (fileUuid in pbxBuildFileSection) { + if (pbxBuildFileSection[fileUuid].fileRef == file.uuid) { + this.removeFromPbxBuildFileSectionByUuid(fileUuid); + } + } +} + pbxProject.prototype.removeFromPbxBuildFileSectionByUuid = function(itemUuid) { var buildSection = this.pbxBuildFileSection(); removeItemAndCommentFromSectionByUuid(buildSection, itemUuid); @@ -539,10 +550,11 @@ pbxProject.prototype.addPbxGroup = function (filePathsArray, name, path, sourceT var groups = this.hash.project.objects['PBXGroup'], pbxGroupUuid = opt.uuid || this.generateUuid(), commentKey = f("%s_comment", pbxGroupUuid), + groupName = name.indexOf(" ") >= 0 && name[0] !== `"` ? `"${name}"` : name, pbxGroup = { isa: 'PBXGroup', children: [], - name: name, + name: groupName, sourceTree: sourceTree ? sourceTree : '""' }, fileReferenceSection = this.pbxFileReferenceSection(), @@ -700,7 +712,7 @@ pbxProject.prototype.removePbxGroupByKey = function(groupKey, path) { file.uuid = file.fileRef; this.removePbxGroupByKey(children[i].value, $path.join(path, children[i].comment)); this.removeFromPbxFileReferenceSectionByUuid(children[i].value); - this.removeFromPbxBuildFileSection(file); + this.removeFromPbxBuildFileSectionByFileRef(file); this.removeFromPbxSourcesBuildPhase(file); } @@ -1616,7 +1628,7 @@ pbxProject.prototype.getFileKey = function(filePath) { return false; } -pbxProject.prototype.addTarget = function(name, type, subfolder) { +pbxProject.prototype.addTarget = function(name, type, subfolder, parentTarget) { // Setup uuid and name of new target var targetUuid = this.generateUuid(), @@ -1695,26 +1707,30 @@ pbxProject.prototype.addTarget = function(name, type, subfolder) { }; // Target: Add to PBXNativeTarget section - this.addToPbxNativeTargetSection(target) - - // Product: Embed (only for "extension"-type targets) - if (targetType === 'app_extension') { + this.addToPbxNativeTargetSection(target); - // Create CopyFiles phase in first target - this.addBuildPhase([], 'PBXCopyFilesBuildPhase', 'Copy Files', this.getFirstTarget().uuid, targetType) + if (targetType === 'app_extension' || targetType === 'watch_extension' || targetType === 'watch_app') { + const isWatchApp = targetType === 'watch_app'; + const copyTargetUuid = parentTarget || this.getFirstTarget().uuid; + const phaseComment = targetType === 'watch_app' ? 'Embed Watch Content' : 'Copy Files'; + let destination; - // Add product to CopyFiles phase - this.addToPbxCopyfilesBuildPhase(productFile) + if(isWatchApp) { + destination = '"$(CONTENTS_FOLDER_PATH)/Watch"'; + } - // this.addBuildPhaseToTarget(newPhase.buildPhase, this.getFirstTarget().uuid) + // Create CopyFiles phase in parent target + this.addBuildPhase([], 'PBXCopyFilesBuildPhase', phaseComment, copyTargetUuid, targetType, destination); + // Add product to CopyFiles phase + this.addToPbxCopyfilesBuildPhase(productFile, phaseComment, copyTargetUuid); } // Target: Add uuid to root project this.addToPbxProjectSection(target); // Target: Add dependency for this target to first (main) target - this.addTargetDependency(this.getFirstTarget().uuid, [target.uuid]); + this.addTargetDependency(parentTarget || this.getFirstTarget().uuid, [target.uuid]); // Return target on success @@ -2005,7 +2021,7 @@ function pbxCopyFilesBuildPhaseObj(obj, folderType, subfolderPath, phaseName) { frameworks: 'frameworks', static_library: 'products_directory', unit_test_bundle: 'wrapper', - watch_app: 'wrapper', + watch_app: 'products_directory', watch_extension: 'plugins' } var SUBFOLDERSPEC_BY_DESTINATION = { @@ -2161,8 +2177,8 @@ function producttypeForTargettype (targetType) { framework: 'com.apple.product-type.framework', static_library: 'com.apple.product-type.library.static', unit_test_bundle: 'com.apple.product-type.bundle.unit-test', - watch_app: 'com.apple.product-type.application.watchapp', - watch_extension: 'com.apple.product-type.watchkit-extension' + watch_app: 'com.apple.product-type.application.watchapp2', + watch_extension: 'com.apple.product-type.watchkit2-extension' }; return PRODUCTTYPE_BY_TARGETTYPE[targetType] @@ -2179,8 +2195,8 @@ function filetypeForProducttype (productType) { 'com.apple.product-type.framework': '"wrapper.framework"', 'com.apple.product-type.library.static': '"archive.ar"', 'com.apple.product-type.bundle.unit-test': '"wrapper.cfbundle"', - 'com.apple.product-type.application.watchapp': '"wrapper.application"', - 'com.apple.product-type.watchkit-extension': '"wrapper.app-extension"' + 'com.apple.product-type.application.watchapp2': '"wrapper.application"', + 'com.apple.product-type.watchkit2-extension': '"wrapper.app-extension"' }; return FILETYPE_BY_PRODUCTTYPE[productType] @@ -2336,7 +2352,7 @@ pbxProject.prototype.findPBXGroupKeyAndType = function(criteria, groupType) { var group = groups[key]; if (criteria && criteria.path && criteria.name) { - if (criteria.path === group.path && criteria.name === group.name) { + if (criteria.path === group.path && (criteria.name === group.name || `"${criteria.name}"` === group.name)) { target = key; break } @@ -2348,7 +2364,7 @@ pbxProject.prototype.findPBXGroupKeyAndType = function(criteria, groupType) { } } else if (criteria && criteria.name) { - if (criteria.name === group.name) { + if (criteria.name === group.name || `"${criteria.name}"` === group.name) { target = key; break }