Skip to content

Commit 5de81d8

Browse files
committed
feat: initial work on watch app
1 parent 2c88692 commit 5de81d8

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

lib/pbxProject.js

+22-18
Original file line numberDiff line numberDiff line change
@@ -435,8 +435,8 @@ pbxProject.prototype.pbxCopyfilesBuildPhaseObj = function(target) {
435435
return this.buildPhaseObject('PBXCopyFilesBuildPhase', 'Copy Files', target);
436436
}
437437

438-
pbxProject.prototype.addToPbxCopyfilesBuildPhase = function(file) {
439-
var sources = this.buildPhaseObject('PBXCopyFilesBuildPhase', 'Copy Files', file.target);
438+
pbxProject.prototype.addToPbxCopyfilesBuildPhase = function(file, comment, target) {
439+
var sources = this.buildPhaseObject('PBXCopyFilesBuildPhase', comment || 'Copy Files', target || file.target);
440440
sources.files.push(pbxBuildPhaseObj(file));
441441
}
442442

@@ -1616,7 +1616,7 @@ pbxProject.prototype.getFileKey = function(filePath) {
16161616
return false;
16171617
}
16181618

1619-
pbxProject.prototype.addTarget = function(name, type, subfolder) {
1619+
pbxProject.prototype.addTarget = function(name, type, subfolder, parentTarget) {
16201620

16211621
// Setup uuid and name of new target
16221622
var targetUuid = this.generateUuid(),
@@ -1695,26 +1695,30 @@ pbxProject.prototype.addTarget = function(name, type, subfolder) {
16951695
};
16961696

16971697
// Target: Add to PBXNativeTarget section
1698-
this.addToPbxNativeTargetSection(target)
1698+
this.addToPbxNativeTargetSection(target);
16991699

1700-
// Product: Embed (only for "extension"-type targets)
1701-
if (targetType === 'app_extension') {
1700+
if (targetType === 'app_extension' || targetType === 'watch_extension' || targetType === 'watch_app') {
1701+
const isWatchApp = targetType === 'watch_app';
1702+
const copyTargetUuid = parentTarget || this.getFirstTarget().uuid;
1703+
const phaseComment = targetType === 'watch_app' ? 'Embed Watch Content' : 'Copy Files';
1704+
let destination;
17021705

1703-
// Create CopyFiles phase in first target
1704-
this.addBuildPhase([], 'PBXCopyFilesBuildPhase', 'Copy Files', this.getFirstTarget().uuid, targetType)
1705-
1706-
// Add product to CopyFiles phase
1707-
this.addToPbxCopyfilesBuildPhase(productFile)
1706+
if(isWatchApp) {
1707+
destination = '"$(CONTENTS_FOLDER_PATH)/Watch"';
1708+
}
17081709

1709-
// this.addBuildPhaseToTarget(newPhase.buildPhase, this.getFirstTarget().uuid)
1710+
// Create CopyFiles phase in parent target
1711+
this.addBuildPhase([], 'PBXCopyFilesBuildPhase', phaseComment, copyTargetUuid, targetType, destination);
17101712

1713+
// Add product to CopyFiles phase
1714+
this.addToPbxCopyfilesBuildPhase(productFile, phaseComment, copyTargetUuid);
17111715
}
17121716

17131717
// Target: Add uuid to root project
17141718
this.addToPbxProjectSection(target);
17151719

17161720
// Target: Add dependency for this target to first (main) target
1717-
this.addTargetDependency(this.getFirstTarget().uuid, [target.uuid]);
1721+
this.addTargetDependency(parentTarget || this.getFirstTarget().uuid, [target.uuid]);
17181722

17191723

17201724
// Return target on success
@@ -2005,7 +2009,7 @@ function pbxCopyFilesBuildPhaseObj(obj, folderType, subfolderPath, phaseName) {
20052009
frameworks: 'frameworks',
20062010
static_library: 'products_directory',
20072011
unit_test_bundle: 'wrapper',
2008-
watch_app: 'wrapper',
2012+
watch_app: 'products_directory',
20092013
watch_extension: 'plugins'
20102014
}
20112015
var SUBFOLDERSPEC_BY_DESTINATION = {
@@ -2161,8 +2165,8 @@ function producttypeForTargettype (targetType) {
21612165
framework: 'com.apple.product-type.framework',
21622166
static_library: 'com.apple.product-type.library.static',
21632167
unit_test_bundle: 'com.apple.product-type.bundle.unit-test',
2164-
watch_app: 'com.apple.product-type.application.watchapp',
2165-
watch_extension: 'com.apple.product-type.watchkit-extension'
2168+
watch_app: 'com.apple.product-type.application.watchapp2',
2169+
watch_extension: 'com.apple.product-type.watchkit2-extension'
21662170
};
21672171

21682172
return PRODUCTTYPE_BY_TARGETTYPE[targetType]
@@ -2179,8 +2183,8 @@ function filetypeForProducttype (productType) {
21792183
'com.apple.product-type.framework': '"wrapper.framework"',
21802184
'com.apple.product-type.library.static': '"archive.ar"',
21812185
'com.apple.product-type.bundle.unit-test': '"wrapper.cfbundle"',
2182-
'com.apple.product-type.application.watchapp': '"wrapper.application"',
2183-
'com.apple.product-type.watchkit-extension': '"wrapper.app-extension"'
2186+
'com.apple.product-type.application.watchapp2': '"wrapper.application"',
2187+
'com.apple.product-type.watchkit2-extension': '"wrapper.app-extension"'
21842188
};
21852189

21862190
return FILETYPE_BY_PRODUCTTYPE[productType]

0 commit comments

Comments
 (0)