@@ -10,59 +10,45 @@ export class IOSWatchAppService extends NativeTargetServiceBase implements IIOSW
1010
1111 public async addWatchAppFromPath ( { watchAppFolderPath, projectData, platformData, pbxProjPath} : IAddWatchAppFromPathOptions ) : Promise < boolean > {
1212 const targetUuids : string [ ] = [ ] ;
13- let addedExtensions = false ;
13+
1414 if ( ! this . $fs . exists ( watchAppFolderPath ) ) {
1515 return false ;
1616 }
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 ) ;
2517
26- return stats . isDirectory ( ) && ! fileName . startsWith ( ". ") ;
27- } ) [ 0 ] ;
18+ const appPath = path . join ( watchAppFolderPath , "watchapp ") ;
19+ const appFolder = this . getTargetDirectories ( appPath ) [ 0 ] ;
2820
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 ] ;
3323
34- return stats . isDirectory ( ) && ! fileName . startsWith ( "." ) ;
35- } ) [ 0 ] ;
24+ const project = new this . $xcode . project ( pbxProjPath ) ;
25+ project . parseSync ( ) ;
3626
3727 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+ ) ;
3936 targetUuids . push ( watchApptarget . uuid ) ;
37+
4038 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 ) ;
4246 targetUuids . push ( watchExtensionTarget . uuid ) ;
43- addedExtensions = true ;
4447
4548 this . $fs . writeFile ( pbxProjPath , project . writeSync ( { omitEmptyValues : true } ) ) ;
4649 this . prepareSigning ( targetUuids , projectData , pbxProjPath ) ;
4750
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 ;
6652 }
6753
6854 public removeWatchApp ( { pbxProjPath} : IRemoveWatchAppOptions ) : void {
@@ -72,6 +58,25 @@ export class IOSWatchAppService extends NativeTargetServiceBase implements IIOSW
7258 project . removeTargetsByProductType ( "com.apple.product-type.watchkit2-extension" ) ;
7359 this . $fs . writeFile ( pbxProjPath , project . writeSync ( { omitEmptyValues : true } ) ) ;
7460 }
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+ }
7580}
7681
7782$injector . register ( "iOSWatchAppService" , IOSWatchAppService ) ;
0 commit comments