Skip to content

Commit d2a0333

Browse files
committed
refactor: extract some constants
1 parent 1f52461 commit d2a0333

File tree

4 files changed

+51
-18
lines changed

4 files changed

+51
-18
lines changed

lib/constants.ts

+17
Original file line numberDiff line numberDiff line change
@@ -282,3 +282,20 @@ export const LiveSyncEvents = {
282282
liveSyncStarted: "liveSyncStarted",
283283
liveSyncNotification: "notify"
284284
};
285+
286+
export enum IOSDeviceTargets {
287+
ios = "1,2",
288+
watchos = 4
289+
}
290+
291+
export enum IOSNativeTargetProductTypes {
292+
watchApp = "com.apple.product-type.application.watchapp2",
293+
watchExtension = "com.apple.product-type.watchkit2-extension",
294+
appExtension = "com.apple.product-type.app-extension"
295+
}
296+
297+
export enum IOSNativeTargetTypes {
298+
watchApp = "watch_app",
299+
watchExtension = "watch_extension",
300+
appExtension = "app_extension"
301+
}

lib/services/ios-extensions-service.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as path from "path";
22
import { NativeTargetServiceBase } from "./ios-native-target-service-base";
3+
import { IOSNativeTargetProductTypes, IOSNativeTargetTypes } from "../constants";
34

45
export class IOSExtensionsService extends NativeTargetServiceBase implements IIOSExtensionsService {
56
constructor(protected $fs: IFileSystem,
@@ -18,7 +19,7 @@ export class IOSExtensionsService extends NativeTargetServiceBase implements IIO
1819
project.parseSync();
1920
this.getTargetDirectories(extensionsFolderPath)
2021
.forEach(extensionFolder => {
21-
const target = this.addTargetToProject(extensionsFolderPath, extensionFolder, 'app_extension', project, platformData);
22+
const target = this.addTargetToProject(extensionsFolderPath, extensionFolder, IOSNativeTargetTypes.appExtension, project, platformData);
2223
this.configureTarget(extensionFolder, path.join(extensionsFolderPath, extensionFolder), target, project, projectData);
2324
targetUuids.push(target.uuid);
2425
addedExtensions = true;
@@ -43,7 +44,7 @@ export class IOSExtensionsService extends NativeTargetServiceBase implements IIO
4344
public removeExtensions({pbxProjPath}: IRemoveExtensionsOptions): void {
4445
const project = new this.$xcode.project(pbxProjPath);
4546
project.parseSync();
46-
project.removeTargetsByProductType("com.apple.product-type.app-extension");
47+
project.removeTargetsByProductType(IOSNativeTargetProductTypes.appExtension);
4748
this.$fs.writeFile(pbxProjPath, project.writeSync({omitEmptyValues: true}));
4849
}
4950
}

lib/services/ios-project-service.ts

+18-6
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import * as plist from "plist";
1313
import { IOSProvisionService } from "./ios-provision-service";
1414
import { IOSEntitlementsService } from "./ios-entitlements-service";
1515
import * as mobileProvisionFinder from "ios-mobileprovision-finder";
16-
import { BUILD_XCCONFIG_FILE_NAME, IosProjectConstants } from "../constants";
16+
import { BUILD_XCCONFIG_FILE_NAME, IosProjectConstants, IOSNativeTargetProductTypes } from "../constants";
1717

1818
interface INativeSourceCodeGroup {
1919
name: string;
@@ -502,9 +502,12 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
502502
}
503503

504504
xcode.setAutomaticSigningStyle(projectData.projectName, teamId);
505-
xcode.setAutomaticSigningStyleByTargetProductType("com.apple.product-type.app-extension", teamId);
506-
xcode.setAutomaticSigningStyleByTargetProductType("com.apple.product-type.watchkit2-extension", teamId);
507-
xcode.setAutomaticSigningStyleByTargetProductType("com.apple.product-type.application.watchapp2", teamId);
505+
xcode.setAutomaticSigningStyleByTargetProductTypesList([
506+
IOSNativeTargetProductTypes.appExtension,
507+
IOSNativeTargetProductTypes.watchApp,
508+
IOSNativeTargetProductTypes.watchExtension
509+
],
510+
teamId);
508511
xcode.save();
509512

510513
this.$logger.trace(`Set Automatic signing style and team id ${teamId}.`);
@@ -546,7 +549,12 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
546549
identity: mobileprovision.Type === "Development" ? "iPhone Developer" : "iPhone Distribution"
547550
};
548551
xcode.setManualSigningStyle(projectData.projectName, configuration);
549-
xcode.setManualSigningStyleByTargetProductType("com.apple.product-type.app-extension", configuration);
552+
xcode.setManualSigningStyleByTargetProductTypesList([
553+
IOSNativeTargetProductTypes.appExtension,
554+
IOSNativeTargetProductTypes.watchApp,
555+
IOSNativeTargetProductTypes.watchExtension
556+
],
557+
configuration);
550558
xcode.save();
551559

552560
// this.cache(uuid);
@@ -802,7 +810,11 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
802810
);
803811
await this.prepareNativeSourceCode(constants.TNS_NATIVE_SOURCE_GROUP_NAME, resourcesNativeCodePath, projectData);
804812
this.$iOSWatchAppService.removeWatchApp({ pbxProjPath });
805-
await this.$iOSWatchAppService.addWatchAppFromPath({ watchAppFolderPath: path.join(resourcesDirectoryPath, platformData.normalizedPlatformName), projectData, platformData, pbxProjPath });
813+
const addedWatchApp = await this.$iOSWatchAppService.addWatchAppFromPath({ watchAppFolderPath: path.join(resourcesDirectoryPath, platformData.normalizedPlatformName), projectData, platformData, pbxProjPath });
814+
815+
if (addedWatchApp) {
816+
this.$logger.warn("The support for Apple Watch App is currently in Beta. For more information about the current development state and any known issues, please check the relevant GitHub issue: ISSUE LINK");
817+
}
806818

807819
}
808820

