@@ -10,59 +10,45 @@ export class IOSWatchAppService extends NativeTargetServiceBase implements IIOSW
10
10
11
11
public async addWatchAppFromPath ( { watchAppFolderPath, projectData, platformData, pbxProjPath} : IAddWatchAppFromPathOptions ) : Promise < boolean > {
12
12
const targetUuids : string [ ] = [ ] ;
13
- let addedExtensions = false ;
13
+
14
14
if ( ! this . $fs . exists ( watchAppFolderPath ) ) {
15
15
return false ;
16
16
}
17
- const project = new this . $xcode . project ( pbxProjPath ) ;
18
- const appPath = path . join ( watchAppFolderPath , "watchapp" ) ;
19
- const extensionPath = path . join ( watchAppFolderPath , "watchextension" ) ;
20
- project . parseSync ( ) ;
21
- const appFolder = this . $fs . readDirectory ( appPath )
22
- . filter ( fileName => {
23
- const filePath = path . join ( appPath , fileName ) ;
24
- const stats = this . $fs . getFsStats ( filePath ) ;
25
17
26
- return stats . isDirectory ( ) && ! fileName . startsWith ( ". ") ;
27
- } ) [ 0 ] ;
18
+ const appPath = path . join ( watchAppFolderPath , "watchapp ") ;
19
+ const appFolder = this . getTargetDirectories ( appPath ) [ 0 ] ;
28
20
29
- const extensionFolder = this . $fs . readDirectory ( extensionPath )
30
- . filter ( fileName => {
31
- const filePath = path . join ( extensionPath , fileName ) ;
32
- const stats = this . $fs . getFsStats ( filePath ) ;
21
+ const extensionPath = path . join ( watchAppFolderPath , "watchextension" ) ;
22
+ const extensionFolder = this . getTargetDirectories ( extensionPath ) [ 0 ] ;
33
23
34
- return stats . isDirectory ( ) && ! fileName . startsWith ( "." ) ;
35
- } ) [ 0 ] ;
24
+ const project = new this . $xcode . project ( pbxProjPath ) ;
25
+ project . parseSync ( ) ;
36
26
37
27
const watchApptarget = this . addTargetToProject ( appPath , appFolder , "watch_app" , project , platformData , project . getFirstTarget ( ) . uuid ) ;
38
- this . configureTarget ( appFolder , path . join ( appPath , appFolder ) , `${ projectData . projectIdentifiers . ios } .watchkitapp` , watchApptarget , project ) ;
28
+ this . configureTarget (
29
+ appFolder ,
30
+ path . join ( appPath , appFolder ) ,
31
+ `${ projectData . projectIdentifiers . ios } .watchkitapp` ,
32
+ "watchapp.json" ,
33
+ watchApptarget ,
34
+ project
35
+ ) ;
39
36
targetUuids . push ( watchApptarget . uuid ) ;
37
+
40
38
const watchExtensionTarget = this . addTargetToProject ( extensionPath , extensionFolder , "watch_extension" , project , platformData , watchApptarget . uuid ) ;
41
- this . configureTarget ( extensionFolder , path . join ( extensionPath , extensionFolder ) , `${ projectData . projectIdentifiers . ios } .watchkitapp.watchkitextension` , watchExtensionTarget , project ) ;
39
+ this . configureTarget (
40
+ extensionFolder ,
41
+ path . join ( extensionPath , extensionFolder ) ,
42
+ `${ projectData . projectIdentifiers . ios } .watchkitapp.watchkitextension` ,
43
+ "extension.json" ,
44
+ watchExtensionTarget ,
45
+ project ) ;
42
46
targetUuids . push ( watchExtensionTarget . uuid ) ;
43
- addedExtensions = true ;
44
47
45
48
this . $fs . writeFile ( pbxProjPath , project . writeSync ( { omitEmptyValues : true } ) ) ;
46
49
this . prepareSigning ( targetUuids , projectData , pbxProjPath ) ;
47
50
48
- return addedExtensions ;
49
- }
50
-
51
- private configureTarget ( targetName : string , targetPath : string , identifier : string , target : IXcode . target , project : IXcode . project ) {
52
- const identifierParts = identifier . split ( "." ) ;
53
- identifierParts . pop ( ) ;
54
- const wkAppBundleIdentifier = identifierParts . join ( "." ) ;
55
- project . addBuildProperty ( "PRODUCT_BUNDLE_IDENTIFIER" , identifier , "Debug" , targetName ) ;
56
- project . addBuildProperty ( "PRODUCT_BUNDLE_IDENTIFIER" , identifier , "Release" , targetName ) ;
57
- project . addBuildProperty ( "SDKROOT" , "watchos" , "Debug" , targetName ) ;
58
- project . addBuildProperty ( "SDKROOT" , "watchos" , "Release" , targetName ) ;
59
- project . addBuildProperty ( "TARGETED_DEVICE_FAMILY" , 4 , "Debug" , targetName ) ;
60
- project . addBuildProperty ( "TARGETED_DEVICE_FAMILY" , 4 , "Release" , targetName ) ;
61
- project . addBuildProperty ( "WATCHOS_DEPLOYMENT_TARGET" , 4.1 , "Debug" , targetName ) ;
62
- project . addBuildProperty ( "WATCHOS_DEPLOYMENT_TARGET" , 4.1 , "Release" , targetName ) ;
63
- project . addBuildProperty ( "WK_APP_BUNDLE_IDENTIFIER" , wkAppBundleIdentifier , "Debug" , targetName ) ;
64
- project . addBuildProperty ( "WK_APP_BUNDLE_IDENTIFIER" , wkAppBundleIdentifier , "Release" , targetName ) ;
65
- project . addToHeaderSearchPaths ( targetPath , target . pbxNativeTarget . productName ) ;
51
+ return true ;
66
52
}
67
53
68
54
public removeWatchApp ( { pbxProjPath} : IRemoveWatchAppOptions ) : void {
@@ -72,6 +58,25 @@ export class IOSWatchAppService extends NativeTargetServiceBase implements IIOSW
72
58
project . removeTargetsByProductType ( "com.apple.product-type.watchkit2-extension" ) ;
73
59
this . $fs . writeFile ( pbxProjPath , project . writeSync ( { omitEmptyValues : true } ) ) ;
74
60
}
61
+
62
+ private configureTarget ( targetName : string , targetPath : string , identifier : string , configurationFileName : string , target : IXcode . target , project : IXcode . project ) {
63
+ const targetConfigurationJsonPath = path . join ( targetPath , configurationFileName ) ;
64
+ this . setConfigurationsFromJsonFile ( targetConfigurationJsonPath , target . uuid , project ) ;
65
+
66
+ const identifierParts = identifier . split ( "." ) ;
67
+ identifierParts . pop ( ) ;
68
+ const wkAppBundleIdentifier = identifierParts . join ( "." ) ;
69
+
70
+ this . setXcodeTargetBuildConfigurationProperties ( [
71
+ { name : "PRODUCT_BUNDLE_IDENTIFIER" , value : identifier } ,
72
+ { name : "SDKROOT" , value : "watchos" } ,
73
+ { name : "TARGETED_DEVICE_FAMILY" , value : 4 } ,
74
+ { name : "WATCHOS_DEPLOYMENT_TARGET" , value : 4.1 } ,
75
+ { name : "WK_APP_BUNDLE_IDENTIFIER" , value : wkAppBundleIdentifier }
76
+ ] , targetName , project ) ;
77
+
78
+ project . addToHeaderSearchPaths ( targetPath , target . pbxNativeTarget . productName ) ;
79
+ }
75
80
}
76
81
77
82
$injector . register ( "iOSWatchAppService" , IOSWatchAppService ) ;
0 commit comments