Skip to content

Commit cec7c99

Browse files
author
Fatme
authored
Merge pull request #4554 from NativeScript/fatme/xcode
refactor: refactor ios build
2 parents 7846bce + d5c9e09 commit cec7c99

21 files changed

+1316
-994
lines changed

lib/bootstrap.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ $injector.require("iOSExtensionsService", "./services/ios-extensions-service");
1919
$injector.require("iOSProjectService", "./services/ios-project-service");
2020
$injector.require("iOSProvisionService", "./services/ios-provision-service");
2121
$injector.require("xcconfigService", "./services/xcconfig-service");
22+
$injector.require("iOSSigningService", "./services/ios/ios-signing-service");
23+
$injector.require("xcodebuildArgsService", "./services/ios/xcodebuild-args-service");
24+
$injector.require("xcodebuildCommandService", "./services/ios/xcodebuild-command-service");
25+
$injector.require("xcodebuildService", "./services/ios/xcodebuild-service");
26+
$injector.require("exportOptionsPlistService", "./services/ios/export-options-plist-service");
2227

2328
$injector.require("cocoapodsService", "./services/cocoapods-service");
2429
$injector.require("cocoaPodsPlatformManager", "./services/cocoapods-platform-manager");

lib/commands/appstore-upload.ts

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { StringCommandParameter } from "../common/command-params";
21
import * as path from "path";
3-
import { IOSProjectService } from "../services/ios-project-service";
2+
import { StringCommandParameter } from "../common/command-params";
43