lib/services/ios-watch-app-service.ts

+13-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import * as path from "path";
22
import { NativeTargetServiceBase } from "./ios-native-target-service-base";
3+
import { IOSDeviceTargets, IOS_WATCHAPP_FOLDER, IOS_WATCHAPP_EXTENSION_FOLDER, IOSNativeTargetProductTypes, IOSNativeTargetTypes } from "../constants";
34

45
export class IOSWatchAppService extends NativeTargetServiceBase implements IIOSWatchAppService {
6+
private static WATCH_APP_IDENTIFIER = "watchkitapp";
7+
private static WACTCH_EXTENSION_IDENTIFIER = "watchkitextension";
58
constructor(protected $fs: IFileSystem,
69
protected $pbxprojDomXcode: IPbxprojDomXcode,
710
protected $xcode: IXcode) {
@@ -15,31 +18,31 @@ export class IOSWatchAppService extends NativeTargetServiceBase implements IIOSW
1518
return false;
1619
}
1720

18-
const appPath = path.join(watchAppFolderPath, "watchapp");
21+
const appPath = path.join(watchAppFolderPath, IOS_WATCHAPP_FOLDER);
1922
const appFolder = this.getTargetDirectories(appPath)[0];
2023

21-
const extensionPath = path.join(watchAppFolderPath, "watchextension");
24+
const extensionPath = path.join(watchAppFolderPath, IOS_WATCHAPP_EXTENSION_FOLDER);
2225
const extensionFolder = this.getTargetDirectories(extensionPath)[0];
2326

2427
const project = new this.$xcode.project(pbxProjPath);
2528
project.parseSync();
2629

27-
const watchApptarget = this.addTargetToProject(appPath, appFolder, "watch_app", project, platformData, project.getFirstTarget().uuid);
30+
const watchApptarget = this.addTargetToProject(appPath, appFolder, IOSNativeTargetTypes.watchApp, project, platformData, project.getFirstTarget().uuid);
2831
this.configureTarget(
2932
appFolder,
3033
path.join(appPath, appFolder),
31-
`${projectData.projectIdentifiers.ios}.watchkitapp`,
34+
`${projectData.projectIdentifiers.ios}.${IOSWatchAppService.WATCH_APP_IDENTIFIER}`,
3235
"watchapp.json",
3336
watchApptarget,
3437
project
3538
);
3639
targetUuids.push(watchApptarget.uuid);
3740

38-
const watchExtensionTarget = this.addTargetToProject(extensionPath, extensionFolder, "watch_extension", project, platformData, watchApptarget.uuid);
41+
const watchExtensionTarget = this.addTargetToProject(extensionPath, extensionFolder, IOSNativeTargetTypes.watchExtension, project, platformData, watchApptarget.uuid);
3942
this.configureTarget(
4043
extensionFolder,
4144
path.join(extensionPath, extensionFolder),
42-
`${projectData.projectIdentifiers.ios}.watchkitapp.watchkitextension`,
45+
`${projectData.projectIdentifiers.ios}.${IOSWatchAppService.WATCH_APP_IDENTIFIER}.${IOSWatchAppService.WACTCH_EXTENSION_IDENTIFIER}`,
4346
"extension.json",
4447
watchExtensionTarget,
4548
project);
@@ -54,8 +57,8 @@ export class IOSWatchAppService extends NativeTargetServiceBase implements IIOSW
5457
public removeWatchApp({pbxProjPath}: IRemoveWatchAppOptions): void {
5558
const project = new this.$xcode.project(pbxProjPath);
5659
project.parseSync();
57-
project.removeTargetsByProductType("com.apple.product-type.application.watchapp2");
58-
project.removeTargetsByProductType("com.apple.product-type.watchkit2-extension");
60+
project.removeTargetsByProductType(IOSNativeTargetProductTypes.watchApp);
61+
project.removeTargetsByProductType(IOSNativeTargetProductTypes.watchExtension);
5962
this.$fs.writeFile(pbxProjPath, project.writeSync({omitEmptyValues: true}));
6063
}
6164

@@ -70,8 +73,8 @@ export class IOSWatchAppService extends NativeTargetServiceBase implements IIOSW
7073
this.setXcodeTargetBuildConfigurationProperties([
7174
{name: "PRODUCT_BUNDLE_IDENTIFIER", value: identifier},
7275
{name: "SDKROOT", value: "watchos"},
73-
{name: "TARGETED_DEVICE_FAMILY", value: 4},
74-
{name: "WATCHOS_DEPLOYMENT_TARGET", value: 4.1},
76+
{name: "TARGETED_DEVICE_FAMILY", value: IOSDeviceTargets.watchos},
77+
{name: "WATCHOS_DEPLOYMENT_TARGET", value: 4.1}, //TODO consider WATCHOS_DEPLOYMENT_TARGET in json configuration
7578
{name: "WK_APP_BUNDLE_IDENTIFIER", value: wkAppBundleIdentifier}
7679
], targetName, project);
7780

0 commit comments

Comments
 (0)