Skip to content

Kddimitrov/watch app #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 25, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 38 additions & 22 deletions lib/pbxProject.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 : '"<group>"'
},
fileReferenceSection = this.pbxFileReferenceSection(),
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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]
Expand All @@ -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]
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down