54
export class PublishIOS implements ICommand {
65
public allowedParameters: ICommandParameter[] = [new StringCommandParameter(this.$injector), new StringCommandParameter(this.$injector),
@@ -13,7 +12,8 @@ export class PublishIOS implements ICommand {
1312
private $projectData: IProjectData,
1413
private $options: IOptions,
1514
private $prompter: IPrompter,
16-
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants) {
15+
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
16+
private $xcodebuildService: IXcodebuildService) {
1717
this.$projectData.initializeProjectData();
1818
}
1919

@@ -32,7 +32,6 @@ export class PublishIOS implements ICommand {
3232
let password = args[1];
3333
const mobileProvisionIdentifier = args[2];
3434
const codeSignIdentity = args[3];
35-
const teamID = this.$options.teamId;
3635
let ipaFilePath = this.$options.ipa ? path.resolve(this.$options.ipa) : null;
3736

3837
if (!username) {
@@ -68,35 +67,31 @@ export class PublishIOS implements ICommand {
6867
config: this.$options,
6968
env: this.$options.env
7069
};
70+
const buildConfig: IBuildConfig = {
71+
projectDir: this.$options.path,
72+
release: this.$options.release,
73+
device: this.$options.device,
74+
provision: this.$options.provision,
75+
teamId: this.$options.teamId,
76+
buildForDevice: true,
77+
iCloudContainerEnvironment: this.$options.iCloudContainerEnvironment,
78+
mobileProvisionIdentifier,
79+
codeSignIdentity
80+
};
7181

7282
if (mobileProvisionIdentifier || codeSignIdentity) {
73-
const iOSBuildConfig: IBuildConfig = {
74-
projectDir: this.$options.path,
75-
release: this.$options.release,
76-
device: this.$options.device,
77-
provision: this.$options.provision,
78-
teamId: this.$options.teamId,
79-
buildForDevice: true,
80-
iCloudContainerEnvironment: this.$options.iCloudContainerEnvironment,
81-
mobileProvisionIdentifier,
82-
codeSignIdentity
83-
};
8483
this.$logger.info("Building .ipa with the selected mobile provision and/or certificate.");
8584
// This is not very correct as if we build multiple targets we will try to sign all of them using the signing identity here.
8685
await this.$platformService.preparePlatform(platformInfo);
87-
await this.$platformService.buildPlatform(platform, iOSBuildConfig, this.$projectData);
88-
ipaFilePath = this.$platformService.lastOutputPath(platform, iOSBuildConfig, this.$projectData);
86+
await this.$platformService.buildPlatform(platform, buildConfig, this.$projectData);
87+
ipaFilePath = this.$platformService.lastOutputPath(platform, buildConfig, this.$projectData);
8988
} else {
9089
this.$logger.info("No .ipa, mobile provision or certificate set. Perfect! Now we'll build .xcarchive and let Xcode pick the distribution certificate and provisioning profile for you when exporting .ipa for AppStore submission.");
9190
await this.$platformService.preparePlatform(platformInfo);
9291

9392
const platformData = this.$platformsData.getPlatformData(platform, this.$projectData);
94-
const iOSProjectService = <IOSProjectService>platformData.platformProjectService;
95-
96-
const archivePath = await iOSProjectService.archive(this.$projectData);
97-
this.$logger.info("Archive at: " + archivePath);
9893

99-
const exportPath = await iOSProjectService.exportArchive(this.$projectData, { archivePath, teamID, provision: mobileProvisionIdentifier || this.$options.provision });
94+
const exportPath = await this.$xcodebuildService.buildForAppStore(platformData, this.$projectData, buildConfig);
10095
this.$logger.info("Export at: " + exportPath);
10196

10297
ipaFilePath = exportPath;

lib/constants.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ class ItunesConnectApplicationTypesClass implements IiTunesConnectApplicationTyp
110110
public Mac = "Mac OS X App";
111111
}
112112

113+
export const iOSAppResourcesFolderName = "iOS";
114+
export const androidAppResourcesFolderName = "Android";
115+
113116
export const ItunesConnectApplicationTypes = new ItunesConnectApplicationTypesClass();
114117
export const VUE_NAME = "vue";
115118
export const ANGULAR_NAME = "angular";

lib/declarations.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -841,10 +841,10 @@ interface IXcprojService {
841841
/**
842842
* Returns the path to the xcodeproj file
843843
* @param projectData Information about the project.
844-
* @param platformData Information about the platform.
844+
* @param projectRoot The root folder of native project.
845845
* @return {string} The full path to the xcodeproj
846846
*/
847-
getXcodeprojPath(projectData: IProjectData, platformData: IPlatformData): string;
847+
getXcodeprojPath(projectData: IProjectData, projectRoot: string): string;
848848
/**
849849
* Checks whether the system needs xcproj to execute ios builds successfully.
850850
* In case the system does need xcproj but does not have it, prints an error message.

lib/definitions/project.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -446,15 +446,15 @@ interface IPlatformProjectService extends NodeJS.EventEmitter, IPlatformProjectS
446446
* @param {IPlatformData} platformData The data for the specified platform.
447447
* @returns {void}
448448
*/
449-
stopServices(platformData: IPlatformData): Promise<ISpawnResult>;
449+
stopServices?(projectRoot: string): Promise<ISpawnResult>;
450450

451451
/**
452452
* Removes build artifacts specific to the platform
453453
* @param {string} projectRoot The root directory of the native project.
454454
* @param {IProjectData} projectData DTO with information about the project.
455455
* @returns {void}
456456
*/
457-
cleanProject(projectRoot: string, projectData: IProjectData): Promise<void>
457+
cleanProject?(projectRoot: string, projectData: IProjectData): Promise<void>
458458

459459
/**
460460
* Check the current state of the project, and validate against the options.
@@ -466,7 +466,7 @@ interface IPlatformProjectService extends NodeJS.EventEmitter, IPlatformProjectS
466466
* Get the deployment target's version
467467
* Currently implemented only for iOS -> returns the value of IPHONEOS_DEPLOYMENT_TARGET property from xcconfig file
468468
*/
469-
getDeploymentTarget(projectData: IProjectData): any;
469+
getDeploymentTarget?(projectData: IProjectData): any;
470470
}
471471

472472
interface IValidatePlatformOutput {

lib/definitions/xcode.d.ts

Lines changed: 98 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,100 @@
11
declare module "nativescript-dev-xcode" {
2-
interface Options {
3-
[key: string]: any;
4-
5-
customFramework?: boolean;
6-
embed?: boolean;
7-
relativePath?: string;
8-
}
9-
10-
class project {
11-
constructor(filename: string);
12-
13-
parse(callback: () => void): void;
14-
parseSync(): void;
15-
16-
writeSync(options: any): string;
17-
18-
addFramework(filepath: string, options?: Options): void;
19-
removeFramework(filePath: string, options?: Options): void;
20-
21-
addPbxGroup(filePathsArray: any[], name: string, path: string, sourceTree: string): void;
22-
23-
removePbxGroup(groupName: string, path: string): void;
24-
25-
addToHeaderSearchPaths(options?: Options): void;
26-
removeFromHeaderSearchPaths(options?: Options): void;
27-
updateBuildProperty(key: string, value: any): void;
28-
29-
pbxXCBuildConfigurationSection(): any;
30-
31-
addTarget(targetName: string, targetType: string, targetPath?: string): target;
32-
addBuildPhase(filePathsArray: string[],
33-
buildPhaseType: string,
34-
comment: string,
35-
target?: string,
36-
optionsOrFolderType?: Object|string,
37-
subfolderPath?: string
38-
): any;
39-
addToBuildSettings(buildSetting: string, value: any, targetUuid?: string): void;
40-
addPbxGroup(
41-
filePathsArray: string[],
42-
name: string,
43-
path: string,
44-
sourceTree: string,
45-
opt: {filesRelativeToProject?: boolean, target?: string, uuid?: string, isMain?: boolean }
46-
): group;
47-
addBuildProperty(prop: string, value: any, build_name?: string, productName?: string): void;
48-
addToHeaderSearchPaths(file: string|Object, productName?: string): void;
49-
removeTargetsByProductType(targetType: string): void
50-
}
51-
52-
class target {
53-
uuid: string;
54-
pbxNativeTarget: {productName: string}
55-
}
56-
57-
class group {
58-
uuid: string;
59-
pbxGroup: Object;
60-
}
2+
interface Options {
3+
[key: string]: any;
4+
5+
customFramework?: boolean;
6+
embed?: boolean;
7+
relativePath?: string;
8+
}
9+
10+
class project {
11+
constructor(filename: string);
12+
13+
parse(callback: () => void): void;
14+
parseSync(): void;
15+
16+
writeSync(options: any): string;
17+
18+
addFramework(filepath: string, options?: Options): void;
19+
removeFramework(filePath: string, options?: Options): void;
20+
21+
addPbxGroup(filePathsArray: any[], name: string, path: string, sourceTree: string): void;
22+
23+
removePbxGroup(groupName: string, path: string): void;
24+
25+
addToHeaderSearchPaths(options?: Options): void;
26+
removeFromHeaderSearchPaths(options?: Options): void;
27+
updateBuildProperty(key: string, value: any): void;
28+
29+
pbxXCBuildConfigurationSection(): any;
30+
31+
addTarget(targetName: string, targetType: string, targetPath?: string): target;
32+
addBuildPhase(filePathsArray: string[],
33+
buildPhaseType: string,
34+
comment: string,
35+
target?: string,
36+
optionsOrFolderType?: Object|string,
37+
subfolderPath?: string
38+
): any;
39+
addToBuildSettings(buildSetting: string, value: any, targetUuid?: string): void;
40+
addPbxGroup(
41+
filePathsArray: string[],
42+
name: string,
43+
path: string,
44+
sourceTree: string,
45+
opt: {filesRelativeToProject?: boolean, target?: string, uuid?: string, isMain?: boolean }
46+
): group;
47+
addBuildProperty(prop: string, value: any, build_name?: string, productName?: string): void;
48+
addToHeaderSearchPaths(file: string|Object, productName?: string): void;
49+
removeTargetsByProductType(targetType: string): void
50+
}
51+
52+
class target {
53+
uuid: string;
54+
pbxNativeTarget: {productName: string}
55+
}
56+
57+
class group {
58+
uuid: string;
59+
pbxGroup: Object;
60+
}
61+
}
62+
63+
interface IiOSSigningService {
64+
setupSigningForDevice(projectRoot: string, projectData: IProjectData, buildConfig: IiOSBuildConfig): Promise<void>;
65+
setupSigningFromTeam(projectRoot: string, projectData: IProjectData, teamId: string): Promise<void>;
66+
setupSigningFromProvision(projectRoot: string, projectData: IProjectData, provision?: string, mobileProvisionData?: any): Promise<void>;
67+
}
68+
69+
interface IXcodebuildService {
70+
buildForSimulator(platformData: IPlatformData, projectData: IProjectData, buildConfig: IBuildConfig): Promise<void>;
71+
buildForDevice(platformData: IPlatformData, projectData: IProjectData, buildConfig: IBuildConfig): Promise<string>;
72+
buildForAppStore(platformData: IPlatformData, projectData: IProjectData, buildConfig: IBuildConfig): Promise<string>;
73+
}
74+
75+
interface IXcodebuildArgsService {
76+
getBuildForSimulatorArgs(platformData: IPlatformData, projectData: IProjectData, buildConfig: IBuildConfig): Promise<string[]>;
77+
getBuildForDeviceArgs(platformData: IPlatformData, projectData: IProjectData, buildConfig: IBuildConfig): Promise<string[]>;
78+
}
79+
80+
interface IXcodebuildCommandService {
81+
executeCommand(args: string[], options: IXcodebuildCommandOptions): Promise<ISpawnResult>;
82+
}
83+
84+
interface IXcodebuildCommandOptions {
85+
message?: string;
86+
cwd: string;
87+
stdio?: string;
88+
spawnOptions?: any;
89+
}
90+
91+
interface IExportOptionsPlistService {
92+
createDevelopmentExportOptionsPlist(archivePath: string, projectData: IProjectData, buildConfig: IBuildConfig): IExportOptionsPlistOutput;
93+
createDistributionExportOptionsPlist(projectRoot: string, projectData: IProjectData, buildConfig: IBuildConfig): IExportOptionsPlistOutput;
94+
}
95+
96+
interface IExportOptionsPlistOutput {
97+
exportFileDir: string;
98+
exportFilePath: string;
99+
exportOptionsPlistFilePath: string;
61100
}

lib/services/android-project-service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,9 +348,9 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
348348
return nativescript && (nativescript.android || (nativescript.platforms && nativescript.platforms.android));
349349
}
350350

351-
public async stopServices(platformData: IPlatformData): Promise<ISpawnResult> {
351+
public async stopServices(projectRoot: string): Promise<ISpawnResult> {
352352
const result = await this.$gradleCommandService.executeCommand(["--stop", "--quiet"], {
353-
cwd: platformData.projectRoot,
353+
cwd: projectRoot,
354354
message: "Gradle stop services...",
355355
stdio: "pipe"
356356
});

0 commit comments

Comments
 (0)